// File: /workspace/github_cpp_makefile_star2_O1/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 $0x978, %rsp            # imm = 0x978
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x68(%rsp)
leaq 0x468(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4e19(%rip), %rsi      # 0x73d4
leaq 0x4e2a(%rip), %rdx      # 0x73ec
leaq 0x458(%rsp), %rdi
callq 0x3b5e
leaq 0x458(%rsp), %rdi
callq 0x34e5
movq 0x458(%rsp), %rdi
cmpq %r15, %rdi
je 0x25ee
callq 0x21f0
leaq 0x458(%rsp), %r15
movq %r15, %rdi
callq 0x2270
movq %r15, %rdi
movq %r14, %rsi
movl $0xc, %edx
callq 0x21b0
leaq 0x88(%rsp), %rdi
leaq 0x458(%rsp), %rsi
callq 0x4c28
leaq 0x458(%rsp), %rdi
callq 0x2070
leaq 0x770(%rsp), %rdi
callq 0x2270
leaq 0x260(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x250(%rsp), %rdi
callq 0x3ace
leaq 0x4d86(%rip), %rsi      # 0x73ed
leaq 0x250(%rsp), %rdi
callq 0x23f0
leaq 0x770(%rsp), %rdi
leaq 0x250(%rsp), %rsi
movl $0xc, %edx
callq 0x21b0
movq 0x250(%rsp), %rdi
cmpq %r14, %rdi
je 0x26a0
callq 0x21f0
vmovdqu 0x88(%rsp), %ymm0
vmovdqu 0x98(%rsp), %ymm1
leaq 0x110(%rsp), %rsi
vmovdqu %ymm0, (%rsi)
vmovdqu %ymm1, 0x10(%rsi)
leaq 0x770(%rsp), %rdi
vzeroupper
callq 0x4fa2
movq %rax, 0xb8(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x4d28
vmovdqu 0x88(%rsp), %ymm0
vmovdqu 0x98(%rsp), %ymm1
leaq 0xe0(%rsp), %rsi
vmovdqu %ymm1, 0x10(%rsi)
vmovdqu %ymm0, (%rsi)
leaq 0x770(%rsp), %rdi
vzeroupper
callq 0x5019
movq %rax, %r15
leaq 0xe0(%rsp), %rdi
callq 0x4d28
leaq 0x770(%rsp), %rdi
callq 0x2070
movl 0x88(%rsp), %r12d
movl 0x8c(%rsp), %ebp
movq 0xa8(%rsp), %r13
leaq 0x250(%rsp), %rdi
callq 0x2270
leaq 0x150(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x140(%rsp), %rdi
callq 0x3ace
leaq 0x4c6f(%rip), %rsi      # 0x73f5
leaq 0x140(%rsp), %rdi
callq 0x23f0
leaq 0x250(%rsp), %rdi
leaq 0x140(%rsp), %rsi
movl $0x8, %edx
callq 0x21b0
movq 0x140(%rsp), %rdi
cmpq %r14, %rdi
je 0x27bf
callq 0x21f0
leaq 0x250(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x52e7
movq %rax, 0xc0(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x2070
movq %r13, 0x18(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x5a38
movq %r15, 0xd0(%rsp)
leaq (,%r12,8), %rdi
movq %rdi, 0x70(%rsp)
callq 0x2030
movq %rax, %r13
movq %r12, 0x30(%rsp)
testq %r12, %r12
je 0x285c
leaq (%rbp,%rbp), %rbx
leal (%rbp,%rbp), %r14d
xorl %r15d, %r15d
leaq 0x140(%rsp), %r12
movq %rbx, %rdi
callq 0x2030
movq %rax, (%r13,%r15,8)
movq %r12, %rdi
movq %rax, %rsi
movl %r14d, %edx
movq %r15, %rcx
callq 0x5f56
incq %r15
cmpq %r15, 0x30(%rsp)
jne 0x2834
movq %r13, 0x50(%rsp)
cmpl $0x0, 0x90(%rsp)
movq 0x30(%rsp), %r15
je 0x2dfd
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
xorl %r13d, %r13d
movq %rbp, 0x40(%rsp)
movslq %r13d, %rax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %ecx
cmpl %ecx, %esi
jb 0x28ad
leal -0x1(%rax), %r13d
addq 0x18(%rsp), %rax
movzbl (%rax), %ecx
incl %r13d
incq %rax
cmpl %ecx, %esi
jae 0x28a0
movl %esi, (%rsp)
movq 0x98(%rsp), %rax
movq 0x8(%rsp), %rcx
movzbl (%rax,%rcx), %ecx
movl $0x1, %eax
movq %rcx, 0x20(%rsp)
shlxl %ecx, %eax, %r12d
movl %r12d, %ebx
movl $0xff, %eax
andl %eax, %ebx
movl %ebp, %eax
subl %r13d, %eax
movzbl %al, %eax
movl %eax, 0x38(%rsp)
imull %r15d, %eax
movl %ebx, %edi
movl %eax, 0x48(%rsp)
imull %eax, %edi
addl %edi, %edi
callq 0x2030
movq %rax, 0x28(%rsp)
leal (%r12,%r12), %eax
movzbl %al, %r14d
testq %r15, %r15
vpmovsxbd 0x4a80(%rip), %zmm24 # 0x7394
vpmovsxbd 0x4a86(%rip), %zmm25 # 0x73a4
vpmovsxbd 0x4a8c(%rip), %zmm26 # 0x73b4
vpmovsxbd 0x4a92(%rip), %zmm27 # 0x73c4
vpmovsxbq 0x4a14(%rip), %zmm29 # 0x7350
vpmovsxbq 0x4a12(%rip), %zmm30 # 0x7358
vpmovsxbq 0x4a10(%rip), %zmm31 # 0x7360
je 0x2d32
movl $0xff, %r10d
leal (%r12,%r10), %r11d
movq 0x8(%rsp), %rcx
leal -0x1(%rcx), %edx
movl $0x1, %esi
shlxl %edx, %esi, %edx
movl %edx, 0x60(%rsp)
shlxl %ecx, %esi, %ecx
movl %ecx, 0x80(%rsp)
movl %r14d, %r9d
shrl %r9d
decl %ebx
movl $0x2, %ecx
movq 0x20(%rsp), %rdx
shlxq %rdx, %rcx, %rdi
movzbl %dil, %r8d
leal 0x3f(%r8), %edi
decq %r8
vpbroadcastq %r8, %zmm0
movl 0x38(%rsp), %ecx
movl %ecx, %r8d
andl $-0x40, %edi
vpbroadcastq %r9, %zmm1
vpbroadcastd %ebx, %zmm2
andl $0x7f, %r12d
imull %ecx, %r12d
addl %r12d, %r12d
movq $0x0, 0x58(%rsp)
andl %r10d, %r11d
movl %r11d, 0x10(%rsp)
xorl %r10d, %r10d
movq %r12, 0x78(%rsp)
cmpl $0x0, 0x38(%rsp)
je 0x2d0f
movq 0x50(%rsp), %rcx
movq (%rcx,%r10,8), %r11
movq 0x58(%rsp), %rcx
movl %ecx, %ebx
xorl %r9d, %r9d
leal (%r13,%r9), %r12d
cmpq $0x0, 0x8(%rsp)
je 0x2a2b
movq 0x50(%rsp), %rcx
movq (%rcx,%r10,8), %r15
movzbl %r12b, %ebp
movzwl (%r15,%rbp,2), %ebp
testl %ebp, 0x60(%rsp)
sete %bpl
jmp 0x2a2e
movb $0x1, %bpl
testb %al, %al
je 0x2d00
movl %ebx, %r15d
addq 0x28(%rsp), %r15
movl $0xff, %ecx
andl %ecx, %r12d
movzwl (%r11,%r12,2), %ecx
andl 0x80(%rsp), %ecx
movq 0xc0(%rsp), %rdx
movq (%rdx,%r10,8), %rdx
movl (%rsp), %esi
shrxl %esi, (%rdx,%r12,4), %edx
andl 0x10(%rsp), %edx
vpbroadcastd %edx, %zmm3
negl %ecx
sbbq %rcx, %rcx
kmovq %rcx, %k0
movl %ebp, %ecx
xorb $0x1, %cl
movl $0x0, %ecx
movq $-0x1, %rdx
cmovneq %rdx, %rcx
kmovq %rcx, %k1
xorl %r12d, %r12d
vpmovsxbq 0x48c6(%rip), %zmm4 # 0x7368
vpmovsxbq 0x48c4(%rip), %zmm5 # 0x7370
vpmovsxbq 0x48c2(%rip), %zmm6 # 0x7378
vpmovsxbq 0x48c0(%rip), %zmm7 # 0x7380
vmovdqa64 %zmm31, %zmm8
vmovdqa64 %zmm30, %zmm9
vmovdqa64 %zmm29, %zmm10
vpmovsxbq 0x48ac(%rip), %zmm11 # 0x7388
vmovdqa64 %zmm27, %zmm12
vmovdqa64 %zmm26, %zmm13
vmovdqa64 %zmm25, %zmm14
vmovdqa64 %zmm24, %zmm15
vmovdqa64 %zmm27, %zmm16
vmovdqa64 %zmm26, %zmm17
vmovdqa64 %zmm25, %zmm18
vmovdqa64 %zmm24, %zmm19
vpcmpleuq %zmm0, %zmm4, %k2
vpcmpleuq %zmm0, %zmm5, %k3
kunpckbw %k2, %k3, %k2
vpcmpleuq %zmm0, %zmm6, %k3
vpcmpleuq %zmm0, %zmm7, %k4
kunpckbw %k3, %k4, %k3
kunpckwd %k2, %k3, %k2
vpcmpleuq %zmm0, %zmm8, %k3
vpcmpleuq %zmm0, %zmm9, %k4
kunpckbw %k3, %k4, %k3
vpcmpleuq %zmm0, %zmm10, %k4
vpcmpleuq %zmm0, %zmm11, %k5
kunpckbw %k4, %k5, %k4
kunpckwd %k3, %k4, %k3
kunpckdq %k2, %k3, %k2
vpcmpltuq %zmm1, %zmm4, %k3
vpcmpltuq %zmm1, %zmm5, %k4
kunpckbw %k3, %k4, %k3
vpcmpltuq %zmm1, %zmm6, %k4
vpcmpltuq %zmm1, %zmm7, %k5
kunpckbw %k4, %k5, %k4
kunpckwd %k3, %k4, %k3
vpcmpltuq %zmm1, %zmm8, %k4
vpcmpltuq %zmm1, %zmm9, %k5
kunpckbw %k4, %k5, %k4
vpcmpltuq %zmm1, %zmm10, %k5
vpcmpltuq %zmm1, %zmm11, %k6
kunpckbw %k5, %k6, %k5
kunpckwd %k4, %k5, %k4
kunpckdq %k3, %k4, %k3
kxnorq %k0, %k0, %k5
kandnq %k2, %k3, %k4
testb %bpl, %bpl
jne 0x2c06
vpandd %zmm15, %zmm2, %zmm20
vpandd %zmm14, %zmm2, %zmm21
vpandd %zmm13, %zmm2, %zmm22
vpandd %zmm12, %zmm2, %zmm23
vpcmpneqd %zmm23, %zmm3, %k5
vpcmpneqd %zmm22, %zmm3, %k6
kunpckwd %k5, %k6, %k5
vpcmpneqd %zmm21, %zmm3, %k6
vpcmpneqd %zmm20, %zmm3, %k7
kunpckwd %k6, %k7, %k6
kunpckdq %k5, %k6, %k5
kxorq %k5, %k0, %k5
vpbroadcastb 0x472b(%rip), %zmm28 # 0x7340
vmovdqu8 %zmm28, %zmm20 {%k5} {z}
vmovdqu8 %zmm20, (%r15,%r12) {%k4}
kandq %k3, %k2, %k2
vpandd %zmm19, %zmm2, %zmm20
vpandd %zmm18, %zmm2, %zmm21
vpandd %zmm17, %zmm2, %zmm22
vpandd %zmm16, %zmm2, %zmm23
vpcmpneqd %zmm23, %zmm3, %k3
vpcmpneqd %zmm22, %zmm3, %k4
kunpckwd %k3, %k4, %k3
vpcmpneqd %zmm21, %zmm3, %k4
vpcmpneqd %zmm20, %zmm3, %k5
kunpckwd %k4, %k5, %k4
kunpckdq %k3, %k4, %k3
korq %k3, %k1, %k3
kxorq %k3, %k0, %k3
vmovdqu8 %zmm28, %zmm20 {%k3} {z}
vmovdqu8 %zmm20, (%r15,%r12) {%k2}
addq $0x40, %r12
vpbroadcastq 0x46bb(%rip), %zmm20 # 0x7348
vpaddq %zmm20, %zmm4, %zmm4
vpaddq %zmm20, %zmm5, %zmm5
vpaddq %zmm20, %zmm6, %zmm6
vpaddq %zmm20, %zmm7, %zmm7
vpaddq %zmm20, %zmm8, %zmm8
vpaddq %zmm20, %zmm9, %zmm9
vpaddq %zmm20, %zmm10, %zmm10
vpaddq %zmm20, %zmm11, %zmm11
vpbroadcastd 0x46c9(%rip), %zmm20 # 0x7390
vpaddd %zmm20, %zmm12, %zmm12
vpaddd %zmm20, %zmm13, %zmm13
vpaddd %zmm20, %zmm14, %zmm14
vpaddd %zmm20, %zmm15, %zmm15
vpaddd %zmm20, %zmm16, %zmm16
vpaddd %zmm20, %zmm17, %zmm17
vpaddd %zmm20, %zmm18, %zmm18
vpaddd %zmm20, %zmm19, %zmm19
cmpq %r12, %rdi
jne 0x2b0c
incq %r9
addl %r14d, %ebx
cmpq %r8, %r9
jne 0x2a02
incq %r10
movq 0x78(%rsp), %r12
movq 0x58(%rsp), %rcx
addl %r12d, %ecx
movq %rcx, 0x58(%rsp)
movq 0x30(%rsp), %r15
cmpq %r15, %r10
jne 0x29e4
movl 0x48(%rsp), %edi
movq %rdi, %r12
vzeroupper
callq 0x2030
movq 0x20(%rsp), %rbp
movq %rax, %rbx
leal 0x1(%rbp), %eax
movzbl %al, %esi
movq 0x68(%rsp), %rdi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x5415
movl 0x48(%rsp), %r12d
imull %r12d, %r14d
movq %r14, %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rbp
movq 0xb8(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq %rbx, %rcx
movl %r12d, %r8d
movl $0x1, %r9d
callq 0x42c1
movq 0x68(%rsp), %rdi
movl $0x1, %esi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0x533b
movq 0x28(%rsp), %rdi
callq 0x22c0
movq %rbx, %rdi
callq 0x22c0
movq 0x10(%rsp), %rdi
callq 0x22c0
movl (%rsp), %esi
addl 0x20(%rsp), %esi
movq 0x8(%rsp), %rdx
incq %rdx
movl 0x90(%rsp), %eax
movq %rdx, 0x8(%rsp)
cmpq %rax, %rdx
jb 0x2887
leal -0x1(%rbp), %eax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %ebx
movq 0x70(%rsp), %rdi
callq 0x2030
movq %rax, %r12
testq %r15, %r15
je 0x2e7d
xorl %r14d, %r14d
movq %rbp, %rdi
callq 0x2030
movq %rax, (%r12,%r14,8)
testl %ebp, %ebp
movq 0x50(%rsp), %r8
movq 0x18(%rsp), %r9
je 0x2e75
xorl %eax, %eax
movq (%r8,%r14,8), %rcx
movzwl (%rcx,%rax,2), %ecx
movl 0x90(%rsp), %edx
movzbl (%r9,%rax), %esi
movl %ebx, %edi
subl %esi, %edi
movl %edi, %esi
shrl $0x1f, %esi
addl %edi, %esi
shrl %esi
subl %esi, %edx
decb %dl
movzbl %dl, %edx
btl %edx, %ecx
movq (%r12,%r14,8), %rcx
setb (%rcx,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x2e3a
incq %r14
cmpq %r15, %r14
jne 0x2e1e
leaq 0x660(%rsp), %rdi
callq 0x5a38
movq 0x70(%rsp), %rdi
callq 0x2030
movq %rax, %rbp
testq %r15, %r15
movq %r12, 0x20(%rsp)
je 0x2f64
xorl %r14d, %r14d
leaq 0x660(%rsp), %rbx
xorl %r12d, %r12d
movl 0x94(%rsp), %r15d
movq %r15, %rdi
callq 0x2030
movq %rax, (%rbp,%r14,8)
movl %r12d, %ecx
movq %rbx, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x5f56
cmpl $0x0, 0x94(%rsp)
je 0x2f2d
xorl %r15d, %r15d
movq (%rbp,%r14,8), %rsi
movb (%rsi,%r15), %al
addq %r15, %rsi
cmpb $-0x1, %al
jne 0x2f0b
incl %r12d
movq %rbx, %rdi
movl $0x1, %edx
movq %r12, %rcx
callq 0x5f56
jmp 0x2ee6
movzbl %al, %ecx
imull $0xab, %ecx, %ecx
shrl $0x9, %ecx
leal (%rcx,%rcx,2), %ecx
subb %cl, %al
movb %al, (%rsi)
incq %r15
movl 0x94(%rsp), %eax
cmpq %rax, %r15
jb 0x2ee6
incl %r12d
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x2eb3
xorl %eax, %eax
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %r12
movq (%rbp,%rax,8), %rcx
movl 0x94(%rsp), %edx
decl %edx
movb $0x0, (%rcx,%rdx)
incq %rax
cmpq %rax, %r15
jne 0x2f4a
cmpl $0x0, 0x94(%rsp)
je 0x324c
leal (%r15,%r15,2), %eax
movl %eax, 0xcc(%rsp)
xorl %ebx, %ebx
movl $0x0, 0x40(%rsp)
movq %rbp, 0x28(%rsp)
movq 0xa0(%rsp), %rax
movq %rbx, 0x10(%rsp)
movzbl (%rax,%rbx), %ecx
movl $0x1, %eax
movq %rcx, 0x8(%rsp)
shlxl %ecx, %eax, %eax
movq %rax, 0x80(%rsp)
movzbl %al, %ecx
movl 0xcc(%rsp), %eax
movl %eax, %edi
movq %rcx, 0x78(%rsp)
imull %ecx, %edi
movq %rdi, 0xd8(%rsp)
callq 0x2030
movq %rax, 0x60(%rsp)
testq %r15, %r15
je 0x319a
movq 0x80(%rsp), %rax
addl $0xff, %eax
movl %eax, 0x58(%rsp)
movl 0x8(%rsp), %r14d
movl 0x40(%rsp), %r13d
movq 0x78(%rsp), %rax
leal (%rax,%rax,2), %eax
movl %eax, 0x70(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, (%rsp)
cmpl $0x0, 0x40(%rsp)
je 0x3043
movq (%rsp), %rax
movq (%rbp,%rax,8), %rax
movq 0x10(%rsp), %rcx
movzbl -0x1(%rax,%rcx), %eax
movl $0x3, %ecx
subl %eax, %ecx
movq %rcx, 0x48(%rsp)
jmp 0x304d
movl $0x3, %eax
movq %rax, 0x48(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x18(%rsp), %r12
cmpl $0x0, 0x8(%rsp)
je 0x308f
movq 0x20(%rsp), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
leal (%r13,%rcx), %edx
movzbl (%rax,%rdx), %edx
shlxl %ecx, %edx, %edx
addb %dl, %r15b
incq %rcx
cmpq %rcx, %r14
jne 0x3074
jmp 0x3092
xorl %r15d, %r15d
cmpb $0x7, 0x8(%rsp)
ja 0x314f
movq 0x48(%rsp), %rax
movq 0x38(%rsp), %rcx
addl %ecx, %eax
cltq
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movzbl %al, %ebp
xorl %ebx, %ebx
movl %ebx, %eax
xorb %r15b, %al
movzbl %al, %eax
andnl 0x58(%rsp), %eax, %eax
movzbl %al, %edi
callq 0x5186
movq 0x8(%rsp), %rcx
subb %al, %cl
movzbl %cl, %ecx
movl %ebp, %eax
subl %ecx, %eax
js 0x311f
movq 0x28(%rsp), %rcx
movq (%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x10(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movq %rax, %rcx
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
imulq %rdx, %rcx
shrq $0x21, %rcx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
jmp 0x3134
movq 0x28(%rsp), %rax
movq (%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %al
leal (%r12,%rbx), %ecx
movq 0x60(%rsp), %rdx
movb %al, (%rdx,%rcx)
incl %ebx
cmpb 0x80(%rsp), %bl
jb 0x30c9
movq 0x38(%rsp), %rcx
incl %ecx
addl 0x78(%rsp), %r12d
movq %rcx, 0x38(%rsp)
cmpl $0x3, %ecx
movq 0x28(%rsp), %rbp
jne 0x305b
movq (%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rax
addl 0x70(%rsp), %eax
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %r15
movq %rcx, (%rsp)
cmpq %r15, %rcx
movq 0x20(%rsp), %r12
jne 0x301b
movq %r15, %rdi
callq 0x2030
movq %rax, %r13
movq 0x8(%rsp), %rax
addl $0x2, %eax
movzbl %al, %esi
movq 0x68(%rsp), %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0x5415
movq 0xd8(%rsp), %r14
movq %r14, %rdi
callq 0x2030
movq %rax, (%rsp)
movq 0x10(%rsp), %rbx
movq 0xd0(%rsp), %rax
movq (%rax,%rbx,8), %rsi
movq (%rsp), %rdi
movq 0x60(%rsp), %rdx
movq %r13, %rcx
movl %r15d, %r8d
movl $0x2, %r9d
callq 0x42c1
movq 0x68(%rsp), %rdi
movl $0x2, %esi
movq %r14, %rdx
movq (%rsp), %rcx
callq 0x533b
movq 0x8(%rsp), %rax
addl %eax, 0x40(%rsp)
movq 0x60(%rsp), %rdi
callq 0x22c0
movq %r13, %rdi
callq 0x22c0
movq (%rsp), %rdi
callq 0x22c0
incq %rbx
movl 0x94(%rsp), %eax
cmpq %rax, %rbx
jb 0x2f8c
testq %r15, %r15
movq 0xd0(%rsp), %r13
je 0x32a9
xorl %ebx, %ebx
movq 0xc0(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x3271
callq 0x22c0
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x3284
callq 0x22c0
movq (%rbp,%rbx,8), %rdi
testq %rdi, %rdi
je 0x3293
callq 0x22c0
movq (%r12,%rbx,8), %rdi
testq %rdi, %rdi
je 0x32a1
callq 0x22c0
incq %rbx
cmpq %rbx, %r15
jne 0x325b
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x32bb
callq 0x22c0
movq 0x50(%rsp), %rdi
callq 0x22c0
movq %rbp, %rdi
callq 0x22c0
movq %r12, %rdi
callq 0x22c0
cmpl $0x0, 0x90(%rsp)
movq 0xb8(%rsp), %rdi
je 0x331a
xorl %r14d, %r14d
movq (%rdi,%r14,8), %rbx
testq %rbx, %rbx
je 0x330b
movq %rbx, %rdi
callq 0x3ef6
movq %rbx, %rdi
callq 0x21f0
movq 0xb8(%rsp), %rdi
incq %r14
movl 0x90(%rsp), %eax
cmpq %rax, %r14
jb 0x32ea
testq %rdi, %rdi
je 0x3324
callq 0x22c0
cmpl $0x0, 0x94(%rsp)
je 0x335a
xorl %r14d, %r14d
movq (%r13,%r14,8), %rbx
testq %rbx, %rbx
je 0x334b
movq %rbx, %rdi
callq 0x3ef6
movq %rbx, %rdi
callq 0x21f0
incq %r14
movl 0x94(%rsp), %eax
cmpq %rax, %r14
jb 0x3331
testq %r13, %r13
je 0x3367
movq %r13, %rdi
callq 0x22c0
leaq 0x660(%rsp), %rdi
callq 0x5e06
leaq 0x140(%rsp), %rdi
callq 0x5e06
leaq 0x250(%rsp), %rdi
callq 0x2090
leaq 0x770(%rsp), %rdi
callq 0x2090
leaq 0x88(%rsp), %rdi
callq 0x4d28
leaq 0x458(%rsp), %rdi
callq 0x2090
addq $0x978, %rsp            # imm = 0x978
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x348c
jmp 0x3485
jmp 0x3485
jmp 0x3485
jmp 0x3470
jmp 0x33e2
movq %rax, %rbx
movq 0x140(%rsp), %rdi
cmpq %r14, %rdi
je 0x34a9
callq 0x21f0
jmp 0x34a9
jmp 0x3470
jmp 0x3441
jmp 0x3441
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x341e
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x4d28
jmp 0x34b6
jmp 0x342a
movq %rax, %rbx
movq 0x250(%rsp), %rdi
cmpq %r14, %rdi
je 0x34b6
callq 0x21f0
jmp 0x34b6
movq %rax, %rbx
jmp 0x34b6
jmp 0x3448
movq %rax, %rbx
jmp 0x34c3
jmp 0x344f
movq %rax, %rbx
jmp 0x34d0
movq %rax, %rbx
movq 0x458(%rsp), %rdi
cmpq %r15, %rdi
je 0x34dd
callq 0x21f0
jmp 0x34dd
movq %rax, %rbx
jmp 0x34dd
movq %rax, %rbx
jmp 0x34a9
jmp 0x348c
jmp 0x3485
jmp 0x3485
jmp 0x348c
jmp 0x348c
jmp 0x3485
jmp 0x3485
jmp 0x348c
movq %rax, %rbx
jmp 0x349c
jmp 0x348c
movq %rax, %rbx
leaq 0x660(%rsp), %rdi
callq 0x5e06
leaq 0x140(%rsp), %rdi
callq 0x5e06
leaq 0x250(%rsp), %rdi
callq 0x2090
leaq 0x770(%rsp), %rdi
callq 0x2090
leaq 0x88(%rsp), %rdi
callq 0x4d28
leaq 0x458(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x23a0