// File: /workspace/github_cpp_makefile_star2_O1/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 0x44b2
movq %r8, %r15
movl %ecx, %ebx
movq %rdx, %r14
movq 0x4cc7(%rip), %r12      # 0x8fd8
leaq 0x1ff2(%rip), %rsi      # 0x630a
movl $0xb, %edx
movq %r12, %rdi
callq 0x22c0
movzbl (%r14), %esi
movq %r12, %rdi
movq %r12, %r13
callq 0x2160
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
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 0x3f22
leaq 0x1f7e(%rip), %rsi      # 0x6300
movl $0x9, %edx
movq %r13, %rdi
callq 0x22c0
movzbl (%r12), %esi
movq %r13, %rdi
callq 0x2160
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movq 0x8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x541e
movzbl (%r14), %ebp
imull %ebx, %ebp
movq %rbp, %rdi
callq 0x2030
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x536c
leaq 0x1f16(%rip), %rsi      # 0x6316
movl $0xa, %edx
movq 0x4bcc(%rip), %r13      # 0x8fd8
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
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movl $0x8, (%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %ebx, %r8d
movl $0x8, %r9d
callq 0x4055
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
leaq 0x1e07(%rip), %rcx      # 0x62ca
movq %rcx, (%rax)
movq 0x4af3(%rip), %rsi      # 0x8fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x23d0