// File: /workspace/github_c_makefile_star2_O2/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 %ecx, %r14d
movq %rdx, -0x38(%rbp)
movq %rsi, %r15
leaq 0x43a2(%rip), %rbx      # 0x65b4
movl %ecx, -0x2c(%rbp)
testq %rdi, %rdi
je 0x2c9e
movq %rdi, %r12
movl 0xc(%rdi), %eax
decl %eax
cmpl $0x11, %eax
ja 0x2c87
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
leaq 0x457b(%rip), %rdi      # 0x67ba
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movq %r15, %rdi
leaq 0x4453(%rip), %rsi      # 0x66aa
pushq $-0x4
popq %r13
movl %r13d, %edx
xorl %eax, %eax
callq 0x1120
movq -0x38(%rbp), %rcx
subl %ecx, %r13d
addl $0x4, %ecx
movq %rcx, -0x38(%rbp)
movq 0x28(%r12), %rcx
movq 0x18(%rcx), %rcx
movl %r13d, 0xc(%rcx)
jmp 0x2c87
movq 0x20(%r12), %rax
movq 0x20(%rax), %r14
movq %r14, %rdi
leaq 0x4113(%rip), %rsi      # 0x63ab
callq 0x1110
testl %eax, %eax
je 0x2a44
movq %r14, %rdi
leaq 0x4133(%rip), %rsi      # 0x63e2
callq 0x1110
testl %eax, %eax
je 0x2b1f
leaq 0x28(%r12), %r14
xorl %r13d, %r13d
movq (%r14), %r14
testq %r14, %r14
je 0x2a11
movq -0x38(%rbp), %rax
leal (%rax,%r13), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x43bb(%rip), %rsi      # 0x66aa
pushq $-0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
leaq 0x46c1(%rip), %rdi      # 0x69c1
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
addl $0x4, %r13d
jmp 0x22c4
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x4678(%rip), %rsi      # 0x69ab
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
leaq 0x467d(%rip), %rdi      # 0x69c1
pushq $0xf
popq %r14
movq %r14, %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
leal 0x4(%rbx), %edx
movq 0x30(%r12), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x21f0
leaq 0x465e(%rip), %rdi      # 0x69d1
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
movq %r15, %rdi
leaq 0x4656(%rip), %rsi      # 0x69e1
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
movq 0x28(%r12), %rax
movl 0x20(%rax), %eax
cmpl $0x10d, %eax            # imm = 0x10D
je 0x2abf
cmpl $0x10e, %eax            # imm = 0x10E
movl -0x2c(%rbp), %r14d
jne 0x2c80
leaq 0x46e3(%rip), %rdi      # 0x6aa1
jmp 0x2c72
movq 0x28(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x4577(%rip), %rsi      # 0x6959
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
leaq 0x4573(%rip), %rdi      # 0x6966
movq %rbx, %r14
pushq $0x12
popq %rbx
movq %rbx, %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r12), %rdi
movq %r15, %rsi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x21f0
leaq 0x4555(%rip), %rdi      # 0x6979
movq %rbx, %rsi
leaq 0x4186(%rip), %rbx      # 0x65b4
movl -0x2c(%rbp), %r14d
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x471c(%rip), %rdi      # 0x6b60
pushq $0xf
jmp 0x2764
leaq 0x43a3(%rip), %rdi      # 0x67f5
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
pushq $0x1
popq %r13
movl %r13d, %ecx
callq 0x21f0
movl %eax, %r14d
movq 0x28(%r12), %rdi
movq %r15, %rsi
movl %eax, %edx
movl %r13d, %ecx
callq 0x21f0
leaq 0x4376(%rip), %rdi      # 0x680c
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
subl %ebx, %r14d
movq %r15, %rdi
leaq 0x41f9(%rip), %rsi      # 0x66aa
movl %r14d, %edx
leaq 0x40f9(%rip), %rbx      # 0x65b4
jmp 0x2899
leaq 0x43f7(%rip), %rdi      # 0x68be
pushq $0x17
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11c0
movl 0x8c4d(%rip), %r14d     # 0xb12c
leal 0x1(%r14), %r13d
leal 0x2(%r14), %eax
movl %eax, 0x8c3f(%rip)      # 0xb12c
movq %r15, %rdi
leaq 0x439a(%rip), %rsi      # 0x6891
movl %r14d, %edx
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
leaq 0x4243(%rip), %rsi      # 0x674e
movl %r13d, %edx
xorl %eax, %eax
callq 0x1120
leaq 0x43ba(%rip), %rdi      # 0x68d6
pushq $0x25
popq %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x28(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
pushq $0x1
popq %rcx
callq 0x21f0
movq %r15, %rdi
leaq 0x4204(%rip), %rsi      # 0x674e
movl %r14d, %edx
leaq 0x4060(%rip), %r14      # 0x65b4
xorl %eax, %eax
callq 0x1120
leaq 0x439a(%rip), %rdi      # 0x68fc
pushq $0x21
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r12), %rdi
movq %r15, %rsi
movl %ebx, %edx
movq %r14, %rbx
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x4390(%rip), %rsi      # 0x691e
movl %r13d, %edx
jmp 0x2899
movq 0x18(%r12), %rax
movl (%rax), %ecx
cmpl $0x4, %ecx
je 0x2ac8
cmpl $0x5, %ecx
jne 0x2c87
cmpl $0x0, 0x10(%rax)
leaq 0x45d3(%rip), %rsi      # 0x6b8d
leaq 0x45d8(%rip), %rcx      # 0x6b99
cmoveq %rcx, %rsi
movl 0xc(%rax), %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0x1120
movq 0x18(%r12), %rax
cmpl $0x0, 0x8(%rax)
je 0x2c87
leaq 0x4578(%rip), %rdi      # 0x6b60
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
jmp 0x2768
movq 0x28(%r12), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %r13d
leal (,%r13,4), %r14d
leaq 0x41ca(%rip), %rdi      # 0x67d9
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
negl %r14d
movq %r15, %rdi
leaq 0x4080(%rip), %rsi      # 0x66aa
movl %r14d, %edx
leaq 0x3f80(%rip), %rbx      # 0x65b4
xorl %eax, %eax
callq 0x1120
movq -0x38(%rbp), %rax
leal (%rax,%r13,4), %eax
movl -0x2c(%rbp), %r14d
movq %rax, -0x38(%rbp)
negl %eax
movq 0x28(%r12), %rcx
movq 0x18(%rcx), %rcx
movl %eax, 0xc(%rcx)
jmp 0x2c87
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x2676
movq %r15, %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0x21f0
movl 0x8aac(%rip), %edx      # 0xb128
movq %r15, %rdi
leaq 0x420b(%rip), %rsi      # 0x6891
jmp 0x289d
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0x21f0
movq 0x28(%r12), %rax
movl 0xc(%rax), %ecx
cmpl $0xf, %ecx
je 0x2adc
cmpl $0x10, %ecx
jne 0x2c87
leaq 0x428b(%rip), %rdi      # 0x694a
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x28(%r12), %r14
movq 0x28(%r14), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x4269(%rip), %rsi      # 0x6959
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
leaq 0x4265(%rip), %rdi      # 0x6966
pushq $0x12
popq %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r14), %rdi
leaq 0x3e96(%rip), %rax      # 0x65b4
movl -0x2c(%rbp), %r14d
movq %r15, %rsi
movl %ebx, %edx
movq %rax, %rbx
xorl %ecx, %ecx
callq 0x21f0
leaq 0x4241(%rip), %rdi      # 0x6979
pushq $0x12
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x423f(%rip), %rdi      # 0x698c
pushq $0xf
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x423a(%rip), %rdi      # 0x699c
pushq $0xe
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
jmp 0x2c87
movl 0x20(%r12), %edx
movq %r15, %rdi
leaq 0x4409(%rip), %rsi      # 0x6b8d
jmp 0x289d
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0x21f0
jmp 0x2c87
leaq 0x407c(%rip), %rdi      # 0x6824
pushq $0x17
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x407c(%rip), %rdi      # 0x683c
pushq $0x21
popq %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x21f0
movl 0x8942(%rip), %r13d     # 0xb12c
leal 0x1(%r13), %r14d
leal 0x2(%r13), %eax
movl %eax, 0x8934(%rip)      # 0xb12c
movq %r15, %rdi
leaq 0x405c(%rip), %rsi      # 0x685e
movl %r14d, %edx
xorl %eax, %eax
callq 0x1120
leaq 0x405a(%rip), %rdi      # 0x686d
pushq $0x23
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x28(%r12), %rdi
movq %r15, %rsi
movl %ebx, %edx
pushq $0x1
popq %rcx
callq 0x21f0
movq %r15, %rdi
leaq 0x4054(%rip), %rsi      # 0x6891
movl %r13d, %edx
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
leaq 0x3efd(%rip), %rsi      # 0x674e
movl %r14d, %edx
leaq 0x3d59(%rip), %r14      # 0x65b4
xorl %eax, %eax
callq 0x1120
leaq 0x402f(%rip), %rdi      # 0x6898
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x30(%r12), %rdi
movq %r15, %rsi
movl %ebx, %edx
movq %r14, %rbx
pushq $0x1
popq %rcx
callq 0x21f0
movq %r15, %rdi
leaq 0x3eb8(%rip), %rsi      # 0x674e
movl %r13d, %edx
movl -0x2c(%rbp), %r14d
xorl %eax, %eax
callq 0x1120
jmp 0x2c87
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x40e3(%rip), %rsi      # 0x69ab
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
leaq 0x40e8(%rip), %rdi      # 0x69c1
pushq $0xf
popq %r14
movq %r14, %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
leal 0x4(%rbx), %edx
movq 0x30(%r12), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x21f0
leaq 0x40c9(%rip), %rdi      # 0x69d1
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
movq %r15, %rdi
leaq 0x40c1(%rip), %rsi      # 0x69e1
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
movq 0x28(%r12), %rax
movl 0x20(%rax), %eax
cmpl $0x10b, %eax            # imm = 0x10B
je 0x2b01
cmpl $0x10c, %eax            # imm = 0x10C
movl -0x2c(%rbp), %r14d
jne 0x2c80
leaq 0x4128(%rip), %rdi      # 0x6a7b
jmp 0x2c72
movq 0x20(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x21f0
movq %r15, %rdi
leaq 0x4034(%rip), %rsi      # 0x69ab
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
leaq 0x4039(%rip), %rdi      # 0x69c1
pushq $0xf
popq %r14
movq %r14, %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
leal 0x4(%rbx), %edx
movq 0x30(%r12), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x21f0
leaq 0x401a(%rip), %rdi      # 0x69d1
movq %r14, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x11c0
movq %r15, %rdi
leaq 0x4012(%rip), %rsi      # 0x69e1
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x1120
movq 0x28(%r12), %rax
movl 0x20(%rax), %eax
movl $0xfffffef1, %ecx       # imm = 0xFFFFFEF1
addl %ecx, %eax
cmpl $0x5, %eax
ja 0x2b16
leaq 0x3c04(%rip), %rcx      # 0x65fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl -0x2c(%rbp), %r14d
jmpq *%rax
leaq 0x3fea(%rip), %rdi      # 0x69f6
jmp 0x2c72
movq 0x20(%r12), %rax
movq 0x20(%rax), %rdx
movq %r15, %rdi
leaq 0x4134(%rip), %rsi      # 0x6b58
xorl %eax, %eax
callq 0x1120
movq %r15, %rdi
leaq 0x3c75(%rip), %rsi      # 0x66aa
movl %r13d, %edx
xorl %eax, %eax
callq 0x1120
jmp 0x2b16
leaq 0x4069(%rip), %rdi      # 0x6ab4
pushq $0x9
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x405a(%rip), %rdi      # 0x6abe
pushq $0xa
popq %rbx
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x404d(%rip), %rdi      # 0x6ac9
pushq $0x12
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x404b(%rip), %r13      # 0x6adc
movq %r13, %rdi
pushq $0x8
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x403c(%rip), %rdi      # 0x6ae5
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
movq %r13, %rdi
jmp 0x2c2c
leaq 0x3fc8(%rip), %rdi      # 0x6a8e
jmp 0x2b08
cmpl $0x0, 0x10(%rax)
leaq 0x409d(%rip), %rsi      # 0x6b70
leaq 0x40a2(%rip), %rcx      # 0x6b7c
jmp 0x2af2
movq 0x18(%rax), %rax
cmpl $0x0, 0x10(%rax)
leaq 0x3e42(%rip), %rsi      # 0x692d
leaq 0x3e47(%rip), %rcx      # 0x6939
cmoveq %rcx, %rsi
movl 0xc(%rax), %edx
movq %r15, %rdi
jmp 0x289d
leaq 0x3f60(%rip), %rdi      # 0x6a68
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
movl -0x2c(%rbp), %r14d
jmp 0x2c80
leaq 0x3fca(%rip), %rdi      # 0x6af0
pushq $0xa
popq %rbx
movq %rbx, %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3fb9(%rip), %rdi      # 0x6afb
pushq $0xe
popq %r13
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3f63(%rip), %rdi      # 0x6abe
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3f9a(%rip), %rdi      # 0x6b0a
pushq $0x13
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3f57(%rip), %rdi      # 0x6adc
pushq $0x8
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3f84(%rip), %rdi      # 0x6b1e
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
movq 0x28(%r12), %rdi
movq %r15, %rsi
movq -0x38(%rbp), %rdx
pushq $0x1
popq %rcx
callq 0x21f0
leaq 0x3f6a(%rip), %rdi      # 0x6b2d
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3f64(%rip), %rdi      # 0x6b3c
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3eef(%rip), %rdi      # 0x6adc
pushq $0x8
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3ebc(%rip), %rdi      # 0x6abe
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3f30(%rip), %rdi      # 0x6b47
pushq $0x10
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3eb0(%rip), %rdi      # 0x6adc
pushq $0x8
popq %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x3973(%rip), %rbx      # 0x65b4
movl -0x2c(%rbp), %r14d
jmp 0x2c87
leaq 0x3df4(%rip), %rdi      # 0x6a42
jmp 0x2c72
leaq 0x3dc5(%rip), %rdi      # 0x6a1c
jmp 0x2c72
leaq 0x3dcf(%rip), %rdi      # 0x6a2f
jmp 0x2c72
leaq 0x3da0(%rip), %rdi      # 0x6a09
jmp 0x2c72
leaq 0x3de3(%rip), %rdi      # 0x6a55
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x11c0
leaq 0x392d(%rip), %rbx      # 0x65b4
movl $0x0, %edi
testl %r14d, %r14d
je 0x2215
movq (%r12), %rdi
jmp 0x2215
movq -0x38(%rbp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)