// File: /workspace/github_cpp_makefile_star2_O2/jBlinden[P]private-codis/ProtocolServer.cpp
// Function: RunServerProtocol(CSocket*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void RunServerProtocol(CSocket *socket, string pArgsFile, string serverDataDir)
{
  ServerLog("starting server protocol");
#if !OPTIMAL
  ServerLog("Reading in protocol args");
#endif

  ifstream in;
  in.open(pArgsFile, ios::in | ios::binary);
  struct ProtocolArgs pArgs(in);
  in.close();

#if !OPTIMAL
  ServerLog("Reading in sender OTs");
#endif

  ifstream sOTFile1;
  sOTFile1.open(serverDataDir + "sOT.txt", ios::in | ios::binary);

  SenderOTCorrelation **FSM1_SC = ReadInSenderOTsFSM1(sOTFile1, pArgs);
  SenderOTCorrelation **FSM2_SC = ReadInSenderOTsFSM2(sOTFile1, pArgs);

  sOTFile1.close();

#if !OPTIMAL
  ServerLog("Finished Reading in OTs");
  ServerLog("Creating fake DB");
#endif

  uint32_t N = pArgs.N;
  uint32_t C = pArgs.C;
  uint8_t* bits_per_component = pArgs.bits_per_component;

  ifstream dbFile;
  dbFile.open(serverDataDir + "db.txt");
  uint32_t **db = ReadInDB(dbFile, N, C);
  dbFile.close();

#if VERBOSE
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < C; j++)
    {
      cout << db[i][j] << ", ";
    }
    cout << endl;
  }
#endif

#if !OPTIMAL
  ServerLog("Creating random permutations");
#endif

  AESContext PRF;

  uint16_t **flipped_bits = new uint16_t *[N];
  for (int i = 0; i < N; i++)
  {
    flipped_bits[i] = new uint16_t[C];
    PRF.FillBuffer((uint8_t *)flipped_bits[i], 2 * C, i);
  }

#if !OPTIMAL
  ServerLog("Running first part FSM");
#endif

  int l = 0;
  int smallest_number_of_bits = 0;
  for (int round = 0; round < pArgs.FSM1_rounds; round++)
  {
    uint8_t concurrent_iterations = pArgs.FSM1_steps[round];
    uint8_t all_ones_string = (uint8_t)((1 << concurrent_iterations) - 1);
    uint8_t pow_iterations = (uint8_t)((1 << concurrent_iterations));
    uint8_t pos_states = 2 * pow_iterations;

    if (l >= bits_per_component[smallest_number_of_bits])
    {
      while(l >= bits_per_component[smallest_number_of_bits])
        smallest_number_of_bits ++;
    }
    uint8_t number_of_bit_entries = C - smallest_number_of_bits;

    uint8_t *msgs = new uint8_t[N * number_of_bit_entries * 2 * pow_iterations];

    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < number_of_bit_entries; j++)
      {
        uint8_t postImageJ = j + C - number_of_bit_entries;

        bool previous_reject = round == 0 ? 1 : !(flipped_bits[i][postImageJ] >> (round - 1) & 0x1);
        bool next_flipped_bit = (flipped_bits[i][postImageJ] >> round) & 0x1;

        uint8_t entry_bits = (db[i][postImageJ] >> l) & all_ones_string;

        for (int state = 0; state < pos_states; state++)
        {
          if (state < (pos_states / 2))
          {
            msgs[number_of_bit_entries * pos_states * i + j * pos_states + state] = (previous_reject != 0 && entry_bits == (state % pow_iterations)) ? next_flipped_bit : !next_flipped_bit;
          }
          else
          {
            msgs[number_of_bit_entries * pos_states * i + j * pos_states + state] = (previous_reject != 1 && entry_bits == (state % pow_iterations)) ? next_flipped_bit : !next_flipped_bit;
          }
        }
      }
    }

#if !OPTIMAL
    ServerLog("Finished creating messages");
