// File: /workspace/github_cpp_makefile_star2_O3/jBlinden[P]private-codis/ProtocolClient.cpp
// Function: RunClientProtocol(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 RunClientProtocol(CSocket *socket, string pArgsFile, string clientDataDir)
{
  ClientLog("starting client protocol");

#if !OPTIMAL
  ClientLog("Reading in protocol arguments");
#endif

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

  in.close();

#if !OPTIMAL
  ClientLog("Reading in receiver OTs");
#endif

  ifstream rOTFile1;
  rOTFile1.open(clientDataDir + "rOT.txt", ios::in | ios::binary);

  ReceiverOTCorrelation **FSM1_RC = ReadInReceiverOTsFSM1(rOTFile1, pArgs);
  ReceiverOTCorrelation **FSM2_RC = ReadInReceiverOTsFSM2(rOTFile1, pArgs);

  rOTFile1.close();

#if !OPTIMAL
  ClientLog("Finished Reading in OTs");
#endif

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

#if !OPTIMAL
  cout << "N: " << N << " C: " << C << endl;
#endif

  ifstream queryFile;
  queryFile.open(clientDataDir + "query.txt");
  uint32_t *query = ReadInEntry(queryFile, C);
  queryFile.close();

#if VERBOSE
  cout << "Query: ";
  for (int i = 0; i < C; i++)
  {
    cout << query[i] << " ";
  }
  cout << endl;
#endif

#if !OPTIMAL
  ClientLog("Creating clients states");
#endif

  uint8_t **client_states = new uint8_t *[N];
  for (int i = 0; i < N; i++)
  {
    client_states[i] = new uint8_t[C];
    for (int j = 0; j < C; j++)
    {
      client_states[i][j] = 0; //Default state is 0
    }
  }

#if !OPTIMAL
  ClientLog("Starting first FSM");

  cout << pArgs.FSM1_rounds << endl;
  for (int i = 0; i < pArgs.FSM1_rounds; i++)
  {
    cout << i << " : " << (uint32_t)pArgs.FSM1_steps[i] << endl;
  }
#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_higher_bit_entries = C - smallest_number_of_bits;
    uint8_t *choices = new uint8_t[N * number_of_higher_bit_entries * concurrent_iterations];
    
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < number_of_higher_bit_entries; j++)
      {
          
        uint8_t postImageJ = j + C - number_of_higher_bit_entries;
        uint8_t query_bits = (query[postImageJ] >> l) & all_ones_string;
        choices[number_of_higher_bit_entries * i + j] = pow_iterations * client_states[i][postImageJ] + query_bits;
      }
    }

#if !OPTIMAL
      ClientLog("Created Choice bits");
#endif
  
      
    uint8_t *rMsg = new uint8_t[N * number_of_higher_bit_entries];
    ConstructOTReceiverMsg(rMsg, *(FSM1_RC[round]), choices, N * number_of_higher_bit_entries);

      
    SendLargePacked(socket, 1 + concurrent_iterations, N * number_of_higher_bit_entries, rMsg);

   
    uint8_t *sMsg = new uint8_t[N * number_of_higher_bit_entries * pos_states];
    ReceiveLargePacked(socket, 1, N * number_of_higher_bit_entries * pos_states, sMsg);

      
    uint8_t *msgs2 = new uint8_t[N * number_of_higher_bit_entries];
    RecoverReceiverMsg(msgs2, *(FSM1_RC[round]), choices, sMsg, N * number_of_higher_bit_entries, 1, bits_FSM1);

#if !OPTIMAL
      ClientLog("Finished One Round");
#endif
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < number_of_higher_bit_entries; j++)
      {
        client_states[i][j + C - number_of_higher_bit_entries] = msgs2[number_of_higher_bit_entries * i + j];
      }
    }
    delete[] choices;
    delete[] msgs2;
    delete[] rMsg;
    delete[] sMsg;

    l += concurrent_iterations;
  }

#if !OPTIMAL
  ClientLog("Finished first FSM");
#endif

