(command.AndOr
  ops: [Id.Op_DAmp]
  children: [
    (command.ShFunction
      name: _pkgadd
      body: 
        (command.BraceGroup
          children: [
            (C {<local>} {<cur>} {<prev>} {<words>} {<cword>})
            (command.AndOr
              ops: [Id.Op_DPipe]
              children: [
                (C {<_init_completion>} {<-n>} {<Id.Lit_Other ':'>})
                (command.ControlFlow token:<Id.ControlFlow_Return return>)
              ]
            )
            (command.Sentence
              child: (C {<local>} {<Id.Lit_VarLike 'device='> </var/spool/pkg>})
              terminator: <Id.Op_Semi _>
            )
            (C {<local>} {<Id.Lit_VarLike 'i='> ($ Id.VSub_DollarName '$cword')})
            (command.Sentence
              child: 
                (command.WhileUntil
                  keyword: <Id.KW_While while>
                  cond: [
                    (command.Sentence
                      child: 
                        (command.DBracket
                          expr: 
                            (bool_expr.Binary
                              op_id: Id.BoolBinary_gt
                              left: 
                                {
                                  (word_part.ArithSub
                                    anode: 
                                      (arith_expr.UnaryAssign
                                        op_id: Id.Node_PostDMinus
                                        child: (sh_lhs_expr.Name name:i)
                                      )
                                  )
                                }
                              right: {<0>}
                            )
                        )
                      terminator: <Id.Op_Semi _>
                    )
                  ]
                  body: 
                    (command.DoGroup
                      children: [
                        (command.Sentence
                          child: 
                            (command.Case
                              to_match: 
                                {
                                  (DQ 
                                    (braced_var_sub
                                      token: <Id.VSub_Name words>
                                      bracket_op: 
                                        (bracket_op.ArrayIndex
                                          expr: (arith_expr.ArithWord w:{($ Id.VSub_DollarName '$i')})
                                        )
                                    )
                                  )
                                }
                              arms: [
                                (case_arm
                                  pat_list: [{<-d>}]
                                  action: [
                                    (command.Sentence
                                      child: 
                                        (command.ShAssignment
                                          pairs: [
                                            (assign_pair
                                              lhs: (sh_lhs_expr.Name name:device)
                                              op: assign_op.Equal
                                              rhs: 
                                                {
                                                  (DQ 
                                                    (braced_var_sub
                                                      token: <Id.VSub_Name words>
                                                      bracket_op: 
                                                        (bracket_op.ArrayIndex
                                                          expr: 
                                                            (arith_expr.ArithWord
                                                              w: 
                                                                {
                                                                  (word_part.ArithSub
                                                                    anode: 
                                                                      (arith_expr.Binary
                                                                        op_id: Id.Arith_Plus
                                                                        left: 
                                                                          (arith_expr.VarRef
                                                                            token: 
                                                                              <Id.Lit_ArithVarLike i>
                                                                          )
                                                                        right: 
                                                                          (arith_expr.ArithWord
                                                                            w: {<Id.Lit_Digits 1>}
                                                                          )
                                                                      )
                                                                  )
                                                                }
                                                            )
                                                        )
                                                    )
                                                  )
                                                }
                                              spids: [104]
                                            )
                                          ]
                                        )
                                      terminator: <Id.Op_Semi _>
                                    )
                                    (command.ControlFlow
                                      token: <Id.ControlFlow_Break break>
                                    )
                                  ]
                                  spids: [100 101 124 -1]
                                )
                              ]
                            )
                          terminator: <Id.Op_Semi _>
                        )
                      ]
                    )
                )
              terminator: <Id.Op_Semi _>
            )
            (command.Case
              to_match: {($ Id.VSub_DollarName '$prev')}
              arms: [
                (case_arm
                  pat_list: [{<-d>}]
                  action: [(C {<_filedir>} {<pkg>}) (C {<_filedir>} {<-d>})]
                  spids: [144 145 158 -1]
                )
                (case_arm
                  pat_list: [{<-a>} {<-r>} {<-V>}]
                  action: [(C {<_filedir>})]
                  spids: [161 166 172 -1]
                )
                (case_arm
                  pat_list: [{<-k>} {<-s>} {<-R>}]
                  action: [(C {<_filedir>} {<-d>})]
                  spids: [175 180 188 -1]
                )
                (case_arm pat_list:[{<-P>} {<-k>} {<-x>}] spids:[191 196 199 -1])
                (case_arm
                  pat_list: [{<Id.Lit_Star '*'>}]
                  action: [
                    (command.If
                      arms: [
                        (if_arm
                          cond: [
                            (command.Sentence
                              child: 
                                (command.DBracket
                                  expr: 
                                    (bool_expr.Binary
                                      op_id: Id.BoolBinary_GlobDEqual
                                      left: {(${ Id.VSub_Name cur)}
                                      right: {<-> <Id.Lit_Other '*'>}
                                    )
                                )
                              terminator: <Id.Op_Semi _>
                            )
                          ]
                          action: [
                            (C {<local>} 
                              {<Id.Lit_VarLike 'opts='> 
                                (DQ <'-a -A -d -k -n -M -P -r -R -s -v -V -x'>)
                              }
                            )
                            (command.ShAssignment
                              pairs: [
                                (assign_pair
                                  lhs: (sh_lhs_expr.Name name:COMPREPLY)
                                  op: assign_op.Equal
                                  rhs: 
                                    {
                                      (sh_array_literal
                                        left: <Id.Op_LParen _>
                                        words: [
                                          {
                                            (command_sub
                                              left_token: <Id.Left_DollarParen '$('>
                                              command_list: 
                                                (command.CommandList
                                                  children: [
                                                    (C {<compgen>} {<-W>} {(DQ (${ Id.VSub_Name opts))} 
                                                      {<-->} {(${ Id.VSub_Name cur)}
                                                    )
                                                  ]
                                                )
                                            )
                                          }
                                        ]
                                      )
                                    }
                                  spids: [234]
                                )
                              ]
                            )
                          ]
                          spids: [206 223]
                        )
                      ]
                      else_action: [
                        (C {<local>} {<pkginst_list>})
                        (command.If
                          arms: [
                            (if_arm
                              cond: [
                                (command.Sentence
                                  child: 
                                    (command.DBracket
                                      expr: 
                                        (bool_expr.Unary
                                          op_id: Id.BoolUnary_d
                                          child: {($ Id.VSub_DollarName '$device')}
                                        )
                                    )
                                  terminator: <Id.Op_Semi _>
                                )
                              ]
                              action: [
                                (command.ForEach
                                  iter_name: filedir
                                  iter_words: [
                                    {
                                      (command_sub
                                        left_token: <Id.Left_DollarParen '$('>
                                        command_list: 
                                          (command.CommandList
                                            children: [
                                              (C {</bin/ls>} {<-1>} {($ Id.VSub_DollarName '$device')})
                                            ]
                                          )
                                      )
                                    }
                                  ]
                                  do_arg_iter: F
                                  body: 
                                    (command.DoGroup
                                      children: [
                                        (command.If
                                          arms: [
                                            (if_arm
                                              cond: [
                                                (command.Sentence
                                                  child: 
                                                    (command.AndOr
                                                      ops: [Id.Op_DAmp]
                                                      children: [
                                                        (command.DBracket
                                                          expr: 
                                                            (bool_expr.Unary
                                                              op_id: Id.BoolUnary_d
                                                              child: 
                                                                {
                                                                  (DQ 
                                                                    ($ Id.VSub_DollarName '$device') </> ($ Id.VSub_DollarName '$filedir')
                                                                  )
                                                                }
                                                            )
                                                        )
                                                        (command.DBracket
                                                          expr: 
                                                            (bool_expr.Unary
                                                              op_id: Id.BoolUnary_f
                                                              child: 
                                                                {
                                                                  (DQ 
                                                                    ($ Id.VSub_DollarName '$device') </> ($ Id.VSub_DollarName '$filedir') </pkginfo>
                                                                  )
                                                                }
                                                            )
                                                        )
                                                      ]
                                                    )
                                                  terminator: <Id.Op_Semi _>
                                                )
                                              ]
                                              action: [
                                                (command.ShAssignment
                                                  pairs: [
                                                    (assign_pair
                                                      lhs: (sh_lhs_expr.Name name:pkginst_list)
                                                      op: assign_op.PlusEqual
                                                      rhs: 
                                                        {
                                                          (sh_array_literal
                                                            left: <Id.Op_LParen _>
                                                            words: [
                                                              {
                                                                (braced_var_sub
                                                                  token: <Id.VSub_Name pkginst_list>
                                                                  bracket_op: 
                                                                    (bracket_op.WholeArray
                                                                      op_id: Id.Lit_At
                                                                    )
                                                                  suffix_op: 
                                                                    (suffix_op.Unary
                                                                      op_id: Id.VTest_ColonHyphen
                                                                      arg_word: {}
                                                                    )
                                                                )
                                                              }
                                                              {(DQ ($ Id.VSub_DollarName '$filedir'))}
                                                            ]
                                                          )
                                                        }
                                                      spids: [331]
                                                    )
                                                  ]
                                                )
                                              ]
                                              spids: [298 328]
                                            )
                                          ]
                                        )
                                      ]
                                    )
                                )
                                (command.ShAssignment
                                  pairs: [
                                    (assign_pair
                                      lhs: (sh_lhs_expr.Name name:pkginst_list)
                                      op: assign_op.Equal
                                      rhs: 
                                        {
                                          (DQ 
                                            (braced_var_sub
                                              token: <Id.VSub_Name pkginst_list>
                                              bracket_op: (bracket_op.WholeArray op_id:Id.Lit_At)
                                            )
                                          )
                                        }
                                      spids: [355]
                                    )
                                  ]
                                )
                              ]
                              spids: [266 277]
                            )
                          ]
                          else_action: [
                            (command.ShAssignment
                              pairs: [
                                (assign_pair
                                  lhs: (sh_lhs_expr.Name name:pkginst_list)
                                  op: assign_op.Equal
                                  rhs: 
                                    {
                                      (command_sub
                                        left_token: <Id.Left_DollarParen '$('>
                                        command_list: 
                                          (command.CommandList
                                            children: [
                                              (command.Pipeline
                                                children: [
                                                  (C {<strings>} 
                                                    {
                                                      (command_sub
                                                        left_token: <Id.Left_DollarParen '$('>
                                                        command_list: 
                                                          (command.CommandList
                                                            children: [
                                                              (C {<dequote>} 
                                                                {($ Id.VSub_DollarName '$device')}
                                                              )
                                                            ]
                                                          )
                                                      )
                                                    }
                                                  )
                                                  (C {<command>} {<grep>} {(DQ <'^PKG='>)})
                                                  (C {<sort>} {<-u>})
                                                  (C {<cut>} {<-d> <Id.Lit_Equals '='>} {<-f2>})
                                                ]
                                                negated: F
                                              )
                                            ]
                                          )
                                      )
                                    }
                                  spids: [369]
                                )
                              ]
                            )
                          ]
                        )
                        (command.ShAssignment
                          pairs: [
                            (assign_pair
                              lhs: (sh_lhs_expr.Name name:COMPREPLY)
                              op: assign_op.Equal
                              rhs: 
                                {
                                  (sh_array_literal
                                    left: <Id.Op_LParen _>
                                    words: [
                                      {
                                        (command_sub
                                          left_token: <Id.Left_DollarParen '$('>
                                          command_list: 
                                            (command.CommandList
                                              children: [
                                                (C {<compgen>} {<-W>} 
                                                  {(DQ ($ Id.VSub_DollarName '$pkginst_list'))} {<-->} {(${ Id.VSub_Name cur)}
                                                )
                                              ]
                                            )
                                        )
                                      }
                                    ]
                                  )
                                }
                              spids: [411]
                            )
                          ]
                        )
                      ]
                    )
                  ]
                  spids: [202 203 -1 436]
                )
              ]
            )
          ]
        )
    )
    (C {<complete>} {<-F>} {<_pkgadd>} {<pkgadd>})
  ]
)