#endif

    uint8_t *rMsg = new uint8_t[N * number_of_bit_entries];

    ReceiveLargePacked(socket, 1 + concurrent_iterations, N * number_of_bit_entries, rMsg);

    uint8_t *sMsg = new uint8_t[N * number_of_bit_entries * pos_states];
    ConstructOTSenderMsg(sMsg, *(FSM1_SC[round]), msgs, rMsg, N * number_of_bit_entries, 1);

    SendLargePacked(socket, 1, N * number_of_bit_entries * pos_states, sMsg);

    delete[] msgs;
    delete[] rMsg;
    delete[] sMsg;

    l += concurrent_iterations;
  }

#if !OPTIMAL
  ServerLog("Finished part 1 of the FSM");
#endif
  uint8_t highest_number_of_bits = bits_per_component[C - 1];
  uint8_t **FinalRandomness = new uint8_t *[N];
  for (int i = 0; i < N; i++)
  {
    FinalRandomness[i] = new uint8_t[C];
    for (int j = 0; j < C; j++)
    {
      FinalRandomness[i][j] = (flipped_bits[i][j] >> (pArgs.FSM1_rounds - 1 - ((highest_number_of_bits - bits_per_component[j]) / 2))) & 0x1;
    }
  }

#if !OPTIMAL
  ServerLog("Starting Second FSM");
#endif

  AESContext PRF2;

  uint8_t **random_shift = new uint8_t *[N];
  uint32_t tag_counter = 0;
  for (int i = 0; i < N; i++)
  {
    random_shift[i] = new uint8_t[pArgs.FSM2_rounds];
    PRF2.FillBuffer(random_shift[i], pArgs.FSM2_rounds, tag_counter);
    for (int j = 0; j < pArgs.FSM2_rounds; j++)
    {
      while (random_shift[i][j] == 255)
      {
        tag_counter += 1;
        PRF2.FillBuffer(&random_shift[i][j], 1, tag_counter);
      }
      random_shift[i][j] %= 3;
    }
    tag_counter += 1;
  }

  for (int i = 0; i < N; i++)
    random_shift[i][pArgs.FSM2_rounds - 1] = 0; // Make sure that the final permutation is always 0 to reveal the true state to the client

  uint32_t c = 0;
  for (int round = 0; round < pArgs.FSM2_rounds; round++)
  {
    uint8_t round_step = pArgs.FSM2_steps[round];
    uint8_t round_factor = 1 << round_step;

    uint8_t *msgs = new uint8_t[N * 3 * round_factor];
    for (int i = 0; i < N; i++)
    {
      int previous_shift = (c == 0) ? 0 : random_shift[i][round - 1];
      for (int possible_state = 0; possible_state < 3; possible_state++)
      {
        uint8_t old_state = (possible_state + 3 - previous_shift) % 3;

        uint8_t equality_bits = 0;
        for (int j = 0; j < round_step; j++)
        {
          equality_bits += (FinalRandomness[i][c + j] * (1 << j));
        }

        // equality bits = the best correct state -> having it correct is plus FSM_RC
        // ~equality bits = worst case -> having it correct is plus 0
        //
        for (uint8_t j = 0; j < round_factor; j++)
        {
          uint8_t no_match_count = round_step - count_ones(((~(j ^ equality_bits)) & (round_factor - 1)));
          if (old_state - no_match_count < 0)
            msgs[((3 * round_factor) * i + possible_state * round_factor + j)] = (0 + random_shift[i][round]);
          else
            msgs[((3 * round_factor) * i + possible_state * round_factor + j)] = (old_state - no_match_count + random_shift[i][round]) % 3;
  
        }
      }

    }

#if !OPTIMAL
    ServerLog("Finished one round");
#endif

    

    uint8_t *rMsg = new uint8_t[N];

    ReceiveLargePacked(socket, 2 + round_step, N, rMsg);
    
    uint8_t *sMsg = new uint8_t[N * 3 * round_factor];
    ConstructOTSenderMsg(sMsg, *(FSM2_SC[round]), msgs, rMsg, N, 2);

    SendLargePacked(socket, 2, N * 3 * round_factor, sMsg);

    c += round_step;

    delete[] msgs;
    delete[] rMsg;
    delete[] sMsg;
  }