#if VERBOSE
  for (int i = 0; i < N; i++)
  {
    cout << "Database entry: " << i << endl;
    cout << "DB   : ";
    for (int j = 0; j < C; j++)
    {
      cout << 0 << ", ";
    }
    cout << endl;
    cout << "Query: ";
    for (int j = 0; j < C; j++)
    {
      cout << query[j] << ", ";
    }
    cout << endl;
    cout << "Equal: ";
    for (int j = 0; j < C; j++)
    {
      cout << (uint32_t)client_states[i][j] << ", ";
    }
    cout << endl;
    cout << "Actual: ";
    for (int j = 0; j < C; j++)
    {
      uint32_t value = (uint32_t)client_states[i][j];
      uint8_t accept_state = 0;

      if (accept_state == 1)
      {
        cout << value << ", ";
      }
      if (accept_state == 0)
      {
        cout << !value << ", ";
      }
    }
    cout << endl;
  }
#endif
#if !OPTIMAL
  ClientLog("Starting Second FSM");

  cout << "Finished with 1st part of OT correlation calculations" << endl;
  cout << "Setting up second FSM to compute k matches" << endl;

#endif

  uint8_t *client_k_state = new uint8_t[N];
  for (int i = 0; i < N; i++)
  {
    client_k_state[i] = 2; // default state
  }
  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 *choices = new uint8_t[N];
    for (int i = 0; i < N; i++)
    {
      // (client state, components equal)
      uint8_t client_state_value = 0;
      for (int j = 0; j < round_step; j++)
      {
        client_state_value += client_states[i][c + j] * (1 << j);
      }
      choices[i] = round_factor * client_k_state[i] + client_state_value;

    }

#if !OPTIMAL
    ClientLog("One one rounds");
#endif


    uint8_t *rMsg = new uint8_t[N];
    ConstructOTReceiverMsg(rMsg, *(FSM2_RC[round]), choices, N);

    SendLargePacked(socket, 2 + round_step, N, rMsg);
    
#if !OPTIMAL
    cout << "Sending: " << N << endl;
#endif

    uint8_t *sMsg = new uint8_t[N * 3 * round_factor];

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

    uint8_t *msgs2 = new uint8_t[N];
    RecoverReceiverMsg(msgs2, *(FSM2_RC[round]), choices, sMsg, N, 2, bits_FSM2);

    for (int i = 0; i < N; i++)
    {
      client_k_state[i] = msgs2[i];
    }

    c += round_step;

    delete[] choices;
    delete[] msgs2;
    delete[] rMsg;
    delete[] sMsg;
  }
#if !OPTIMAL
  ClientLog("Finished second FSM");
#endif
  for (int i = 0; i < N; i++)
  {
    if (client_k_state[i] > 0)
      ClientLog("found a match at index " + to_string(i));
  }

#if !OPTIMAL
  cout << "Memory clean up" << endl;
