// File: rofl0r[P]ascc/cs_parser.cpp
// Function: parse_variable_declaration(long, int*, int, int, ccCompiledScript*, ccInternalList*, int, int, int)
int parse_variable_declaration(long cursym,int *next_type,int isglobal,
    int varsize,ccCompiledScript*scrip,ccInternalList*targ, int vtwas,
    int isPointer, int isRawPointer) {
  long lbuffer = 0;
  std::vector<char> xbuffer;
  long *getsvalue = &lbuffer;
  int need_fixup = 0;
  int array_size = 1;
  if (sym.get_type(cursym) != 0) {
    cc_error ("Symbol '%s' already defined");
    return -1;
  }

  if ((sym.entries[vtwas].flags & SFLG_MANAGED) && (!isPointer) && (isglobal != 2)) {
    // managed structs must be allocated via ccRegisterObject,
    // and cannot be declared normally in the script (unless imported)
    cc_error("Cannot declare local instance of managed type");
    return -1;
  }

  if (vtwas == sym.normalVoidSym) {
    cc_error("'void' not a valid variable type");
    return -1;
  }

  sym.entries[cursym].extends = 0;
  sym.entries[cursym].stype = (isglobal != 0) ? SYM_GLOBALVAR : SYM_LOCALVAR;
  if (isRawPointer) {
    sym.entries[cursym].flags |= SFLG_ARRAY;
    sym.entries[cursym].vartype = sym.normalIntSym;
    sym.entries[cursym].arrsize = 0;
    sym.entries[cursym].ssize = varsize;
    vtwas = sym.normalIntSym;
    varsize = 4;
  } else {
    if (isPointer) {
      varsize = 4;
    }
    sym.entries[cursym].arrsize = 1;
    sym.entries[cursym].vartype = vtwas;
    if (isPointer)
      sym.entries[cursym].flags |= SFLG_POINTER;
    sym.entries[cursym].ssize = varsize;
  }

  if (((sym.entries[vtwas].flags & SFLG_MANAGED) == 0) && (isPointer) && (isglobal != 2)) {
    // can only point to managed structs
    cc_error("Cannot declare pointer to non-managed type");
    return -1;
  }

  if (next_type[0] == SYM_OPENBRACKET) {
    // an array
    targ->getnext();  // skip the [

    if (sym.get_type(targ->peeknext()) == SYM_CLOSEBRACKET)
    {
      sym.entries[cursym].flags |= SFLG_DYNAMICARRAY;
      array_size = 0;
      varsize = 4;
      //cc_error("dynamic arrays not yet supported"); return -1;
    }
    else
    {
      int nextt = targ->getnext();

      if (accept_literal_or_constant_value(nextt, array_size, false, "Array size must be constant value") < 0) {
        return -1;
      }

      if (sym.entries[vtwas].flags & SFLG_HASDYNAMICARRAY) {
        cc_error("Cannot declare an array of a type containing dynamic array(s)");
        return -1;
      }

      if (array_size < 1) {
        cc_error("Array size must be >=1");
        return -1;
      }

      varsize *= array_size;
    }
    sym.entries[cursym].flags |= SFLG_ARRAY;
    sym.entries[cursym].arrsize = array_size;

    if (sym.get_type(targ->getnext()) != SYM_CLOSEBRACKET)
    {
      cc_error("expected ']'");
      return -1;
    }

    next_type[0] = sym.get_type(targ->peeknext());
    xbuffer.resize(varsize + 1);
    getsvalue = (long*)&xbuffer.front();
  }
  else if (varsize > 4) {
    xbuffer.resize(varsize + 1);
    getsvalue = (long*)&xbuffer.front();
  }

  if (strcmp(sym.get_name(vtwas),"string")==0) {
    sym.entries[cursym].flags |= SFLG_ISSTRING;
    // if it's a string, allocate it some space
    if (ccGetOption(SCOPT_OLDSTRINGS) == 0) {
      cc_error("type 'string' is no longer supported; use String instead");
      return -1;
    }
    else if (sym.entries[cursym].flags & SFLG_DYNAMICARRAY)
    {
      cc_error("arrays of old-style strings are not supported");
      return -1;
    }
    else if (isglobal == 2) {
      // importing a string
      // cannot import, because string is really char*, and the pointer
      // won't resolve properly
      cc_error("cannot import string; use char[] instead");
      return -1;
    }
    else if (isglobal == 1) {
      getsvalue[0] = scrip->add_global(STRING_LENGTH,NULL);
      if (getsvalue[0] < 0)
        return -1;
      need_fixup = 1;
    }
    else if (isglobal == 0) {
      //getsvalue[0] = scrip->cur_sp;
      getsvalue = NULL;
      // save the address of this bit of memory to assign the pointer to it
      // we can't use scrip->cur_sp since we don't know if we'll be in
      // a nested function call at the time
      scrip->write_cmd2(SCMD_REGTOREG, SREG_SP, SREG_CX);
      //scrip->add_fixup(scrip->codesize-2,FIXUP_STACK);
      scrip->cur_sp += STRING_LENGTH;
      scrip->write_cmd2(SCMD_ADD,SREG_SP,STRING_LENGTH);
      sym.entries[cursym].flags |= SFLG_STRBUFFER;
      //need_fixup = 1;
    }
  }

  // assign an initial value to the variable
  if (next_type[0] == SYM_ASSIGN) {
    if (isglobal == 2) {
      cc_error("cannot set initial value of imported variables");
      return -1;
    }
    if ((sym.entries[cursym].flags & (SFLG_ARRAY | SFLG_DYNAMICARRAY)) == SFLG_ARRAY &&
         !isRawPointer) {
      cc_error("cannot assign value to array");
      return -1;
    }
    if (sym.entries[cursym].flags & SFLG_ISSTRING) {
      cc_error("cannot assign value to string, use StrCopy");
      return -1;
    }
    targ->getnext();  // skip the '='

    int actualVarType = vtwas;
    if (sym.entries[cursym].flags & SFLG_POINTER)
      actualVarType |= STYPE_POINTER;

    if (sym.entries[cursym].flags & SFLG_DYNAMICARRAY)
      actualVarType |= STYPE_DYNARRAY;

    if (isglobal) {
      if ((sym.entries[cursym].flags & (SFLG_POINTER | SFLG_DYNAMICARRAY)) != 0) {
        cc_error("cannot assign initial value to global pointer");
        return -1;
      }
      bool is_neg = false;
      if (sym.get_name(targ->peeknext())[0] == '-') {
        is_neg = true;
        targ->getnext();
      }
      if (sym.entries[cursym].vartype == sym.normalFloatSym) {
        // initialize float
        if (sym.get_type(targ->peeknext()) != SYM_LITERALFLOAT) {
          cc_error("Expected floating point value after '='");
          return -1;
        }
        float tehValue = (float)atof(sym.get_name(targ->getnext()));
        if (is_neg)
          tehValue = -tehValue;
        getsvalue[0] = float_to_int_raw(tehValue);
      }
      else if (sym.entries[cursym].ssize > 4) {
        cc_error("cannot initialize struct type");
        return -1;
      }
      else {
        int getsvalue_int;
        if (accept_literal_or_constant_value(targ->getnext(), getsvalue_int, is_neg, "Expected integer value after '='") < 0) {
          return -1;
        }
        getsvalue[0] = (long)getsvalue_int;

      }
    }
    else {

      if (evaluate_expression(targ,scrip,0,false))
        return -1;

      PerformStringConversionInAX(scrip, &scrip->ax_val_type, actualVarType);

      if (check_type_mismatch(scrip->ax_val_type, actualVarType, 1))
        return -1;
      need_fixup = 2;
    }
    next_type[0] = sym.get_type(targ->peeknext());
  }

  if (isglobal == 2) {
    // an imported variable
    sym.entries[cursym].soffs = scrip->add_new_import(sym.get_name(cursym));
    sym.entries[cursym].flags |= SFLG_IMPORTED;
    if (sym.entries[cursym].soffs == -1) {
      cc_error("Internal error: import table overflow");
      return -1;
      }
    }
  else if (isglobal) {
    // a global variable
    sym.entries[cursym].soffs = scrip->add_global(varsize,reinterpret_cast<const char*>(&getsvalue[0]));
    if (sym.entries[cursym].soffs < 0)
      return -1;
    if (need_fixup == 1) scrip->add_fixup(sym.entries[cursym].soffs,FIXUP_DATADATA);
    }
  else {
    // local variable
    sym.entries[cursym].soffs = scrip->cur_sp;
    scrip->write_cmd2(SCMD_REGTOREG,SREG_SP,SREG_MAR);
    if (need_fixup == 2) {
      // expression worked out into ax
      if ((sym.entries[cursym].flags & (SFLG_POINTER | SFLG_DYNAMICARRAY)) != 0)
      {
        scrip->write_cmd1(SCMD_MEMINITPTR, SREG_AX);
      }
      else
        scrip->write_cmd1(get_readcmd_for_size(varsize,1),SREG_AX);
    }
    else if (getsvalue == NULL)
      // local string, so the memory chunk pointer needs to be written
      scrip->write_cmd1(SCMD_MEMWRITE, SREG_CX);
    else { // local variable without initial value -- zero it
      if(compiler_max_command >= SCMD_ZEROMEMORY)
        scrip->write_cmd1(SCMD_ZEROMEMORY, varsize);
      else
        scrip->write_cmd2(SCMD_WRITELIT, varsize, 0);
    }

    if (need_fixup == 1) {
      sym.entries[cursym].flags |= SFLG_STRBUFFER;
      scrip->fixup_previous(FIXUP_STACK);
    }
    if(varsize > 0) {
      scrip->cur_sp += varsize;
      scrip->write_cmd2(SCMD_ADD,SREG_SP,varsize);
    }
  }
  if (next_type[0] == SYM_COMMA) {
    targ->getnext();  // skip the comma
    return 2;
    }
  if (check_not_eof(*targ))
    return -1;
  if (next_type[0] != SYM_SEMICOLON) {
    cc_error("Expected ',' or ';', not '%s'",sym.get_friendly_name(targ->peeknext()).c_str());
    return -1;
    }
  targ->getnext();  // skip the semicolon
  return 0;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x18320
leaq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x1, -0x60(%rbp)
movl -0x10(%rbp), %esi
leaq 0x32895(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0xac(%rbp)
jmp 0xffe8
movl -0xac(%rbp), %eax
cmpl $0x0, %eax
je 0x10027
leaq 0x22802(%rip), %rdi     # 0x327fc
xorl %eax, %eax
callq 0x1bac0
jmp 0x10003
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x10f6e
movslq 0x10(%rbp), %rsi
leaq 0x3283e(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x1000, %rax           # imm = 0x1000
cmpq $0x0, %rax
je 0x1007a
cmpl $0x0, 0x18(%rbp)
jne 0x1007a
cmpl $0x2, -0x1c(%rbp)
je 0x1007a
leaq 0x227ba(%rip), %rdi     # 0x32818
xorl %eax, %eax
callq 0x1bac0
jmp 0x10067
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movl 0x10(%rbp), %eax
leaq 0x327ec(%rip), %rcx     # 0x42870
cmpl 0x18(%rcx), %eax
jne 0x100ac
leaq 0x227b6(%rip), %rdi     # 0x32846
xorl %eax, %eax
callq 0x1bac0
jmp 0x10099
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x10(%rbp), %rsi
leaq 0x327b9(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movw $0x0, 0x50(%rax)
movl -0x1c(%rbp), %edx
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movw %ax, -0xae(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x32785(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movw -0xae(%rbp), %cx
movw %cx, 0x20(%rax)
cmpl $0x0, 0x20(%rbp)
je 0x101b6
movq -0x10(%rbp), %rsi
leaq 0x3275c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rcx
orq $0x2, %rcx
movq %rcx, 0x28(%rax)
leaq 0x32740(%rip), %rax     # 0x42870
movl (%rax), %eax
movw %ax, -0xba(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x3272c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movw -0xba(%rbp), %cx
movw %cx, 0x30(%rax)
movq -0x10(%rbp), %rsi
leaq 0x3270d(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq $0x0, 0x48(%rax)
movslq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x326e6(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq -0xb8(%rbp), %rcx
movq %rcx, 0x38(%rax)
leaq 0x326cb(%rip), %rax     # 0x42870
movl (%rax), %eax
movl %eax, 0x10(%rbp)
movl $0x4, -0x20(%rbp)
jmp 0x1025b
cmpl $0x0, 0x18(%rbp)
je 0x101c3
movl $0x4, -0x20(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x326a2(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq $0x1, 0x48(%rax)
movl 0x10(%rbp), %eax
movw %ax, -0xbc(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x3267c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movw -0xbc(%rbp), %cx
movw %cx, 0x30(%rax)
cmpl $0x0, 0x18(%rbp)
je 0x10231
movq -0x10(%rbp), %rsi
leaq 0x32657(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rcx
orq $0x100, %rcx            # imm = 0x100
movq %rcx, 0x28(%rax)
movslq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x32629(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq -0xc8(%rbp), %rcx
movq %rcx, 0x38(%rax)
movslq 0x10(%rbp), %rsi
leaq 0x3260a(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x1000, %rax           # imm = 0x1000
cmpq $0x0, %rax
jne 0x102ae
cmpl $0x0, 0x18(%rbp)
je 0x102ae
cmpl $0x2, -0x1c(%rbp)
je 0x102ae
leaq 0x21bef(%rip), %rdi     # 0x31e81
xorl %eax, %eax
callq 0x1bac0
jmp 0x1029b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x18(%rbp), %rax
cmpl $0x7, (%rax)
jne 0x1050b
movq -0x30(%rbp), %rdi
callq 0x1de00
jmp 0x102c6
movq -0x30(%rbp), %rdi
callq 0x1dd60
movq %rax, -0xd0(%rbp)
jmp 0x102d8
movq -0xd0(%rbp), %rax
movl %eax, %esi
leaq 0x32588(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0xd4(%rbp)
jmp 0x102f5
movl -0xd4(%rbp), %eax
cmpl $0x8, %eax
jne 0x10336
movq -0x10(%rbp), %rsi
leaq 0x32565(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rcx
orq $0x40000, %rcx          # imm = 0x40000
movq %rcx, 0x28(%rax)
movl $0x0, -0x60(%rbp)
movl $0x4, -0x20(%rbp)
jmp 0x10407
movq -0x30(%rbp), %rdi
callq 0x1de00
movq %rax, -0xe0(%rbp)
jmp 0x10348
movq -0xe0(%rbp), %rax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %edi
leaq 0x2250b(%rip), %rcx     # 0x32867
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x86e0
movl %eax, -0xe4(%rbp)
jmp 0x1036f
movl -0xe4(%rbp), %eax
cmpl $0x0, %eax
jge 0x1038d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movslq 0x10(%rbp), %rsi
leaq 0x324d8(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x100000, %rax         # imm = 0x100000
cmpq $0x0, %rax
je 0x103d4
leaq 0x224d1(%rip), %rdi     # 0x32889
xorl %eax, %eax
callq 0x1bac0
jmp 0x103c1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
cmpl $0x1, -0x60(%rbp)
jge 0x103fd
leaq 0x224e6(%rip), %rdi     # 0x328c7
xorl %eax, %eax
callq 0x1bac0
jmp 0x103ea
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movl -0x60(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x3245e(%rip), %rdi     # 0x42870
addq $0x28, %rdi
movq %rdi, -0x100(%rbp)
callq 0x17e60
movq -0x100(%rbp), %rdi
movb 0x28(%rax), %cl
orb $0x2, %cl
movb %cl, 0x28(%rax)
movslq -0x60(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rsi
callq 0x17e60
movq -0xf8(%rbp), %rcx
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rdi
callq 0x1de00
movq %rax, -0xf0(%rbp)
jmp 0x10463
movq -0xf0(%rbp), %rax
movl %eax, %esi
leaq 0x323fd(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x104(%rbp)
jmp 0x10480
movl -0x104(%rbp), %eax
cmpl $0x8, %eax
je 0x104ae
leaq 0x2244c(%rip), %rdi     # 0x328de
xorl %eax, %eax
callq 0x1bac0
jmp 0x1049b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x30(%rbp), %rdi
callq 0x1dd60
movq %rax, -0x110(%rbp)
jmp 0x104c0
movq -0x110(%rbp), %rax
movl %eax, %esi
leaq 0x323a0(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x114(%rbp)
jmp 0x104dd
movl -0x114(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x18340
jmp 0x104fc
leaq -0x50(%rbp), %rdi
callq 0x183d0
movq %rax, -0x58(%rbp)
jmp 0x10533
cmpl $0x4, -0x20(%rbp)
jle 0x10531
movl -0x20(%rbp), %eax
incl %eax
movslq %eax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x18340
jmp 0x10524
leaq -0x50(%rbp), %rdi
callq 0x183d0
movq %rax, -0x58(%rbp)
jmp 0x10533
movl 0x10(%rbp), %esi
leaq 0x32333(%rip), %rdi     # 0x42870
callq 0x1f730
movq %rax, -0x120(%rbp)
jmp 0x1054b
movq -0x120(%rbp), %rdi
leaq 0x23f6f(%rip), %rsi     # 0x344c8
callq 0x4510
cmpl $0x0, %eax
jne 0x1070c
movq -0x10(%rbp), %rsi
leaq 0x322fe(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movb 0x28(%rax), %cl
orb $0x20, %cl
movb %cl, 0x28(%rax)
movl $0x80, %edi
callq 0x265a0
movl %eax, -0x124(%rbp)
jmp 0x10596
movl -0x124(%rbp), %eax
cmpl $0x0, %eax
jne 0x105c4
leaq 0x22343(%rip), %rdi     # 0x328eb
xorl %eax, %eax
callq 0x1bac0
jmp 0x105b1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x10(%rbp), %rsi
leaq 0x322a1(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x1060b
leaq 0x22335(%rip), %rdi     # 0x32924
xorl %eax, %eax
callq 0x1bac0
jmp 0x105f8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
cmpl $0x2, -0x1c(%rbp)
jne 0x10634
leaq 0x2233a(%rip), %rdi     # 0x32952
xorl %eax, %eax
callq 0x1bac0
jmp 0x10621
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
cmpl $0x1, -0x1c(%rbp)
jne 0x1068a
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0xc8, %esi
callq 0x255b0
movl %eax, -0x128(%rbp)
jmp 0x10654
movl -0x128(%rbp), %eax
movslq %eax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x10681
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movl $0x1, -0x5c(%rbp)
jmp 0x10704
cmpl $0x0, -0x1c(%rbp)
jne 0x10702
movq $0x0, -0x58(%rbp)
movq -0x28(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
movl $0x5, %ecx
callq 0x25240
jmp 0x106b2
movq -0x28(%rbp), %rax
movq 0x8d40(%rax), %rcx
addq $0xc8, %rcx
movq %rcx, 0x8d40(%rax)
movq -0x28(%rbp), %rdi
movl $0x1, %edx
movl $0xc8, %ecx
movl %edx, %esi
callq 0x25240
jmp 0x106e2
movq -0x10(%rbp), %rsi
leaq 0x32183(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rcx
orq $0x10, %rcx
movq %rcx, 0x28(%rax)
jmp 0x10704
jmp 0x10706
jmp 0x10708
jmp 0x1070a
jmp 0x1070c
movq -0x18(%rbp), %rax
cmpl $0x19, (%rax)
jne 0x10b64
cmpl $0x2, -0x1c(%rbp)
jne 0x10742
leaq 0x22255(%rip), %rdi     # 0x3297b
xorl %eax, %eax
callq 0x1bac0
jmp 0x1072f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x10(%rbp), %rsi
leaq 0x32123(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x40002, %rax          # imm = 0x40002
cmpq $0x2, %rax
jne 0x1078f
cmpl $0x0, 0x20(%rbp)
jne 0x1078f
leaq 0x22237(%rip), %rdi     # 0x329aa
xorl %eax, %eax
callq 0x1bac0
jmp 0x1077c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x10(%rbp), %rsi
leaq 0x320d6(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x20, %rax
cmpq $0x0, %rax
je 0x107d4
leaq 0x2220f(%rip), %rdi     # 0x329c7
xorl %eax, %eax
callq 0x1bac0
jmp 0x107c1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x30(%rbp), %rdi
callq 0x1de00
jmp 0x107df
movl 0x10(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x32080(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0x10814
movl -0x78(%rbp), %eax
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x32051(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x10843
movl -0x78(%rbp), %eax
orl $0x10000000, %eax       # imm = 0x10000000
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x10a96
movq -0x10(%rbp), %rsi
leaq 0x32018(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x40100, %rax          # imm = 0x40100
cmpq $0x0, %rax
je 0x10894
leaq 0x2217a(%rip), %rdi     # 0x329f2
xorl %eax, %eax
callq 0x1bac0
jmp 0x10881
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movb $0x0, -0x79(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1dd60
movq %rax, -0x130(%rbp)
jmp 0x108aa
movq -0x130(%rbp), %rax
movl %eax, %esi
leaq 0x31fb6(%rip), %rdi     # 0x42870
callq 0x1f730
movq %rax, -0x138(%rbp)
jmp 0x108c8
movq -0x138(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x108e8
movb $0x1, -0x79(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1de00
jmp 0x108e6
jmp 0x108e8
movq -0x10(%rbp), %rsi
leaq 0x31f7d(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movswl 0x30(%rax), %eax
leaq 0x31f69(%rip), %rcx     # 0x42870
cmpl 0x14(%rcx), %eax
jne 0x109e8
movq -0x30(%rbp), %rdi
callq 0x1dd60
movq %rax, -0x140(%rbp)
jmp 0x10922
movq -0x140(%rbp), %rax
movl %eax, %esi
leaq 0x31f3e(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x144(%rbp)
jmp 0x1093f
movl -0x144(%rbp), %eax
cmpl $0x16, %eax
je 0x1096d
leaq 0x220cf(%rip), %rdi     # 0x32a20
xorl %eax, %eax
callq 0x1bac0
jmp 0x1095a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x30(%rbp), %rdi
callq 0x1de00
movq %rax, -0x150(%rbp)
jmp 0x1097f
movq -0x150(%rbp), %rax
movl %eax, %esi
leaq 0x31ee1(%rip), %rdi     # 0x42870
callq 0x1f730
movq %rax, -0x158(%rbp)
jmp 0x1099d
movq -0x158(%rbp), %rdi
callq 0x44c0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x80(%rbp)
testb $0x1, -0x79(%rbp)
je 0x109cf
movss -0x80(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x80(%rbp)
movss -0x80(%rbp), %xmm0
callq 0xa1e0
movslq %eax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10a91
movq -0x10(%rbp), %rsi
leaq 0x31e7d(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
cmpq $0x4, 0x38(%rax)
jle 0x10a26
leaq 0x2203e(%rip), %rdi     # 0x32a48
xorl %eax, %eax
callq 0x1bac0
jmp 0x10a13
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x30(%rbp), %rdi
callq 0x1de00
movq %rax, -0x160(%rbp)
jmp 0x10a38
movq -0x160(%rbp), %rax
movl %eax, %edi
movzbl -0x79(%rbp), %edx
andl $0x1, %edx
leaq 0x22017(%rip), %rcx     # 0x32a66
leaq -0x84(%rbp), %rsi
callq 0x86e0
movl %eax, -0x164(%rbp)
jmp 0x10a63
movl -0x164(%rbp), %eax
cmpl $0x0, %eax
jge 0x10a81
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movslq -0x84(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10a91
jmp 0x10b29
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x7d10
movl %eax, -0x168(%rbp)
jmp 0x10aaf
movl -0x168(%rbp), %eax
cmpl $0x0, %eax
je 0x10acd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x28(%rbp), %rdi
movq %rdi, %rsi
addq $0x8d4c, %rsi           # imm = 0x8D4C
movl -0x78(%rbp), %edx
callq 0xb5a0
jmp 0x10ae5
movq -0x28(%rbp), %rax
movl 0x8d4c(%rax), %edi
movl -0x78(%rbp), %esi
movl $0x1, %edx
callq 0xa7c0
movl %eax, -0x16c(%rbp)
jmp 0x10b04
movl -0x16c(%rbp), %eax
cmpl $0x0, %eax
je 0x10b22
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movl $0x2, -0x5c(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1dd60
movq %rax, -0x178(%rbp)
jmp 0x10b3b
movq -0x178(%rbp), %rax
movl %eax, %esi
leaq 0x31d25(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x17c(%rbp)
jmp 0x10b58
movl -0x17c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x2, -0x1c(%rbp)
jne 0x10c2b
movq -0x28(%rbp), %rax
movq %rax, -0x190(%rbp)
movl -0x10(%rbp), %esi
leaq 0x31ced(%rip), %rdi     # 0x42870
callq 0x1f730
movq %rax, -0x188(%rbp)
jmp 0x10b91
movq -0x188(%rbp), %rsi
movq -0x190(%rbp), %rdi
callq 0x25930
movl %eax, -0x194(%rbp)
jmp 0x10bac
movq -0x10(%rbp), %rsi
leaq 0x31cb9(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movl -0x194(%rbp), %ecx
movl %ecx, 0x34(%rax)
movq -0x10(%rbp), %rsi
leaq 0x31c9c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rcx
orq $0x4, %rcx
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rsi
leaq 0x31c7c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
cmpl $-0x1, 0x34(%rax)
jne 0x10c26
leaq 0x21e7d(%rip), %rdi     # 0x32a87
xorl %eax, %eax
callq 0x1bac0
jmp 0x10c13
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
jmp 0x10e58
cmpl $0x0, -0x1c(%rbp)
je 0x10cd9
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %esi
movq -0x58(%rbp), %rdx
callq 0x255b0
movl %eax, -0x198(%rbp)
jmp 0x10c4d
movq -0x10(%rbp), %rsi
leaq 0x31c18(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movl -0x198(%rbp), %ecx
movl %ecx, 0x34(%rax)
movq -0x10(%rbp), %rsi
leaq 0x31bfb(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
cmpl $0x0, 0x34(%rax)
jge 0x10c97
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
cmpl $0x1, -0x5c(%rbp)
jne 0x10cd4
movq -0x28(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x31bbd(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq -0x1a0(%rbp), %rdi
movl 0x34(%rax), %esi
movl $0x5, %edx
callq 0x25790
jmp 0x10cd2
jmp 0x10cd4
jmp 0x10e56
movq -0x28(%rbp), %rax
movl 0x8d40(%rax), %eax
movl %eax, -0x1a4(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x31b7c(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movl -0x1a4(%rbp), %ecx
movl %ecx, 0x34(%rax)
movq -0x28(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
movl $0x2, %ecx
callq 0x25240
jmp 0x10d20
cmpl $0x2, -0x5c(%rbp)
jne 0x10d92
movq -0x10(%rbp), %rsi
leaq 0x31b3f(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x40100, %rax          # imm = 0x40100
cmpq $0x0, %rax
je 0x10d61
movq -0x28(%rbp), %rdi
movl $0x32, %esi
movl $0x3, %edx
callq 0x25200
jmp 0x10d5f
jmp 0x10d90
movq -0x28(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl -0x20(%rbp), %edi
movl $0x1, %esi
callq 0xb960
movq -0x1b0(%rbp), %rdi
movl %eax, %esi
movl $0x3, %edx
callq 0x25200
jmp 0x10d8e
jmp 0x10d90
jmp 0x10de9
cmpq $0x0, -0x58(%rbp)
jne 0x10db0
movq -0x28(%rbp), %rdi
movl $0x8, %esi
movl $0x5, %edx
callq 0x25200
jmp 0x10dae
jmp 0x10de7
cmpl $0x3f, 0x31639(%rip)    # 0x423f0
jl 0x10dce
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x3f, %esi
callq 0x25200
jmp 0x10dcc
jmp 0x10de5
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %edx
movl $0x4, %esi
xorl %ecx, %ecx
callq 0x25240
jmp 0x10de3
jmp 0x10de5
jmp 0x10de7
jmp 0x10de9
cmpl $0x1, -0x5c(%rbp)
jne 0x10e1e
movq -0x10(%rbp), %rsi
leaq 0x31a76(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movb 0x28(%rax), %cl
orb $0x10, %cl
movb %cl, 0x28(%rax)
movq -0x28(%rbp), %rdi
movl $0x6, %esi
callq 0x25820
jmp 0x10e1c
jmp 0x10e1e
cmpl $0x0, -0x20(%rbp)
jle 0x10e54
movslq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x8d40(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8d40(%rax)
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %ecx
movl $0x1, %edx
movl %edx, %esi
callq 0x25240
jmp 0x10e52
jmp 0x10e54
jmp 0x10e56
jmp 0x10e58
movq -0x18(%rbp), %rax
cmpl $0x2a, (%rax)
jne 0x10e7f
movq -0x30(%rbp), %rdi
callq 0x1de00
jmp 0x10e6c
movl $0x2, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x30(%rbp), %rdi
callq 0x8a60
movl %eax, -0x1b4(%rbp)
jmp 0x10e90
movl -0x1b4(%rbp), %eax
cmpl $0x0, %eax
je 0x10eae
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq -0x18(%rbp), %rax
cmpl $0x28, (%rax)
je 0x10f40
movq -0x30(%rbp), %rdi
callq 0x1dd60
movq %rax, -0x1c0(%rbp)
jmp 0x10ecd
movq -0x1c0(%rbp), %rax
movl %eax, %edx
leaq 0x31993(%rip), %rsi     # 0x42870
leaq -0xa8(%rbp), %rdi
callq 0x1f080
jmp 0x10eeb
leaq -0xa8(%rbp), %rdi
callq 0x41b0
movq %rax, %rsi
leaq 0x21bac(%rip), %rdi     # 0x32aad
xorl %eax, %eax
callq 0x1bac0
jmp 0x10f0a
leaq -0xa8(%rbp), %rdi
callq 0x4270
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x10f59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x4270
jmp 0x10f6e
movq -0x30(%rbp), %rdi
callq 0x1de00
jmp 0x10f4b
movl $0x0, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x18400
movl -0x4(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x18400
movq -0x68(%rbp), %rdi
callq 0x4670