#if !OPTIMAL
  ServerLog("finished everything");
  cout << "Memory clean up" << endl;
#endif

  for (int i = 0; i < N; i++)
  {
    delete[] db[i];
    delete[] flipped_bits[i];
    delete[] random_shift[i];
    delete[] FinalRandomness[i];
  }
  delete[] db;
  delete[] flipped_bits;
  delete[] random_shift;
  delete[] FinalRandomness;

  for (int i = 0; i < pArgs.FSM1_rounds; i++)
  {
    delete FSM1_SC[i];
  }
  delete[] FSM1_SC;

  for (int i = 0; i < pArgs.FSM2_rounds; i++)
  {
    delete FSM2_SC[i];
  }
  delete[] FSM2_SC;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x988, %rsp            # imm = 0x988
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x60(%rsp)
leaq 0x3a65(%rip), %rsi      # 0x6004
leaq 0x460(%rsp), %rdi
leaq 0x668(%rsp), %rdx
callq 0x20e0
leaq 0x460(%rsp), %rdi
callq 0x30bb
leaq 0x460(%rsp), %rdi
callq 0x20f0
leaq 0x460(%rsp), %r15
movq %r15, %rdi
callq 0x2280
pushq $0xc
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x21b0
leaq 0xa8(%rsp), %rdi
leaq 0x460(%rsp), %rsi
callq 0x436c
leaq 0x460(%rsp), %rdi
callq 0x2070
leaq 0x668(%rsp), %rdi
callq 0x2280
leaq 0x39fb(%rip), %rdx      # 0x601d
leaq 0x258(%rsp), %rdi
movq %rbx, %rsi
callq 0x3474
leaq 0x668(%rsp), %rdi
leaq 0x258(%rsp), %rsi
pushq $0xc
popq %rdx
callq 0x21b0
leaq 0x258(%rsp), %rdi
callq 0x20f0
vmovups 0xa8(%rsp), %ymm0
vmovups 0xb8(%rsp), %ymm1
leaq 0x110(%rsp), %rsi
vmovups %ymm0, (%rsi)
vmovups %ymm1, 0x10(%rsi)
leaq 0x668(%rsp), %rdi
vzeroupper
callq 0x463c
movq %rax, 0x80(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x4476
vmovups 0xa8(%rsp), %ymm0
vmovups 0xb8(%rsp), %ymm1
leaq 0xe0(%rsp), %rsi
vmovups %ymm1, 0x10(%rsi)
vmovups %ymm0, (%rsi)
leaq 0x668(%rsp), %rdi
vzeroupper
callq 0x46ba
movq %rax, 0x78(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x4476
leaq 0x668(%rsp), %rdi
callq 0x2070
movl 0xac(%rsp), %eax
movl 0xa8(%rsp), %r14d
movq 0xc8(%rsp), %rcx
movq %rax, 0x20(%rsp)
movq %rcx, 0x38(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x2280
leaq 0x38ff(%rip), %rdx      # 0x6025
leaq 0x140(%rsp), %rdi
movq %rbx, %rsi
callq 0x3474
leaq 0x258(%rsp), %rdi
leaq 0x140(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x21b0
leaq 0x140(%rsp), %rdi
callq 0x20f0
leaq 0x258(%rsp), %rdi
movq 0x20(%rsp), %rdx
movl %r14d, %esi
callq 0x494e
leaq 0x258(%rsp), %rdi
movq %rax, %rbx
callq 0x2070
leaq 0x140(%rsp), %rdi
callq 0x4ff8
movq %rbx, 0x90(%rsp)
movq %r14, 0x40(%rsp)
leaq (,%r14,8), %rdi
movq %rdi, 0x68(%rsp)
callq 0x2030
movq %rax, 0x50(%rsp)
movq 0x20(%rsp), %rax
leaq 0x140(%rsp), %r13
xorl %r12d, %r12d
leaq (%rax,%rax), %rbx
leal (%rax,%rax), %r14d
cmpq %r12, 0x40(%rsp)
je 0x27f7
movq %rbx, %rdi
callq 0x2030
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
movq %r13, %rdi
movq %rax, %rsi
movl %r14d, %edx
movq %r12, %rcx
callq 0x5362
incq %r12
jmp 0x27c9
xorl %r14d, %r14d
pushq $0x1
popq %rbx
movq 0x40(%rsp), %r13
movl $0xff, %edx
xorl %edi, %edi
xorl %esi, %esi
movl 0xb0(%rsp), %eax
cmpq %rax, %r14
jae 0x2a77
movq 0x38(%rsp), %rcx
movslq %edi, %rax
movzbl (%rcx,%rax), %ecx
cmpl %ecx, %esi
jb 0x283f
leal -0x1(%rax), %edi
addq 0x38(%rsp), %rax
movzbl (%rax), %ecx
incl %edi
incq %rax
cmpl %ecx, %esi
jae 0x2833
movq 0xb8(%rsp), %rax
movl %ebx, %ebp
movq %rdi, 0x58(%rsp)
movl %esi, 0x48(%rsp)
movzbl (%rax,%r14), %r12d
shlxl %r12d, %ebx, %eax
movl %eax, %r15d
movl %eax, %ebx
movq 0x20(%rsp), %rax
subl %edi, %eax
andl %edx, %r15d
movzbl %al, %eax
movl %r15d, %edi
movl %eax, 0x10(%rsp)
imull %r13d, %eax
imull %eax, %edi
movl %eax, 0xc(%rsp)
addl %edi, %edi
callq 0x2030
movq %rax, 0x18(%rsp)
movl $0xff, %eax
addl %eax, %ebx
movl %ebx, 0x28(%rsp)
pushq $0x2
popq %rax
movl 0x10(%rsp), %ecx
shlxq %r12, %rax, %rdx
leal -0x1(%r14), %eax
decl %r15d
movq %r12, 0x30(%rsp)
xorl %r9d, %r9d
shlxl %eax, %ebp, %eax
andl $0xfe, %edx
movl %r15d, %esi
movl %eax, 0x70(%rsp)
shlxl %r14d, %ebp, %eax
movq %rdx, %rbx
shrl %edx
movl %eax, 0x98(%rsp)
movl %ecx, %eax
movq %rax, (%rsp)
movl %edx, %eax
imull %ecx, %eax
movq %r14, %rcx
addl %eax, %eax
movl %eax, 0x88(%rsp)
xorl %eax, %eax
cmpq %r13, %r9
je 0x29c6
movq %rax, 0x10(%rsp)
movl %eax, %r10d
xorl %r11d, %r11d
cmpq (%rsp), %r11
je 0x29b2
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
movq (%rdi,%r9,8), %r15
addl %r11d, %eax
movzbl %al, %eax
testq %r14, %r14
je 0x2934
movzwl (%r15,%rax,2), %edi
testl %edi, 0x70(%rsp)
sete %dil
jmp 0x2937
movb $0x1, %dil
movq 0x90(%rsp), %r14
movl 0x48(%rsp), %ebp
movzwl (%r15,%rax,2), %r15d
movl %r10d, %r8d
addq 0x18(%rsp), %r8
andl 0x98(%rsp), %r15d
movq (%r14,%r9,8), %r13
shrxl %ebp, (%r13,%rax,4), %eax
andl 0x28(%rsp), %eax
movzbl %al, %r13d
xorl %eax, %eax
cmpq %rax, %rbx
je 0x299f
testl %r15d, %r15d
movl %esi, %r12d
setne %r14b
cmpq %rdx, %rax
setb %bpl
andl %eax, %r12d
cmpl %r12d, %r13d
setne %r12b
xorb %dil, %bpl
orb %r12b, %bpl
xorb %r14b, %bpl
movb %bpl, (%r8,%rax)
incq %rax
jmp 0x296d
movq 0x40(%rsp), %r13
incq %r11
addl %ebx, %r10d
movq %rcx, %r14
jmp 0x2902
movq 0x10(%rsp), %rax
incq %r9
addl 0x88(%rsp), %eax
jmp 0x28ee
movl 0xc(%rsp), %r15d
movl %r15d, %r12d
movq %r12, %rdi
callq 0x2030
movq %rax, (%rsp)
movq 0x30(%rsp), %rbp
leal 0x1(%rbp), %eax
movq 0x60(%rsp), %rdi
movq (%rsp), %rcx
movzbl %al, %esi
movq %r12, %rdx
callq 0x4a6a
imull %r15d, %ebx
movq %rbx, %rdi
movq %rbx, %rbp
callq 0x2030
movl %r15d, %r8d
pushq $0x1
popq %rbx
movq (%rsp), %r15
movq 0x80(%rsp), %rsi
movq %rax, %r12
movq (%rsi,%r14,8), %rsi
movq 0x18(%rsp), %rdx
movq %r12, %rdi
movq %r15, %rcx
movl %ebx, %r9d
callq 0x3b08
movq 0x60(%rsp), %rdi
movl %ebx, %esi
movq %rbp, %rdx
movq %r12, %rcx
callq 0x4997
movq 0x18(%rsp), %rdi
callq 0x22c0
movq %r15, %rdi
callq 0x22c0
movq %r12, %rdi
callq 0x22c0
movl 0x48(%rsp), %esi
movq 0x58(%rsp), %rdi
incq %r14
movl $0xff, %edx
addl 0x30(%rsp), %esi
jmp 0x280b
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rcx
decl %eax
movzbl (%rcx,%rax), %ebp
movq 0x68(%rsp), %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movl 0xb0(%rsp), %ebx
movzwl %bp, %ebp
movw $0xfffe, %r15w          # imm = 0xFFFE
xorl %r14d, %r14d
decl %ebx
cmpq %r13, %r14
je 0x2b01
movq 0x20(%rsp), %rdi
callq 0x2030
movq 0x10(%rsp), %rdx
movq %rax, %rcx
xorl %esi, %esi
movq %rcx, (%rdx,%r14,8)
cmpq %rsi, 0x20(%rsp)
je 0x2afc
movq 0x50(%rsp), %rax
movq (%rax,%r14,8), %rax
movzwl (%rax,%rsi,2), %edi
movq 0x38(%rsp), %rax
movzbl (%rax,%rsi), %edx
movl %ebp, %eax
subl %edx, %eax
cwtd
idivw %r15w
addl %ebx, %eax
btl %eax, %edi
setb (%rcx,%rsi)
incq %rsi
jmp 0x2ac7
incq %r14
jmp 0x2aaa
leaq 0x870(%rsp), %rdi
callq 0x4ff8
movq 0x68(%rsp), %rdi
callq 0x2030
movq %rax, (%rsp)
leaq 0x870(%rsp), %r12
movb $0x3, %r14b
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq 0x40(%rsp), %rbx
je 0x2bba
movl 0xb4(%rsp), %ebp
movq %rbp, %rdi
callq 0x2030
movq (%rsp), %rcx
movq %rax, %r15
movq %r15, (%rcx,%rbx,8)
movl %r13d, %ecx
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x5362
movq %rbx, 0x18(%rsp)
movq %r15, %rbx
xorl %r15d, %r15d
movl 0xb4(%rsp), %eax
cmpq %rax, %r15
jae 0x2baa
leaq (%rbx,%r15), %rbp
movb (%rbp), %al
cmpb $-0x1, %al
jne 0x2b99
incl %r13d
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x5362
jmp 0x2b7c
movzbl %al, %eax
incq %r15
divb %r14b
movzbl %ah, %eax
movb %al, (%rbp)
jmp 0x2b6c
movq 0x18(%rsp), %rbx
incl %r13d
incq %rbx
jmp 0x2b2c
movq 0x40(%rsp), %r12
movq 0x10(%rsp), %rbx
xorl %eax, %eax
cmpq %rax, %r12
je 0x2be5
movq (%rsp), %rcx
movl 0xb4(%rsp), %edx
movq (%rcx,%rax,8), %rcx
decl %edx
incq %rax
movb $0x0, (%rcx,%rdx)
jmp 0x2bc6
leal (%r12,%r12,2), %eax
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movl %eax, 0xa4(%rsp)
movl 0xb4(%rsp), %eax
cmpq %rax, %r14
jae 0x2e49
movq 0xc0(%rsp), %rax
movq %r14, 0x18(%rsp)
movzbl (%rax,%r14), %r14d
pushq $0x1
popq %rax
movl 0xa4(%rsp), %ecx
shlxl %r14d, %eax, %r15d
movzbl %r15b, %r13d
movl %ecx, %edi
imull %r13d, %edi
movq %rdi, 0xd8(%rsp)
callq 0x2030
movq %rax, 0x48(%rsp)
movl 0xc(%rsp), %r9d
leal 0xff(%r15), %eax
movl %r14d, %r8d
movq %r14, 0x58(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x30(%rsp)
movq %r13, 0x20(%rsp)
movq %r8, 0x38(%rsp)
movl %eax, 0x28(%rsp)
leal (%r13,%r13,2), %eax
movl %eax, 0x68(%rsp)
movq %r9, 0x88(%rsp)
cmpq %r12, %r14
je 0x2da5
pushq $0x3
popq %rcx
cmpl $0x0, 0xc(%rsp)
movl %ecx, %eax
movq %rax, 0x70(%rsp)
je 0x2cba
movq (%rsp), %rax
movq 0x18(%rsp), %rdx
movq (%rax,%r14,8), %rax
movzbl -0x1(%rax,%rdx), %eax
subl %eax, %ecx
movq %rcx, 0x70(%rsp)
movq 0x30(%rsp), %r12
xorl %ecx, %ecx
cmpl $0x3, %ecx
je 0x2d8a
movq 0x70(%rsp), %rax
movq %rcx, 0x98(%rsp)
xorl %r13d, %r13d
addl %ecx, %eax
xorl %ecx, %ecx
cmpq %rcx, %r8
je 0x2cfc
movq (%rbx,%r14,8), %rdx
leal (%r9,%rcx), %esi
movzbl (%rdx,%rsi), %edx
shlxl %ecx, %edx, %edx
incq %rcx
addb %dl, %r13b
jmp 0x2cde
cltd
pushq $0x3
popq %rcx
idivl %ecx
xorl %ebp, %ebp
movzbl %dl, %ebx
cmpb %r15b, %bpl
jae 0x2d61
movl %ebp, %eax
xorb %r13b, %al
movzbl %al, %eax
andnl 0x28(%rsp), %eax, %eax
movzbl %al, %edi
callq 0x483c
movq (%rsp), %rdx
movq 0x58(%rsp), %rcx
subb %al, %cl
movl %ebx, %eax
movzbl %cl, %ecx
subl %ecx, %eax
movq (%rdx,%r14,8), %rcx
movq 0x18(%rsp), %rdx
movb (%rcx,%rdx), %dl
js 0x2d51
movzbl %dl, %ecx
movw $0x3, %si
xorl %edx, %edx
addl %ecx, %eax
divw %si
movq 0x48(%rsp), %rcx
leal (%r12,%rbp), %eax
incl %ebp
movb %dl, (%rcx,%rax)
jmp 0x2d07
movq 0x98(%rsp), %rcx
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %rbx
movq 0x38(%rsp), %r8
movq 0x88(%rsp), %r9
incl %ecx
addl %r13d, %r12d
jmp 0x2cc1
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %r12
incq %r14
addl 0x68(%rsp), %eax
movq %rax, 0x30(%rsp)
jmp 0x2c87
movq %r12, %rdi
callq 0x2030
movq 0x58(%rsp), %r15
movq %rax, %r13
leal 0x2(%r15), %eax
movq 0x60(%rsp), %rdi
movzbl %al, %esi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4a6a
movq 0xd8(%rsp), %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
pushq $0x2
popq %rbp
movq 0x18(%rsp), %r14
movq 0x78(%rsp), %rax
movq (%rax,%r14,8), %rsi
movq 0x28(%rsp), %rdi
movq 0x48(%rsp), %rdx
movq %r13, %rcx
movl %r12d, %r8d
movl %ebp, %r9d
callq 0x3b08
movq 0x60(%rsp), %rdi
movq 0xd8(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl %ebp, %esi
callq 0x4997
addl %r15d, 0xc(%rsp)
movq 0x48(%rsp), %rdi
callq 0x22c0
movq %r13, %rdi
callq 0x22c0
movq 0x28(%rsp), %rdi
callq 0x22c0
incq %r14
jmp 0x2bfb
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x2ea3
movq 0x90(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2e66
callq 0x22c0
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2e79
callq 0x22c0
movq (%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2e8b
callq 0x22c0
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2e9e
callq 0x22c0
incq %rbx
jmp 0x2e4b
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2eb5
callq 0x22c0
movq 0x50(%rsp), %rdi
callq 0x22c0
movq (%rsp), %rdi
callq 0x22c0
movq 0x10(%rsp), %rdi
callq 0x22c0
xorl %r14d, %r14d
movl 0xb0(%rsp), %eax
cmpq %rax, %r14
jae 0x2f07
movq 0x80(%rsp), %rax
movq (%rax,%r14,8), %rbx
testq %rbx, %rbx
je 0x2efa
movq %rbx, %rdi
callq 0x374c
movq %rbx, %rdi
callq 0x2200
incq %r14
jmp 0x2ed5
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x2f19
callq 0x22c0
xorl %r14d, %r14d
movl 0xb4(%rsp), %eax
cmpq %rax, %r14
jae 0x2f4b
movq 0x78(%rsp), %rax
movq (%rax,%r14,8), %rbx
testq %rbx, %rbx
je 0x2f3e
movq %rbx, %rdi
callq 0x374c
movq %rbx, %rdi
callq 0x2200
incq %r14
jmp 0x2f1c
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2f5a
callq 0x22c0
leaq 0x870(%rsp), %rdi
callq 0x5238
leaq 0x140(%rsp), %rdi
callq 0x5238
leaq 0x258(%rsp), %rdi
callq 0x2090
leaq 0x668(%rsp), %rdi
callq 0x2090
leaq 0xa8(%rsp), %rdi
callq 0x4476
leaq 0x460(%rsp), %rdi
callq 0x2090
addq $0x988, %rsp            # imm = 0x988
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3062
jmp 0x305b
jmp 0x305b
jmp 0x305b
jmp 0x3046
leaq 0x140(%rsp), %rdi
movq %rax, %rbx
callq 0x20f0
jmp 0x307f
jmp 0x3046
jmp 0x301c
jmp 0x301c
leaq 0xe0(%rsp), %rdi
jmp 0x2ffd
leaq 0x110(%rsp), %rdi
movq %rax, %rbx
callq 0x4476
jmp 0x308c
leaq 0x258(%rsp), %rdi
movq %rax, %rbx
callq 0x20f0
jmp 0x308c
movq %rax, %rbx
jmp 0x308c
jmp 0x3023
movq %rax, %rbx
jmp 0x3099
jmp 0x302a
movq %rax, %rbx
jmp 0x30a6
leaq 0x460(%rsp), %rdi
movq %rax, %rbx
callq 0x20f0
jmp 0x30b3
movq %rax, %rbx
jmp 0x30b3
movq %rax, %rbx
jmp 0x307f
jmp 0x3062
jmp 0x305b
jmp 0x305b
jmp 0x3062
jmp 0x3062
jmp 0x3062
jmp 0x305b
jmp 0x305b
movq %rax, %rbx
jmp 0x3072
jmp 0x3062
leaq 0x870(%rsp), %rdi
movq %rax, %rbx
callq 0x5238
leaq 0x140(%rsp), %rdi
callq 0x5238
leaq 0x258(%rsp), %rdi
callq 0x2090
leaq 0x668(%rsp), %rdi
callq 0x2090
leaq 0xa8(%rsp), %rdi
callq 0x4476
leaq 0x460(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2390