(CommandList
  children: [
    (FuncDef
      name: run-cmd-with-retries
      body: 
        (BraceGroup
          children: [
            (Assignment
              keyword: Assign_None
              pairs: [
                (assign_pair
                  lhs: (LhsName name:RETRIES)
                  op: Equal
                  rhs: 
                    {
                      (DQ 
                        (BracedVarSub
                          token: <VSub_Name RETRIES>
                          suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(3)})
                          spids: [56 60]
                        )
                      )
                    }
                  spids: [54]
                )
              ]
              spids: [54]
            )
            (ForEach
              iter_name: attempt
              iter_words: [
                {
                  (CommandSubPart
                    command_list: (CommandList children:[(C {(seq)} {(1)} {(${ VSub_Name RETRIES)})])
                    left_token: <Left_CommandSub "$(">
                    spids: [70 78]
                  )
                }
              ]
              do_arg_iter: False
              body: 
                (DoGroup
                  children: [
                    (Assignment
                      keyword: Assign_Local
                      pairs: [(assign_pair lhs:(LhsName name:ret_val) op:Equal rhs:{(0)} spids:[86])]
                      spids: [84]
                    )
                    (SimpleCommand
                      words: [{(exec)}]
                      redirects: [(Redir op_id:Redir_GreatAnd fd:5 arg_word:{(1)} spids:[92])]
                    )
                    (AndOr
                      children: [
                        (Assignment
                          keyword: Assign_None
                          pairs: [
                            (assign_pair
                              lhs: (LhsName name:result)
                              op: Equal
                              rhs: 
                                {
                                  (CommandSubPart
                                    command_list: 
                                      (CommandList
                                        children: [
                                          (Pipeline
                                            children: [
                                              (SimpleCommand
                                                words: [{(DQ ($ VSub_At "$@"))}]
                                                redirects: [
                                                  (Redir
                                                    op_id: Redir_GreatAnd
                                                    fd: 2
                                                    arg_word: {(1)}
                                                    spids: [113]
                                                  )
                                                ]
                                              )
                                              (C {(tee)} 
                                                {
                                                  (CommandSubPart
                                                    command_list: 
                                                      (CommandList
                                                        children: [
                                                          (SimpleCommand
                                                            words: [{(cat)} {(-)}]
                                                            redirects: [
                                                              (Redir
                                                                op_id: Redir_GreatAnd
                                                                fd: -1
                                                                arg_word: {(5)}
                                                                spids: [125]
                                                              )
                                                            ]
                                                          )
                                                        ]
                                                      )
                                                    left_token: <Left_ProcSubOut ">(">
                                                    spids: [120 127]
                                                  )
                                                }
                                              )
                                            ]
                                            negated: False
                                          )
                                        ]
                                      )
                                    left_token: <Left_CommandSub "$(">
                                    spids: [108 128]
                                  )
                                }
                              spids: [107]
                            )
                          ]
                          spids: [107]
                        )
                        (Assignment
                          keyword: Assign_None
                          pairs: [
                            (assign_pair
                              lhs: (LhsName name:ret_val)
                              op: Equal
                              rhs: {(DQ ($ VSub_QMark "$?"))}
                              spids: [132]
                            )
                          ]
                          spids: [132]
                        )
                      ]
                      op_id: Op_DPipe
                    )
                    (If
                      arms: [
                        (if_arm
                          cond: [
                            (Sentence
                              child: 
                                (DBracket
                                  expr: 
                                    (BoolBinary
                                      op_id: BoolBinary_ne
                                      left: 
                                        {
                                          (DQ 
                                            (BracedVarSub
                                              token: <VSub_Name ret_val>
                                              suffix_op: 
                                                (StringUnary
                                                  op_id: VTest_ColonHyphen
                                                  arg_word: {(0)}
                                                )
                                              spids: [143 147]
                                            )
                                          )
                                        }
                                      right: {(DQ (0))}
                                    )
                                )
                              terminator: <Op_Semi ";">
                            )
                          ]
                          action: [
                            (If
                              arms: [
                                (if_arm
                                  cond: [
                                    (Sentence
                                      child: 
                                        (DBracket
                                          expr: 
                                            (BoolBinary
                                              op_id: BoolBinary_gt
                                              left: 
                                                {
                                                  (CommandSubPart
                                                    command_list: 
                                                      (CommandList
                                                        children: [
                                                          (Pipeline
                                                            children: [
                                                              (C {(echo)} {(DQ (${ VSub_Name result))})
                                                              (C {(grep)} {(-c)} 
                                                                {(DQ ("already exists"))}
                                                              )
                                                            ]
                                                            negated: False
                                                          )
                                                        ]
                                                      )
                                                    left_token: <Left_CommandSub "$(">
                                                    spids: [166 184]
                                                  )
                                                }
                                              right: {(0)}
                                            )
                                        )
                                      terminator: <Op_Semi ";">
                                    )
                                  ]
                                  action: [
                                    (If
                                      arms: [
                                        (if_arm
                                          cond: [
                                            (Sentence
                                              child: 
                                                (DBracket
                                                  expr: 
                                                    (BoolBinary
                                                      op_id: BoolBinary_GlobDEqual
                                                      left: {(DQ (${ VSub_Name attempt))}
                                                      right: {(1)}
                                                    )
                                                )
                                              terminator: <Op_Semi ";">
                                            )
                                          ]
                                          action: [
                                            (SimpleCommand
                                              words: [
                                                {(echo)}
                                                {(-e)}
                                                {
                                                  (DQ (${ VSub_Name color_red) ("Failed to ") 
                                                    ($ VSub_Number "$1") (" ") ($ VSub_Number "$2") (" ") ($ VSub_Number "$3") 
                                                    (
" as the resource hasn't been deleted from a previous run."
                                                    ) (${ VSub_Name color_norm)
                                                  )
                                                }
                                              ]
                                              redirects: [
                                                (Redir
                                                  op_id: Redir_GreatAnd
                                                  fd: -1
                                                  arg_word: {(2)}
                                                  spids: [236]
                                                )
                                              ]
                                            )
                                            (C {(exit)} {(1)})
                                          ]
                                          spids: [-1 213]
                                        )
                                      ]
                                      spids: [-1 246]
                                    )
                                    (C {(echo)} {(-e)} 
                                      {
                                        (DQ (${ VSub_Name color_yellow) ("Succeeded to ") 
                                          ($ VSub_Number "$1") (" ") ($ VSub_Number "$2") (" ") ($ VSub_Number "$3") 
                                          (
" in the previous attempt, but status response wasn't received."
                                          ) (${ VSub_Name color_norm)
                                        )
                                      }
                                    )
                                    (ControlFlow
                                      token: <ControlFlow_Return return>
                                      arg_word: {(0)}
                                    )
                                  ]
                                  spids: [-1 193]
                                )
                              ]
                              spids: [-1 275]
                            )
                            (SimpleCommand
                              words: [
                                {(echo)}
                                {(-e)}
                                {
                                  (DQ (${ VSub_Name color_yellow) ("Attempt ") ($ VSub_Name "$attempt") 
                                    (" failed to ") ($ VSub_Number "$1") (" ") ($ VSub_Number "$2") (" ") ($ VSub_Number "$3") (". Retrying.") 
                                    (${ VSub_Name color_norm)
                                  )
                                }
                              ]
                              redirects: [
                                (Redir
                                  op_id: Redir_GreatAnd
                                  fd: -1
                                  arg_word: {(2)}
                                  spids: [300]
                                )
                              ]
                            )
                            (C {(sleep)} 
                              {
                                (ArithSubPart
                                  anode: 
                                    (ArithBinary
                                      op_id: Arith_Star
                                      left: (ArithWord w:{($ VSub_Name "$attempt")})
                                      right: (ArithWord w:{(Lit_Digits 5)})
                                    )
                                  spids: [307 314]
                                )
                              }
                            )
                          ]
                          spids: [-1 159]
                        )
                      ]
                      else_action: [
                        (C {(echo)} {(-e)} 
                          {
                            (DQ (${ VSub_Name color_green) ("Succeeded to ") ($ VSub_Number "$1") (" ") 
                              ($ VSub_Number "$2") (" ") ($ VSub_Number "$3") (.) (${ VSub_Name color_norm)
                            )
                          }
                        )
                        (ControlFlow
                          token: <ControlFlow_Return return>
                          arg_word: {(0)}
                        )
                      ]
                      spids: [317 346]
                    )
                  ]
                  spids: [81 349]
                )
              spids: [69 79]
            )
            (SimpleCommand
              words: [
                {(echo)}
                {(-e)}
                {
                  (DQ (${ VSub_Name color_red) ("Failed to ") ($ VSub_Number "$1") (" ") 
                    ($ VSub_Number "$2") (" ") ($ VSub_Number "$3") (.) (${ VSub_Name color_norm)
                  )
                }
              ]
              redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[372])]
            )
            (C {(exit)} {(1)})
          ]
          spids: [51]
        )
      spids: [47 50]
    )
  ]
)