(CommandList
  children: [
    (FuncDef
      name: rolldie
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:dice)
                  op: Equal
                  rhs: {($ VSub_Number '$1')}
                  spids: [23]
                )
              ]
              spids: [23]
            )
            (Assignment
              keyword: Assign_None
              pairs: [(assign_pair lhs:(LhsName name:dicecount) op:Equal rhs:{(1)} spids:[27])]
              spids: [27]
            )
            (Assignment
              keyword: Assign_None
              pairs: [(assign_pair lhs:(LhsName name:sum) op:Equal rhs:{(0)} spids:[31])]
              spids: [31]
            )
            (If
              arms: [
                (if_arm
                  cond: [
                    (Sentence
                      child: 
                        (C {(Lit_Other '[')} {(-z)} 
                          {
                            (DQ 
                              (CommandSubPart
                                command_list: 
                                  (CommandList
                                    children: [
                                      (Pipeline
                                        children: [
                                          (C {(echo)} {($ VSub_Name '$dice')})
                                          (C {(grep)} {(SQ <d>)})
                                        ]
                                        negated: False
                                      )
                                    ]
                                  )
                                left_token: <Left_CommandSub '$('>
                                spids: [48 60]
                              )
                            )
                          } {(Lit_Other ']')}
                        )
                      terminator: <Op_Semi ';'>
                    )
                  ]
                  action: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [(assign_pair lhs:(LhsName name:quantity) op:Equal rhs:{(1)} spids:[70])]
                      spids: [70]
                    )
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:sides)
                          op: Equal
                          rhs: {($ VSub_Name '$dice')}
                          spids: [74]
                        )
                      ]
                      spids: [74]
                    )
                  ]
                  spids: [-1 67]
                )
              ]
              else_action: [
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:quantity)
                      op: Equal
                      rhs: 
                        {
                          (CommandSubPart
                            command_list: 
                              (CommandList
                                children: [
                                  (Pipeline
                                    children: [
                                      (C {(echo)} {($ VSub_Name '$dice')})
                                      (C {(cut)} {(-dd)} {(-f1)})
                                    ]
                                    negated: False
                                  )
                                ]
                              )
                            left_token: <Left_CommandSub '$('>
                            spids: [82 94]
                          )
                        }
                      spids: [81]
                    )
                  ]
                  spids: [81]
                )
                (If
                  arms: [
                    (if_arm
                      cond: [
                        (Sentence
                          child: 
                            (C {(Lit_Other '[')} {(-z)} {(DQ ($ VSub_Name '$quantity'))} 
                              {(Lit_Other ']')}
                            )
                          terminator: <Op_Semi ';'>
                        )
                      ]
                      action: [
                        (Assignment
                          keyword: Assign_None
                          pairs: [
                            (assign_pair
                              lhs: (LhsName name:quantity)
                              op: Equal
                              rhs: {(1)}
                              spids: [117]
                            )
                          ]
                          spids: [117]
                        )
                      ]
                      spids: [-1 111]
                    )
                  ]
                  spids: [-1 121]
                )
                (Assignment
                  keyword: Assign_None
                  pairs: [
                    (assign_pair
                      lhs: (LhsName name:sides)
                      op: Equal
                      rhs: 
                        {
                          (CommandSubPart
                            command_list: 
                              (CommandList
                                children: [
                                  (Pipeline
                                    children: [
                                      (C {(echo)} {($ VSub_Name '$dice')})
                                      (C {(cut)} {(-dd)} {(-f2)})
                                    ]
                                    negated: False
                                  )
                                ]
                              )
                            left_token: <Left_CommandSub '$('>
                            spids: [125 137]
                          )
                        }
                      spids: [124]
                    )
                  ]
                  spids: [124]
                )
              ]
              spids: [78 140]
            )
            (Sentence child:(C {(echo)} {(DQ )}) terminator:<Op_Semi ';'>)
            (C {(echo)} 
              {
                (DQ ('rolling ') ($ VSub_Name '$quantity') (' ') ($ VSub_Name '$sides') ('-sided die'))
              }
            )
            (While
              cond: [
                (Sentence
                  child: 
                    (C {(Lit_Other '[')} {($ VSub_Name '$dicecount')} {(-le)} {($ VSub_Name '$quantity')} 
                      {(Lit_Other ']')}
                    )
                  terminator: <Op_Semi ';'>
                )
              ]
              body: 
                (DoGroup
                  children: [
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:roll)
                          op: Equal
                          rhs: 
                            {
                              (ArithSubPart
                                anode: 
                                  (ArithBinary
                                    op_id: Arith_Plus
                                    left: 
                                      (ArithBinary
                                        op_id: Arith_Percent
                                        left: (ArithWord w:{($ VSub_Name '$RANDOM')})
                                        right: (ArithWord w:{($ VSub_Name '$sides')})
                                      )
                                    right: (ArithWord w:{(Lit_Digits 1)})
                                  )
                                spids: [186 203]
                              )
                            }
                          spids: [185]
                        )
                      ]
                      spids: [185]
                    )
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:sum)
                          op: Equal
                          rhs: 
                            {
                              (ArithSubPart
                                anode: 
                                  (ArithBinary
                                    op_id: Arith_Plus
                                    left: (ArithWord w:{($ VSub_Name '$sum')})
                                    right: (ArithWord w:{($ VSub_Name '$roll')})
                                  )
                                spids: [207 216]
                              )
                            }
                          spids: [206]
                        )
                      ]
                      spids: [206]
                    )
                    (C {(echo)} 
                      {(DQ ('  roll #') ($ VSub_Name '$dicecount') (' = ') ($ VSub_Name '$roll'))}
                    )
                    (Assignment
                      keyword: Assign_None
                      pairs: [
                        (assign_pair
                          lhs: (LhsName name:dicecount)
                          op: Equal
                          rhs: 
                            {
                              (ArithSubPart
                                anode: 
                                  (ArithBinary
                                    op_id: Arith_Plus
                                    left: (ArithWord w:{($ VSub_Name '$dicecount')})
                                    right: (ArithWord w:{(Lit_Digits 1)})
                                  )
                                spids: [230 239]
                              )
                            }
                          spids: [229]
                        )
                      ]
                      spids: [229]
                    )
                  ]
                  spids: [182 242]
                )
            )
            (C {(echo)} {(I)} {(rolled)} {($ VSub_Name '$dice')} {(and)} {(it)} {(added)} {(up)} {(to)} 
              {($ VSub_Name '$sum')}
            )
          ]
          spids: [20]
        )
      spids: [16 19]
    )
    (While
      cond: [
        (Sentence
          child: (C {(Lit_Other '[')} {($ VSub_Pound '$#')} {(-gt)} {(0)} {(Lit_Other ']')})
          terminator: <Op_Semi ';'>
        )
      ]
      body: 
        (DoGroup
          children: [
            (C {(rolldie)} {($ VSub_Number '$1')})
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:sumtotal)
                  op: Equal
                  rhs: 
                    {
                      (ArithSubPart
                        anode: 
                          (ArithBinary
                            op_id: Arith_Plus
                            left: (ArithWord w:{($ VSub_Name '$sumtotal')})
                            right: (ArithWord w:{($ VSub_Name '$sum')})
                          )
                        spids: [292 301]
                      )
                    }
                  spids: [291]
                )
              ]
              spids: [291]
            )
            (C {(shift)})
          ]
          spids: [283 306]
        )
    )
    (C {(echo)} {(DQ )})
    (C {(echo)} {(DQ ('In total, all of those dice add up to ') ($ VSub_Name '$sumtotal'))})
    (C {(echo)} {(DQ )})
    (C {(exit)} {(0)})
  ]
)