// File: /workspace/github_c_makefile_star2_O1/taeguk[P]Compiler-Proj-Cminus/src/cgen.c
// Function: localCodeGen
static int localCodeGen(TreeNode *syntaxTree, FILE *codeStream, int currStack, int travSibling)
{
  TreeNode *t;
  for(t = syntaxTree;
      t != NULL;
      t = travSibling ? t->sibling : NULL)
    {
      switch (t->nodeKind)
        {

        case VariableDeclarationK:
        {
          int size = sizeof(int);

          fprintf(codeStream, "\n# Local variable declaration\n");
          fprintf(codeStream, "addiu $sp, $sp, %d\n", -size);
          currStack += size;
          t->attr.varDecl._var->symbolInfo->attr.intInfo.memloc = -currStack;
          break;
        }
        case ArrayDeclarationK:
        {
          int size = regSize * t->attr.varDecl._var->symbolInfo->attr.arrInfo.arrLen;
          fprintf(codeStream, "\n# Local array declaration\n");
          fprintf(codeStream, "addiu $sp, $sp, %d\n", -size);
          t->attr.varDecl._var->symbolInfo->attr.arrInfo.memloc = -currStack-size;
          currStack += size;
          break;
        }

        case CompoundStatementK:
        {
          fprintf(codeStream, "\n# Compound Statement\n");
          int updateStack = currStack;

          updateStack = localCodeGen(t->attr.cmpdStmt.local_decl, codeStream, updateStack, 1);
          if(localCodeGen(t->attr.cmpdStmt.stmt_list, codeStream, updateStack, 1) != updateStack, 1)
            DONT_OCCUR_PRINT;

          // stack cleanup
          if(updateStack < currStack)
            DONT_OCCUR_PRINT;

          fprintf(codeStream, "\n# Local stack cleanup\n");
          fprintf(codeStream, "addiu $sp, $sp, %d\n", updateStack - currStack);

          /*
          if(updateStack > 0) // it does not have return stmt
            {
              fprintf(codeStream, "\n# Local stack cleanup\n");
              fprintf(codeStream, "addiu $sp, $sp, %d\n", updateStack - currStack);
            }
          */
          break;
        }
        case ExpressionStatementK:
        {
          if(localCodeGen(t->attr.exprStmt.expr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          break;
        }
        case SelectionStatementK:
        {
          fprintf(codeStream, "\n# Selection Statement\n");
          fprintf(codeStream, "# Selection Statement Expression\n");
          if(localCodeGen(t->attr.selectStmt.expr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          int L_exit = labelAlloc(), L_false = labelAlloc();
          fprintf(codeStream, "beqz $v0, L%d\n", L_false);
          fprintf(codeStream, "# Selection Statement If Statement\n");
          if(localCodeGen(t->attr.selectStmt.if_stmt, codeStream, currStack, 1) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "j L%d\n", L_exit);
          fprintf(codeStream, "L%d:\n", L_false);
          fprintf(codeStream, "# Selection Statement Else Statement\n");
          if(localCodeGen(t->attr.selectStmt.else_stmt, codeStream, currStack, 1) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "L%d:\n", L_exit);
          break;
        }
        case IterationStatementK:
        {
          fprintf(codeStream, "\n# Iteration Statement\n");
          int L_cmp = labelAlloc(), L_loop = labelAlloc();
          fprintf(codeStream, "j L%d\n", L_cmp);
          fprintf(codeStream, "L%d:\n", L_loop);
          fprintf(codeStream, "# Iteration Statement Loop Statement\n");
          if(localCodeGen(t->attr.iterStmt.loop_stmt, codeStream, currStack, 1) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "L%d:\n", L_cmp);
          fprintf(codeStream, "# Iteration Statement Expression\n");
          if(localCodeGen(t->attr.iterStmt.expr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "bnez $v0, L%d\n", L_loop);
          break;
        }
        case ReturnStatementK:
        {
          // TODO: review this
          // ex) have to jr immediatly (but have to clean stack with prev value
          // of registers. no need to load. just roll up the stack.)
          // int f(int i) {
          //   if(i) {
          //     int j;
          //     return 1;
          //   }
          //   return 0;
          // }
          if(t->attr.retStmt.expr != NULL)
            if(localCodeGen(t->attr.retStmt.expr, codeStream, currStack, 0) != currStack)
              DONT_OCCUR_PRINT;

          fprintf(codeStream, "j L%d\n", L_cleanup);

          break;

          /*
          // cleanup
          fprintf(codeStream, "\n# Stack cleanup\n");

          // return to original sp
          fprintf(codeStream, "addiu $sp, $sp, %d\n", currStack - 10 * regSize);

          // load register $fp
          fprintf(codeStream, "lw $fp, %d($sp)\n", 0 * regSize);
          // load registers $s0~$s7
          int i;
          for(i=0; i<8; ++i)
            fprintf(codeStream, "lw $s%d, %d($sp)\n", i, (i+1) * regSize);
          // load register $ra
          fprintf(codeStream, "lw $ra, %d($sp)\n", 9 * regSize);

          // free stack
          fprintf(codeStream, "addiu $sp, $sp, %d\n", 10 * regSize);

          // return
          fprintf(codeStream, "\n# Return to caller\n");
          fprintf(codeStream, "jr $ra\n\n");
          */

          // Optimization: do not need to check other stmts
          //return 0;
        }

        case AssignExpressionK:
        {
          if(localCodeGen(t->attr.assignStmt.expr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          if (t->attr.assignStmt._var->nodeKind == VariableK)
            {
              fprintf(codeStream,
                      t->attr.assignStmt._var->symbolInfo->attr.intInfo.globalFlag ?
                      "sw $v0, %d\n" : "sw $v0, %d($fp)\n",
                      t->attr.assignStmt._var->symbolInfo->attr.intInfo.memloc);
            }
          else if (t->attr.assignStmt._var->nodeKind == ArrayK)
            {
              fprintf(codeStream, "move $s1, $v0\n");
              {
                TreeNode* arr = t->attr.assignStmt._var;
                if(localCodeGen(arr->attr.arr.arr_expr, codeStream, currStack, 0) != currStack)
                  DONT_OCCUR_PRINT;
                fprintf(codeStream, "li $s0, %lu\n", sizeof(int));
                fprintf(codeStream, "mul $s0, $v0, $s0\n");
                if(localCodeGen(arr->attr.arr._var, codeStream, currStack, 0) != currStack)
                  DONT_OCCUR_PRINT;
                fprintf(codeStream, "add $v0, $v0, $s0\n");
              }
              /*
              if(localCodeGen(t->attr.assignStmt._var, codeStream, currStack) != currStack)
                DONT_OCCUR_PRINT;*/
              fprintf(codeStream, "sw $s1, 0($v0)\n");
              fprintf(codeStream, "move $v0, $s1\n");
            }
          else
            DONT_OCCUR_PRINT;
          break;
        }
        case ComparisonExpressionK:
        {
          if(localCodeGen(t->attr.cmpExpr.lexpr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "addiu $sp, $sp, -%lu\n", sizeof(int));
          fprintf(codeStream, "sw $v0, 0($sp)\n");
          currStack += sizeof(int);

          if(localCodeGen(t->attr.cmpExpr.rexpr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "lw $s0, 0($sp)\n");
          fprintf(codeStream, "addiu $sp, $sp, %lu\n", sizeof(int));
          currStack -= sizeof(int);

          switch(t->attr.cmpExpr.op->attr.TOK)
            {
            case LT: fprintf(codeStream, "slt $v0, $s0, $v0\n"); break;
            case LE: fprintf(codeStream, "sle $v0, $s0, $v0\n"); break;
            case GT: fprintf(codeStream, "sgt $v0, $s0, $v0\n"); break;
            case GE: fprintf(codeStream, "sge $v0, $s0, $v0\n"); break;
            case EQ: fprintf(codeStream, "seq $v0, $s0, $v0\n"); break;
            case NE: fprintf(codeStream, "sne $v0, $s0, $v0\n"); break;
            default: DONT_OCCUR_PRINT;
            }
          break;
        }
        case AdditiveExpressionK:
        {
          if(localCodeGen(t->attr.addExpr.lexpr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "addiu $sp, $sp, -%lu\n", sizeof(int));
          fprintf(codeStream, "sw $v0, 0($sp)\n");
          currStack += sizeof(int);

          if(localCodeGen(t->attr.addExpr.rexpr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "lw $s0, 0($sp)\n");
          fprintf(codeStream, "addiu $sp, $sp, %lu\n", sizeof(int));
          currStack -= sizeof(int);

          switch(t->attr.addExpr.op->attr.TOK)
            {
            case PLUS: fprintf(codeStream, "add $v0, $s0, $v0\n"); break;
            case MINUS: fprintf(codeStream, "sub $v0, $s0, $v0\n"); break;
            default: DONT_OCCUR_PRINT;
            }
          break;
          //return currStack; //break;
        }
        case MultiplicativeExpressionK:
        {
          if(localCodeGen(t->attr.multExpr.lexpr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "addiu $sp, $sp, -%lu\n", sizeof(int));
          fprintf(codeStream, "sw $v0, 0($sp)\n");
          currStack += sizeof(int);

          if(localCodeGen(t->attr.multExpr.rexpr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "lw $s0, 0($sp)\n");
          fprintf(codeStream, "addiu $sp, $sp, %lu\n", sizeof(int));
          currStack -= sizeof(int);

          switch(t->attr.multExpr.op->attr.TOK)
            {
            case TIMES: fprintf(codeStream, "mul $v0, $s0, $v0\n"); break;
            case OVER: fprintf(codeStream, "div $v0, $s0, $v0\n"); break;
            default: DONT_OCCUR_PRINT;
            }
          break;
        }

        case CallK:
        {
          int accLoc = 0, i;
          TreeNode *expr;
          if (!strcmp(t->attr.call._var->attr.ID, "input"))
            {
              // print "input : "
              fprintf(codeStream, "\n# input\n");
              fprintf(codeStream, "li $v0, 4\n");
              fprintf(codeStream, "la $a0, input_str\n");
              fprintf(codeStream, "syscall\n");
              // read_int
              fprintf(codeStream, "li $v0, 5\n");
              fprintf(codeStream, "syscall\n");
            }
          else if (!strcmp(t->attr.call._var->attr.ID, "output"))
            {
              // print "output : "
              fprintf(codeStream, "\n# output\n");
              fprintf(codeStream, "move $t0, $v0\n");
              fprintf(codeStream, "li $v0, 4\n");
              fprintf(codeStream, "la $a0, output_str\n");
              fprintf(codeStream, "syscall\n");
              fprintf(codeStream, "move $v0, $t0\n");
              // print_int
              if (localCodeGen(t->attr.call.expr_list, codeStream, currStack + accLoc, 1) != (currStack + accLoc))
                DONT_OCCUR_PRINT;
              fprintf(codeStream, "move $a0, $v0\n"); // the argument
              fprintf(codeStream, "li $v0, 1\n");
              fprintf(codeStream, "syscall\n");
              // print newline
              fprintf(codeStream, "li $v0, 4\n");
              fprintf(codeStream, "la $a0, newline\n");
              fprintf(codeStream, "syscall\n");
            }
          else
            {
              for(expr = t->attr.call.expr_list, i = 0;
                  expr != NULL;
                  expr = expr->sibling, i++)
                {
                  int size;
                  switch(t->attr.call._var->symbolInfo->attr.funcInfo.paramTypeList[i])
                    {
                    case IntT: size = sizeof(int); break;
                    case IntArrayT: size = regSize; break;
                    default: DONT_OCCUR_PRINT;
                    }

                  if(localCodeGen(expr, codeStream, currStack + accLoc, 0) != (currStack + accLoc))
                    DONT_OCCUR_PRINT;

                  fprintf(codeStream, "addiu $sp, $sp, %d\n", -size);
                  fprintf(codeStream, "sw $v0, 0($sp)\n");
                  accLoc += size;
                }
              fprintf(codeStream, "jal %s\n", t->attr.call._var->attr.ID);
              fprintf(codeStream, "addiu $sp, $sp, %d\n", accLoc);
            }

          break;
          /* For fixing a bug about iteration of sibling in parameter passing. */
          //return currStack;//break;
        }

        case ArrayK:
        {
          if(localCodeGen(t->attr.arr.arr_expr, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "li $s0, %lu\n", sizeof(int));
          fprintf(codeStream, "mul $s0, $v0, $s0\n");
          if(localCodeGen(t->attr.arr._var, codeStream, currStack, 0) != currStack)
            DONT_OCCUR_PRINT;
          fprintf(codeStream, "add $v0, $v0, $s0\n");
          fprintf(codeStream, "lw $v0, 0($v0)\n");
          
          break;
          /* For fixing a bug about iteration of sibling in parameter passing. */
          //return currStack;//break;
        }
        case VariableK:
        {
          switch(t->symbolInfo->nodeType)
            {
            case IntT:
              fprintf(codeStream,
                      t->symbolInfo->attr.intInfo.globalFlag ? "lw $v0, %d\n" : "lw $v0, %d($fp)\n",
                      t->symbolInfo->attr.intInfo.memloc);
              break;
            case IntArrayT:
              fprintf(codeStream,
                      t->symbolInfo->attr.arrInfo.globalFlag ? "li $v0, %d\n" : "addiu $v0, $fp, %d\n",
                      t->symbolInfo->attr.arrInfo.memloc);
              if (t->symbolInfo->attr.arrInfo.isParam)
                fprintf(codeStream, "lw $v0, 0($v0)\n");
              break;
            default:
              DONT_OCCUR_PRINT;
            }

          break;
          /* For fixing a bug about iteration of sibling in parameter passing. */
          //return currStack;//break;
        }
        case ConstantK:
        {
          fprintf(codeStream, "li $v0, %d\n", t->attr.NUM);
          
          break;
          /* For fixing a bug about iteration of sibling in parameter passing. */
          //return currStack;//break;
        }

        default:
          DONT_OCCUR_PRINT;
        }
    }
  return currStack;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r12d
testq %rdi, %rdi
je 0x2f06
movl %ecx, %r13d
movq %rsi, %r15
movq %rdi, %rcx
leaq 0x4222(%rip), %r14      # 0x65b4
leaq 0x4311(%rip), %rbx      # 0x66aa
movl %r13d, -0x34(%rbp)
movl 0xc(%rcx), %eax
decl %eax
cmpl $0x11, %eax
movq %rcx, -0x30(%rbp)
ja 0x2c05
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movl $0x1e, %esi
movl $0x1, %edx
leaq 0x43f1(%rip), %rdi      # 0x67ba
movl %r13d, %r14d
movq %rcx, %r13
movq %r15, %rcx
callq 0x11c0
movq %r15, %rdi
movq %rbx, %rsi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
xorl %eax, %eax
callq 0x1120
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
movq %r12, %rbx
subl %ebx, %eax
addl $0x4, %ebx
movq 0x28(%r13), %rcx
movl %r14d, %r13d
leaq 0x41b0(%rip), %r14      # 0x65b4
jmp 0x27d4
movq 0x20(%rcx), %rax
movq 0x20(%rax), %r14
movq %r14, %rdi
leaq 0x3f90(%rip), %rsi      # 0x63ab
callq 0x1110
testl %eax, %eax
je 0x2b69
movq %r14, %rdi
leaq 0x3fb0(%rip), %rsi      # 0x63e2
callq 0x1110
testl %eax, %eax
je 0x2d35
movq -0x30(%rbp), %rax
movq 0x28(%rax), %r14
xorl %r13d, %r13d
leaq 0x4259(%rip), %rbx      # 0x66aa
testq %r14, %r14
je 0x2b33
leal (%r12,%r13), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2365
movq %r15, %rdi
movq %rbx, %rsi
movl $0xfffffffc, %edx       # imm = 0xFFFFFFFC
xorl %eax, %eax
callq 0x1120
movl $0xf, %esi
movl $0x1, %edx
leaq 0x4533(%rip), %rdi      # 0x69c1
movq %r15, %rcx
callq 0x11c0
addl $0x4, %r13d
movq (%r14), %r14
jmp 0x2451
movq 0x20(%rcx), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl $0x4, %edx
movq %r15, %rdi
leaq 0x44ea(%rip), %rsi      # 0x69ab
xorl %eax, %eax
callq 0x1120
movl $0xf, %esi
movl $0x1, %edx
leaq 0x44e8(%rip), %rdi      # 0x69c1
movq %r15, %rcx
callq 0x11c0
leal 0x4(%r12), %edx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2365
movl $0xf, %esi
movl $0x1, %edx
leaq 0x44c8(%rip), %rdi      # 0x69d1
movq %r15, %rcx
callq 0x11c0
movl $0x4, %edx
movq %r15, %rdi
leaq 0x44c1(%rip), %rsi      # 0x69e1
xorl %eax, %eax
callq 0x1120
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x20(%rax), %eax
cmpl $0x10e, %eax            # imm = 0x10E
je 0x2c0d
cmpl $0x10d, %eax            # imm = 0x10D
jne 0x2ee3
movl $0x12, %esi
movl $0x1, %edx
leaq 0x4535(%rip), %rdi      # 0x6a8e
jmp 0x2edb
movq 0x28(%rcx), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
movq %rcx, %r12
xorl %ecx, %ecx
callq 0x2365
movl $0x4, %edx
movq %r15, %rdi
leaq 0x43d6(%rip), %rsi      # 0x6959
xorl %eax, %eax
callq 0x1120
movl $0x12, %esi
movl $0x1, %edx
leaq 0x43cb(%rip), %rdi      # 0x6966
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r12), %rdi
movq %r15, %rsi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl $0x12, %esi
movl $0x1, %edx
leaq 0x43b4(%rip), %rdi      # 0x6979
movq %r15, %rcx
callq 0x11c0
movl $0xf, %esi
movl $0x1, %edx
leaq 0x4582(%rip), %rdi      # 0x6b60
jmp 0x2edb
movl $0x16, %esi
movl $0x1, %edx
leaq 0x4201(%rip), %rdi      # 0x67f5
movl %r13d, %ebx
movq %rcx, %r13
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r13), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl $0x1, %ecx
callq 0x2365
movl %eax, %r14d
movq 0x28(%r13), %rdi
movl %ebx, %r13d
movq %r15, %rsi
movl %eax, %edx
movl $0x1, %ecx
callq 0x2365
movl $0x17, %esi
movl $0x1, %edx
leaq 0x41cc(%rip), %rdi      # 0x680c
movq %r15, %rcx
callq 0x11c0
subl %r12d, %r14d
movq %r15, %rdi
leaq 0x4055(%rip), %rsi      # 0x66aa
movq %r12, %rbx
movl %r14d, %edx
leaq 0x3f52(%rip), %r14      # 0x65b4
jmp 0x299f
movl $0x17, %esi
movl $0x1, %edx
leaq 0x4246(%rip), %rdi      # 0x68be
movq %rcx, %r13
movq %r15, %rcx
callq 0x11c0
movl 0x8aa2(%rip), %r14d     # 0xb12c
leal 0x1(%r14), %ebx
movl %ebx, -0x38(%rbp)
leal 0x2(%r14), %eax
movl %eax, 0x8a91(%rip)      # 0xb12c
movq %r15, %rdi
leaq 0x41ec(%rip), %rsi      # 0x6891
movl %r14d, %edx
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
leaq 0x4095(%rip), %rsi      # 0x674e
movl %ebx, %edx
xorl %eax, %eax
callq 0x1120
movl $0x25, %esi
movl $0x1, %edx
leaq 0x4203(%rip), %rdi      # 0x68d6
movq %r15, %rcx
callq 0x11c0
movq 0x28(%r13), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
movl $0x1, %ecx
callq 0x2365
movq %r15, %rdi
leaq 0x4053(%rip), %rsi      # 0x674e
movl %r14d, %edx
leaq 0x3eaf(%rip), %r14      # 0x65b4
xorl %eax, %eax
callq 0x1120
movl $0x21, %esi
movl $0x1, %edx
leaq 0x41df(%rip), %rdi      # 0x68fc
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r13), %rdi
movq %r15, %rsi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movq %r15, %rdi
leaq 0x41df(%rip), %rsi      # 0x691e
movl -0x38(%rbp), %edx
jmp 0x299b
movq 0x18(%rcx), %rax
movl (%rax), %ecx
cmpl $0x5, %ecx
je 0x2c23
cmpl $0x4, %ecx
movq %r12, %rbx
jne 0x2ee3
cmpl $0x0, 0x10(%rax)
leaq 0x4403(%rip), %rsi      # 0x6b70
leaq 0x4408(%rip), %rcx      # 0x6b7c
jmp 0x2853
movq 0x28(%rcx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %r13d
leal (,%r13,4), %r14d
movl $0x1b, %esi
movl $0x1, %edx
leaq 0x403b(%rip), %rdi      # 0x67d9
movq %r15, %rcx
callq 0x11c0
negl %r14d
movq %r15, %rdi
movq %rbx, %rsi
movl %r14d, %edx
leaq 0x3dfb(%rip), %r14      # 0x65b4
xorl %eax, %eax
callq 0x1120
leal (%r12,%r13,4), %ebx
movl -0x34(%rbp), %r13d
movl %ebx, %eax
negl %eax
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq 0x18(%rcx), %rcx
movl %eax, 0xc(%rcx)
jmp 0x2ee3
movq 0x20(%rcx), %rdi
testq %rdi, %rdi
movq %r12, %rbx
je 0x27f8
movq %r15, %rsi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl 0x892a(%rip), %edx      # 0xb128
movq %r15, %rdi
leaq 0x4089(%rip), %rsi      # 0x6891
jmp 0x299f
movq 0x20(%rcx), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
movq %rcx, %r12
xorl %ecx, %ecx
callq 0x2365
movq 0x28(%r12), %rax
movl 0xc(%rax), %ecx
cmpl $0x10, %ecx
je 0x2c60
cmpl $0xf, %ecx
jne 0x2ee3
movq 0x18(%rax), %rax
cmpl $0x0, 0x10(%rax)
leaq 0x40e1(%rip), %rsi      # 0x692d
leaq 0x40e6(%rip), %rcx      # 0x6939
cmoveq %rcx, %rsi
movl 0xc(%rax), %edx
movq %r15, %rdi
jmp 0x299f
movl 0x20(%rcx), %edx
movq %r15, %rdi
leaq 0x431e(%rip), %rsi      # 0x6b8d
xorl %eax, %eax
callq 0x1120
jmp 0x2c05
movq 0x20(%rcx), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
jmp 0x2ee3
movl $0x17, %esi
movl $0x1, %edx
leaq 0x3f80(%rip), %rdi      # 0x6824
movq %rcx, %r14
movq %r15, %rcx
callq 0x11c0
movl $0x21, %esi
movl $0x1, %edx
leaq 0x3f7c(%rip), %rdi      # 0x683c
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r14), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl 0x884a(%rip), %r13d     # 0xb12c
leal 0x1(%r13), %edx
movl %edx, -0x38(%rbp)
leal 0x2(%r13), %eax
movl %eax, 0x8839(%rip)      # 0xb12c
movq %r15, %rdi
leaq 0x3f61(%rip), %rsi      # 0x685e
xorl %eax, %eax
callq 0x1120
movl $0x23, %esi
movl $0x1, %edx
leaq 0x3f58(%rip), %rdi      # 0x686d
movq %r15, %rcx
callq 0x11c0
movq 0x28(%r14), %rdi
movq %r15, %rsi
movl %ebx, %edx
movl $0x1, %ecx
callq 0x2365
movq %r15, %rdi
leaq 0x3f57(%rip), %rsi      # 0x6891
movl %r13d, %edx
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
leaq 0x3e00(%rip), %r12      # 0x674e
movq %r12, %rsi
movl -0x38(%rbp), %edx
leaq 0x3c59(%rip), %r14      # 0x65b4
xorl %eax, %eax
callq 0x1120
movl $0x25, %esi
movl $0x1, %edx
leaq 0x3f25(%rip), %rdi      # 0x6898
movq %r15, %rcx
callq 0x11c0
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq %r15, %rsi
movl %ebx, %edx
movl $0x1, %ecx
callq 0x2365
movq %r15, %rdi
movq %r12, %rsi
movl %r13d, %edx
movl -0x34(%rbp), %r13d
xorl %eax, %eax
callq 0x1120
jmp 0x2ee3
movq 0x20(%rcx), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl $0x4, %edx
movq %r15, %rdi
leaq 0x3fde(%rip), %rsi      # 0x69ab
xorl %eax, %eax
callq 0x1120
movl $0xf, %esi
movl $0x1, %edx
leaq 0x3fdc(%rip), %rdi      # 0x69c1
movq %r15, %rcx
callq 0x11c0
leal 0x4(%r12), %edx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2365
movl $0xf, %esi
movl $0x1, %edx
leaq 0x3fbc(%rip), %rdi      # 0x69d1
movq %r15, %rcx
callq 0x11c0
movl $0x4, %edx
movq %r15, %rdi
leaq 0x3fb5(%rip), %rsi      # 0x69e1
xorl %eax, %eax
callq 0x1120
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x20(%rax), %eax
cmpl $0x10c, %eax            # imm = 0x10C
je 0x2d1f
cmpl $0x10b, %eax            # imm = 0x10B
jne 0x2ee3
movl $0x12, %esi
movl $0x1, %edx
leaq 0x4003(%rip), %rdi      # 0x6a68
jmp 0x2edb
movq 0x20(%rcx), %rdi
movq %r15, %rsi
movq %r12, %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl $0x4, %edx
movq %r15, %rdi
leaq 0x3f1f(%rip), %rsi      # 0x69ab
xorl %eax, %eax
callq 0x1120
movl $0xf, %esi
movl $0x1, %edx
leaq 0x3f1d(%rip), %rdi      # 0x69c1
movq %r15, %rcx
callq 0x11c0
leal 0x4(%r12), %edx
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2365
movl $0xf, %esi
movl $0x1, %edx
leaq 0x3efd(%rip), %rdi      # 0x69d1
movq %r15, %rcx
callq 0x11c0
movl $0x4, %edx
movq %r15, %rdi
leaq 0x3ef6(%rip), %rsi      # 0x69e1
xorl %eax, %eax
callq 0x1120
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x20(%rax), %eax
movl $0xfffffef1, %ecx       # imm = 0xFFFFFEF1
addl %ecx, %eax
cmpl $0x5, %eax
ja 0x2ee3
leaq 0x3ae8(%rip), %rcx      # 0x65fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3ec8(%rip), %rdi      # 0x69f6
jmp 0x2edb
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x20(%rax), %rdx
movq %r15, %rdi
leaq 0x400f(%rip), %rsi      # 0x6b58
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
movq %rbx, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x1120
movl -0x34(%rbp), %r13d
jmp 0x2bfe
movl $0x9, %esi
movl $0x1, %edx
leaq 0x3f3a(%rip), %rdi      # 0x6ab4
movq %r15, %rcx
callq 0x11c0
movl $0xa, %esi
movl $0x1, %edx
leaq 0x3f2b(%rip), %rdi      # 0x6abe
movq %r15, %rcx
callq 0x11c0
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3f1d(%rip), %rdi      # 0x6ac9
movq %r15, %rcx
callq 0x11c0
movl $0x8, %esi
movl $0x1, %edx
leaq 0x3f17(%rip), %rbx      # 0x6adc
movq %rbx, %rdi
movq %r15, %rcx
callq 0x11c0
movl $0xa, %esi
movl $0x1, %edx
leaq 0x3f04(%rip), %rdi      # 0x6ae5
movq %r15, %rcx
callq 0x11c0
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x11c0
leaq 0x39af(%rip), %r14      # 0x65b4
movq %r12, %rbx
jmp 0x2ee3
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3e83(%rip), %rdi      # 0x6aa1
jmp 0x2edb
cmpl $0x0, 0x10(%rax)
leaq 0x3f5f(%rip), %rsi      # 0x6b8d
leaq 0x3f64(%rip), %rcx      # 0x6b99
cmoveq %rcx, %rsi
movl 0xc(%rax), %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0x1120
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x8(%rax)
movq %r12, %rbx
jne 0x25cd
jmp 0x2ee3
movl $0xe, %esi
movl $0x1, %edx
leaq 0x3cd9(%rip), %rdi      # 0x694a
movq %r15, %rcx
callq 0x11c0
movq -0x30(%rbp), %rax
movq 0x28(%rax), %r14
movq 0x28(%r14), %rdi
movq %r15, %rsi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl $0x4, %edx
movq %r15, %rdi
leaq 0x3cb9(%rip), %rsi      # 0x6959
xorl %eax, %eax
callq 0x1120
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3cae(%rip), %rdi      # 0x6966
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r14), %rdi
leaq 0x38e9(%rip), %r14      # 0x65b4
movq %r15, %rsi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x2365
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3c91(%rip), %rdi      # 0x6979
movq %r15, %rcx
callq 0x11c0
movl $0xf, %esi
movl $0x1, %edx
leaq 0x3c8b(%rip), %rdi      # 0x698c
movq %r15, %rcx
callq 0x11c0
movl $0xe, %esi
movl $0x1, %edx
leaq 0x3c82(%rip), %rdi      # 0x699c
jmp 0x2edb
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3d4b(%rip), %rdi      # 0x6a7b
jmp 0x2edb
movq %r12, %rbx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x3da7(%rip), %rdi      # 0x6af0
movq %r15, %rcx
callq 0x11c0
movl $0xe, %esi
movl $0x1, %edx
leaq 0x3d99(%rip), %rdi      # 0x6afb
movq %r15, %rcx
callq 0x11c0
movl $0xa, %esi
movl $0x1, %edx
leaq 0x3d43(%rip), %r14      # 0x6abe
movq %r14, %rdi
movq %r15, %rcx
callq 0x11c0
movl $0x13, %esi
movl $0x1, %edx
leaq 0x3d73(%rip), %rdi      # 0x6b0a
movq %r15, %rcx
callq 0x11c0
movl $0x8, %esi
movl $0x1, %edx
leaq 0x3d2c(%rip), %r12      # 0x6adc
movq %r12, %rdi
movq %r15, %rcx
callq 0x11c0
movl $0xe, %esi
movl $0x1, %edx
leaq 0x3d52(%rip), %rdi      # 0x6b1e
movq %r15, %rcx
callq 0x11c0
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
movq %r15, %rsi
movl %ebx, %edx
movl $0x1, %ecx
callq 0x2365
movl $0xe, %esi
movl $0x1, %edx
leaq 0x3d31(%rip), %rdi      # 0x6b2d
movq %r15, %rcx
callq 0x11c0
movl $0xa, %esi
movl $0x1, %edx
leaq 0x3d27(%rip), %rdi      # 0x6b3c
movq %r15, %rcx
callq 0x11c0
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x11c0
movl $0xa, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rcx
callq 0x11c0
movl $0x10, %esi
movl $0x1, %edx
leaq 0x3cef(%rip), %rdi      # 0x6b47
movq %r15, %rcx
callq 0x11c0
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rcx
callq 0x11c0
leaq 0x3738(%rip), %r14      # 0x65b4
jmp 0x2ee3
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3bb3(%rip), %rdi      # 0x6a42
jmp 0x2edb
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3b7a(%rip), %rdi      # 0x6a1c
jmp 0x2edb
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3b7a(%rip), %rdi      # 0x6a2f
jmp 0x2edb
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3b41(%rip), %rdi      # 0x6a09
jmp 0x2edb
movl $0x12, %esi
movl $0x1, %edx
leaq 0x3b7a(%rip), %rdi      # 0x6a55
movq %r15, %rcx
callq 0x11c0
movq %rbx, %r12
testl %r13d, %r13d
je 0x2ef4
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
jmp 0x2ef6
xorl %ecx, %ecx
leaq 0x37ad(%rip), %rbx      # 0x66aa
testq %rcx, %rcx
jne 0x239d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq