// File: /workspace/github_cpp_makefile_star2_O3/jBlinden[P]private-codis/protocol.cpp
// Function: OTReceiverProtocol(CSocket*, unsigned char*, ReceiverOTCorrelation const&, unsigned int, unsigned char const*)
void OTReceiverProtocol(CSocket *socket, uint8_t *outputs, const ReceiverOTCorrelation &corr,
                        uint32_t nOTs, const uint8_t *choiceBits)
{
  if (nOTs > corr.N)
  {
    throw "insufficient number of of OT correlations";
  }

  cout << "Value has: " << (uint32_t)corr.K << endl;

  uint8_t *clientMsg = new uint8_t[nOTs];
  ConstructOTReceiverMsg(clientMsg, corr, choiceBits, nOTs);

  cout << "Sending: " << (uint32_t) clientMsg[0] << endl;

  socket->SendLarge(clientMsg, nOTs * sizeof(uint8_t));

  uint8_t *serverMsg = new uint8_t[corr.K * nOTs];
  socket->ReceiveLarge((uint8_t *)serverMsg, corr.K * nOTs * sizeof(uint8_t));

  cout << "Recieved: " << (uint32_t) serverMsg[0] << (uint32_t)serverMsg[1] << (uint32_t)serverMsg[2] <<(uint32_t) serverMsg[3] << endl;

  RecoverReceiverMsg(outputs, corr, clientMsg, serverMsg, nOTs, 8, 8);

  delete[] clientMsg;
  delete[] serverMsg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
cmpl %ecx, 0x4(%rdx)
jb 0x45ee
movq 0x4b93(%rip), %r12      # 0x8fd8
movq %rdx, %r14
leaq 0x212b(%rip), %rsi      # 0x657a
movl $0xb, %edx
movq %r8, %r15
movl %ecx, %ebx
movq %r12, %rdi
callq 0x22c0
movzbl (%r14), %esi
movq %r12, %rdi
movq %r12, %r13
callq 0x2160
movq %rax, %r12
movq (%rax), %rax
movl $0xa, %esi
movq -0x18(%rax), %rdi
addq %r12, %rdi
callq 0x2230
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movl %ebx, %ebp
movq %rbp, %rdi
callq 0x2030
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x404d
leaq 0x20b2(%rip), %rsi      # 0x6570
movl $0x9, %edx
movq %r13, %rdi
callq 0x22c0
movzbl (%r12), %esi
movq %r13, %rdi
callq 0x2160
movq %rax, %r15
movq (%rax), %rax
movl $0xa, %esi
movq -0x18(%rax), %rdi
addq %r15, %rdi
callq 0x2230
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0x8(%rsp), %r13
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rdi
callq 0x556a
movzbl (%r14), %ebp
imull %ebx, %ebp
movq %rbp, %rdi
callq 0x2030
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x54b8
movq 0x4a9c(%rip), %r13      # 0x8fd8
leaq 0x2043(%rip), %rsi      # 0x6586
movl $0xa, %edx
movq %r13, %rdi
callq 0x22c0
movzbl (%r15), %esi
movq %r13, %rdi
callq 0x2160
movzbl 0x1(%r15), %esi
movq %rax, %rdi
callq 0x2160
movzbl 0x2(%r15), %esi
movq %rax, %rdi
callq 0x2160
movzbl 0x3(%r15), %esi
movq %rax, %rdi
callq 0x2160
movq %rax, %r13
movq (%rax), %rax
movl $0xa, %esi
movq -0x18(%rax), %rdi
addq %r13, %rdi
callq 0x2230
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movl $0x8, (%rsp)
movl $0x8, %r9d
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %ebx, %r8d
movq 0x10(%rsp), %rdi
callq 0x4192
movq %r12, %rdi
callq 0x2300
movq %r15, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2300
movl $0x8, %edi
callq 0x2120
movq 0x49c1(%rip), %rsi      # 0x8fc0
leaq 0x1f34(%rip), %rcx      # 0x653a
movq %rax, %rdi
xorl %edx, %edx
movq %rcx, (%rax)
callq 0x23d0