#endif

  delete[] query;
  for (int i = 0; i < N; i++)
  {
    delete[] client_states[i];
  }
  delete[] client_states;
  delete[] client_k_state;

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x798, %rsp            # imm = 0x798
leaq 0x398(%rsp), %r15
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x40(%rsp)
movq %r15, -0x10(%r15)
leaq 0x3c69(%rip), %rsi      # 0x6284
leaq 0x3c7a(%rip), %rdx      # 0x629c
leaq 0x388(%rsp), %rdi
callq 0x3940
leaq 0x388(%rsp), %rdi
callq 0x317c
movq 0x388(%rsp), %rdi
cmpq %r15, %rdi
je 0x264e
callq 0x2210
leaq 0x388(%rsp), %r15
movq %r15, %rdi
callq 0x22a0
movl $0xc, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21d0
leaq 0x70(%rsp), %rdi
leaq 0x388(%rsp), %rsi
callq 0x4a24
leaq 0x388(%rsp), %rdi
callq 0x2080
leaq 0x590(%rsp), %rdi
callq 0x22a0
leaq 0x190(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x180(%rsp), %rdi
callq 0x38aa
leaq 0x3bd9(%rip), %rsi      # 0x629d
leaq 0x180(%rsp), %rdi
callq 0x2450
leaq 0x590(%rsp), %rdi
leaq 0x180(%rsp), %rsi
movl $0xc, %edx
callq 0x21d0
movq 0x180(%rsp), %rdi
cmpq %r15, %rdi
je 0x26fd
callq 0x2210
vmovdqu 0x70(%rsp), %ymm0
vmovdqu 0x80(%rsp), %ymm1
leaq 0x150(%rsp), %rsi
vmovdqu %ymm0, (%rsi)
vmovdqu %ymm1, 0x10(%rsi)
leaq 0x590(%rsp), %rdi
vzeroupper
callq 0x4e93
movq %rax, 0x30(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x4b24
vmovdqu 0x70(%rsp), %ymm0
vmovdqu 0x80(%rsp), %ymm1
leaq 0x120(%rsp), %rsi
vmovdqu %ymm1, 0x10(%rsi)
vmovdqu %ymm0, (%rsi)
leaq 0x590(%rsp), %rdi
vzeroupper
callq 0x4f0e
movq %rax, 0x28(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x4b24
leaq 0x590(%rsp), %rdi
callq 0x2080
movq 0x90(%rsp), %rax
movl 0x70(%rsp), %r15d
movl 0x74(%rsp), %r13d
movq %rax, 0xa0(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x22a0
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x38aa
leaq 0x3acb(%rip), %rsi      # 0x62a5
leaq 0x50(%rsp), %rdi
callq 0x2450
leaq 0x180(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x8, %edx
callq 0x21d0
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x280a
callq 0x2210
leaq 0x180(%rsp), %rdi
movl %r13d, %esi
callq 0x4f9f
leaq 0x180(%rsp), %rdi
movq %rax, %rbp
callq 0x2080
leaq (,%r15,8), %rdi
callq 0x2030
movq %rax, %r12
testq %r15, %r15
je 0x2989
leaq 0x3f(%r13), %rbx
leaq -0x1(%r13), %rax
xorl %r14d, %r14d
andq $-0x40, %rbx
vpbroadcastq %rax, %zmm0
vmovdqu64 %zmm0, 0xe0(%rsp)
movq %r13, %rdi
vzeroupper
callq 0x2030
vmovdqu64 0xe0(%rsp), %zmm8
vpmovsxbq 0x39bd(%rip), %zmm9 # 0x6240
vpmovsxbq 0x39bb(%rip), %zmm10 # 0x6248
vpmovsxbq 0x39b9(%rip), %zmm11 # 0x6250
vpmovsxbq 0x39b7(%rip), %zmm12 # 0x6258
vpmovsxbq 0x39b5(%rip), %zmm13 # 0x6260
vpmovsxbq 0x39b3(%rip), %zmm14 # 0x6268
vpmovsxbq 0x39b1(%rip), %zmm15 # 0x6270
vpmovsxbq 0x39af(%rip), %zmm16 # 0x6278
vpxord %xmm17, %xmm17, %xmm17
movq %rax, (%r12,%r14,8)
testq %r13, %r13
je 0x297d
xorl %ecx, %ecx
vpbroadcastq %rcx, %zmm0
vporq %zmm9, %zmm0, %zmm1
vporq %zmm13, %zmm0, %zmm5
vporq %zmm15, %zmm0, %zmm7
vporq %zmm10, %zmm0, %zmm2
vporq %zmm11, %zmm0, %zmm3
vporq %zmm12, %zmm0, %zmm4
vporq %zmm14, %zmm0, %zmm6
vporq %zmm16, %zmm0, %zmm0
vpcmpleuq %zmm8, %zmm0, %k0
vpcmpleuq %zmm8, %zmm7, %k1
vpcmpleuq %zmm8, %zmm5, %k2
vpcmpleuq %zmm8, %zmm1, %k3
kunpckbw %k0, %k1, %k0
vpcmpleuq %zmm8, %zmm6, %k1
kunpckbw %k1, %k2, %k1
vpcmpleuq %zmm8, %zmm3, %k2
kunpckwd %k0, %k1, %k0
vpcmpleuq %zmm8, %zmm4, %k1
kunpckbw %k1, %k2, %k1
vpcmpleuq %zmm8, %zmm2, %k2
kunpckbw %k2, %k3, %k2
kunpckwd %k1, %k2, %k1
kunpckdq %k0, %k1, %k1
vmovdqu8 %zmm17, (%rax,%rcx) {%k1}
addq $0x40, %rcx
cmpq %rcx, %rbx
jne 0x28de
incq %r14
cmpq %r15, %r14
jne 0x2863
cmpl $0x0, 0x78(%rsp)
movq %r12, 0x48(%rsp)
movq %r15, 0xe0(%rsp)
je 0x2c0e
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r13, 0xa8(%rsp)
movq 0xa0(%rsp), %rcx
movslq %ebx, %rax
movzbl (%rcx,%rax), %ecx
cmpl %ecx, %r14d
jb 0x29e3
leal -0x1(%rax), %ebx
addq 0xa0(%rsp), %rax
movzbl (%rax), %ecx
incl %ebx
incq %rax
cmpl %ecx, %r14d
jae 0x29d6
movq 0x80(%rsp), %rax
movq 0x8(%rsp), %rcx
movzbl (%rax,%rcx), %r12d
movl %r13d, %eax
subl %ebx, %eax
movzbl %al, %r13d
movl %r13d, %eax
imull 0xe0(%rsp), %eax
movl %eax, %edi
movl %eax, 0x18(%rsp)
imull %r12d, %edi
vzeroupper
callq 0x2030
movq %rax, 0x10(%rsp)
cmpl $0x0, 0xe0(%rsp)
movq 0x48(%rsp), %r11
movl %r13d, %r15d
je 0x2a91
movq 0x10(%rsp), %rdx
movl $0x1, %eax
movl %ebx, %ecx
xorl %esi, %esi
shlxl %r12d, %eax, %eax
addl $0xff, %eax
testl %r13d, %r13d
je 0x2a81
movq (%r11,%rsi,8), %rdi
xorl %r8d, %r8d
leal (%rcx,%r8), %r9d
movzbl %r9b, %r9d
shrxl %r14d, (%rbp,%r9,4), %r10d
movzbl (%rdi,%r9), %r9d
andl %eax, %r10d
shlxl %r12d, %r9d, %r9d
addl %r10d, %r9d
movb %r9b, (%rdx,%r8)
incq %r8
cmpq %r8, %r15
jne 0x2a56
incq %rsi
addq %r15, %rdx
cmpq 0xe0(%rsp), %rsi
jne 0x2a4a
movl 0x18(%rsp), %edi
movl %r13d, 0x20(%rsp)
movq %rdi, 0x38(%rsp)
callq 0x2030
movq %rax, %r13
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x10(%rsp), %rdx
movl 0x18(%rsp), %ecx
movq %r13, %rdi
callq 0x404d
leal 0x1(%r12), %eax
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rdx
movzbl %al, %esi
movq %r13, %rcx
callq 0x5141
movl $0x2, %eax
movq %r13, 0xb8(%rsp)
shlxl %r12d, %eax, %r13d
andl $0xfe, %r13d
imull 0x18(%rsp), %r13d
movq %r13, %rdi
callq 0x2030
movq 0x40(%rsp), %rdi
movl $0x1, %esi
movq %r13, %rdx
movq %rax, %rcx
movq %rax, %r13
callq 0x521b
movq %r13, %rax
movq 0x38(%rsp), %rdi
movq %rax, 0xb0(%rsp)
callq 0x2030
movq %rax, %r13
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x10(%rsp), %rdx
movq 0xb0(%rsp), %rcx
movl 0x18(%rsp), %r8d
movl $0x1, %r9d
movq %r13, %rdi
movl $0x4, (%rsp)
callq 0x4192
cmpl $0x0, 0xe0(%rsp)
je 0x2bbd
movq 0xa8(%rsp), %rax
subl 0x20(%rsp), %eax
movq %r13, %rcx
xorl %edx, %edx
cmpl $0x0, 0x20(%rsp)
je 0x2bad
movq 0x48(%rsp), %rsi
xorl %edi, %edi
movq (%rsi,%rdx,8), %rsi
movb (%rcx,%rdi), %r8b
leal (%rax,%rdi), %r9d
incq %rdi
movb %r8b, (%rsi,%r9)
cmpq %rdi, %r15
jne 0x2b99
incq %rdx
addq %r15, %rcx
cmpq 0xe0(%rsp), %rdx
jne 0x2b87
movq 0x10(%rsp), %rdi
callq 0x2300
movq %r13, %rdi
callq 0x2300
movq 0xb8(%rsp), %rdi
callq 0x2300
movq 0xb0(%rsp), %rdi
callq 0x2300
movq 0x8(%rsp), %rdx
movl 0x78(%rsp), %eax
movq 0xa8(%rsp), %r13
addl %r12d, %r14d
incq %rdx
movq %rdx, 0x8(%rsp)
cmpq %rax, %rdx
jb 0x29b7
movq 0xe0(%rsp), %r12
movq %r12, %rdi
vzeroupper
callq 0x2030
leaq 0x60(%rsp), %r13
movq %rax, %rbx
testl %r12d, %r12d
je 0x2c3e
movl $0x2, %esi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x2140
cmpl $0x0, 0x7c(%rsp)
movq %rbx, 0x8(%rsp)
je 0x2de2
leal (%r12,%r12,2), %eax
xorl %ecx, %ecx
movl $0x0, 0x10(%rsp)
movl %eax, 0x38(%rsp)
movq 0x88(%rsp), %rax
movq %rcx, 0x20(%rsp)
movzbl (%rax,%rcx), %r15d
movq %r12, %rdi
callq 0x2030
movq 0x48(%rsp), %r10
movq %rax, %r14
testl %r12d, %r12d
je 0x2cd3
movl 0x10(%rsp), %ecx
movl %r15d, %eax
xorl %edx, %edx
testl %r15d, %r15d
je 0x2cb9
movq (%r10,%rdx,8), %rdi
xorl %r8d, %r8d
xorl %esi, %esi
leal (%rcx,%r8), %r9d
movzbl (%rdi,%r9), %r9d
shlxl %r8d, %r9d, %r9d
incq %r8
addb %r9b, %sil
cmpq %r8, %rax
jne 0x2c9e
jmp 0x2cbb
xorl %esi, %esi
movzbl (%rbx,%rdx), %edi
shlxl %r15d, %edi, %edi
addb %sil, %dil
movb %dil, (%r14,%rdx)
incq %rdx
cmpq %r12, %rdx
jne 0x2c90
movq %r12, %rdi
callq 0x2030
movq %rax, %rbx
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq %rbx, %rdi
movq %r14, %rdx
movl %r12d, %ecx
callq 0x404d
leal 0x2(%r15), %eax
movq 0x40(%rsp), %rdi
movzbl %al, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x5141
movl $0x1, %eax
movq %rbx, 0x18(%rsp)
shlxl %r15d, %eax, %eax
movzbl %al, %ebx
imull 0x38(%rsp), %ebx
movq %rbx, %rdi
callq 0x2030
movq 0x40(%rsp), %rdi
movl $0x2, %esi
movq %rax, %r13
movq %rbx, %rdx
movq %rax, %rcx
callq 0x521b
movq 0xe0(%rsp), %r12
movq %r12, %rdi
callq 0x2030
movq %rax, %rbx
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movl $0x2, %r9d
movl $0x6, (%rsp)
movq %rbx, %rdi
movq %r14, %rdx
movq %r13, %rcx
movl %r12d, %r8d
callq 0x4192
testl %r12d, %r12d
je 0x2d9c
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x21b0
addl %r15d, 0x10(%rsp)
movq %r14, %rdi
callq 0x2300
movq %rbx, %rdi
callq 0x2300
movq 0x18(%rsp), %rdi
callq 0x2300
movq %r13, %rdi
callq 0x2300
movq 0x20(%rsp), %rcx
movl 0x7c(%rsp), %eax
movq 0x8(%rsp), %rbx
leaq 0x60(%rsp), %r13
incq %rcx
cmpq %rax, %rcx
jb 0x2c60
testl %r12d, %r12d
je 0x2f3c
leaq 0xc0(%rsp), %r15
movl $0xd1b71759, %edx       # imm = 0xD1B71759
xorl %r14d, %r14d
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax,%r14)
je 0x2f30
movl $0x1, %r12d
cmpq $0xa, %r14
jb 0x2e59
movl $0x4, %r12d
movl %r14d, %eax
cmpl $0x63, %eax
jbe 0x2e50
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x2e56
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x2e59
movl %eax, %ecx
imulq %rdx, %rcx
addl $0x4, %r12d
shrq $0x2d, %rcx
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x2e20
addl $-0x3, %r12d
jmp 0x2e59
addl $-0x2, %r12d
jmp 0x2e59
decl %r12d
leaq 0xd0(%rsp), %rax
movl %r12d, %esi
movq %rax, 0xc0(%rsp)
movl $0x2d, %edx
movq %r15, %rdi
callq 0x22d0
movq 0xc0(%rsp), %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0x383c
movl $0x17, %r8d
leaq 0x3416(%rip), %rcx      # 0x62af
movq %r15, %rbx
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2290
movq %r13, 0x50(%rsp)
movq 0xe0(%rsp), %r12
movq %rax, %rcx
addq $0x10, %rcx
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x2ed3
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x2edd
vmovdqu (%rcx), %xmm0
vmovdqu %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x50(%rsp), %rdi
callq 0x317c
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x2f0e
callq 0x2210
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x2f28
callq 0x2210
movl $0xd1b71759, %edx       # imm = 0xD1B71759
movq %rbx, %r15
incq %r14
cmpq %r12, %r14
jne 0x2dfb
testq %rbp, %rbp
je 0x2f49
movq %rbp, %rdi
callq 0x2300
movq 0x48(%rsp), %r14
testl %r12d, %r12d
je 0x2f6b
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2f63
callq 0x2300
incq %rbx
cmpq %rbx, %r12
jne 0x2f55
movq %r14, %rdi
callq 0x2300
movq 0x8(%rsp), %rdi
callq 0x2300
cmpl $0x0, 0x78(%rsp)
je 0x2fb3
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
movq (%rax,%r14,8), %rbx
testq %rbx, %rbx
je 0x2f9d
movq %rbx, %rdi
callq 0x3e6a
movq %rbx, %rdi
callq 0x2210
movl 0x78(%rsp), %eax
incq %r14
cmpq %rax, %r14
jb 0x2f87
jmp 0x2fbb
cmpq $0x0, 0x30(%rsp)
je 0x2fc5
movq 0x30(%rsp), %rdi
callq 0x2300
cmpl $0x0, 0x7c(%rsp)
je 0x2ffb
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
movq (%rax,%r14,8), %rbx
testq %rbx, %rbx
je 0x2fe5
movq %rbx, %rdi
callq 0x3e6a
movq %rbx, %rdi
callq 0x2210
movl 0x7c(%rsp), %eax
incq %r14
cmpq %rax, %r14
jb 0x2fcf
jmp 0x3003
cmpq $0x0, 0x28(%rsp)
je 0x300d
movq 0x28(%rsp), %rdi
callq 0x2300
leaq 0x180(%rsp), %rdi
callq 0x20a0
leaq 0x590(%rsp), %rdi
callq 0x20a0
leaq 0x70(%rsp), %rdi
callq 0x4b24
leaq 0x388(%rsp), %rdi
callq 0x20a0
addq $0x798, %rsp            # imm = 0x798
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3140
jmp 0x3140
jmp 0x305c
movq 0x50(%rsp), %rdi
movq %rax, %rbx
cmpq %r12, %rdi
jne 0x3129
jmp 0x3143
jmp 0x3140
jmp 0x30ba
jmp 0x30ba
leaq 0x120(%rsp), %rdi
jmp 0x308d
leaq 0x150(%rsp), %rdi
movq %rax, %rbx
callq 0x4b24
jmp 0x3150
jmp 0x309c
movq 0x180(%rsp), %rdi
movq %rax, %rbx
cmpq %r15, %rdi
je 0x3150
callq 0x2210
jmp 0x3150
movq %rax, %rbx
jmp 0x3150
jmp 0x30c4
movq %rax, %rbx
jmp 0x315d
jmp 0x30ce
movq %rax, %rbx
jmp 0x3167
movq 0x388(%rsp), %rdi
movq %rax, %rbx
cmpq %r15, %rdi
je 0x3174
callq 0x2210
jmp 0x3174
movq %rax, %rbx
jmp 0x3174
jmp 0x3140
movq 0x50(%rsp), %rdi
movq %rax, %rbx
cmpq %r13, %rdi
je 0x3114
callq 0x2210
jmp 0x3114
jmp 0x3140
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3143
callq 0x2210
jmp 0x3143
jmp 0x3140
jmp 0x3140
jmp 0x3140
jmp 0x3140
jmp 0x3140
jmp 0x3140
jmp 0x3140
jmp 0x3140
movq %rax, %rbx
leaq 0x180(%rsp), %rdi
callq 0x20a0
leaq 0x590(%rsp), %rdi
callq 0x20a0
leaq 0x70(%rsp), %rdi
callq 0x4b24
leaq 0x388(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2400