// File: 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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movl %ecx, 0x3c(%rsp)
movq %r8, 0x30(%rsp)
movl 0x3c(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0x68d1
movl $0x8, %edi
callq 0x3150
movq %rax, %rdi
leaq 0x39dc(%rip), %rax      # 0xa29a
movq %rax, (%rdi)
movq 0x6700(%rip), %rsi      # 0xcfc8
xorl %eax, %eax
movl %eax, %edx
callq 0x3440
movq 0x6700(%rip), %rdi      # 0xcfd8
leaq 0x39fb(%rip), %rsi      # 0xa2da
callq 0x32a0
movq %rax, %rdi
movq 0x40(%rsp), %rax
movzbl (%rax), %esi
callq 0x3390
movq %rax, %rdi
movq 0x66c2(%rip), %rsi      # 0xcfc0
callq 0x32f0
movl 0x3c(%rsp), %eax
movl %eax, %edi
callq 0x3030
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x30(%rsp), %rdx
movl 0x3c(%rsp), %ecx
callq 0x62d0
movq 0x66a6(%rip), %rdi      # 0xcfd8
leaq 0x3997(%rip), %rsi      # 0xa2d0
callq 0x32a0
movq %rax, %rdi
movq 0x28(%rsp), %rax
movzbl (%rax), %esi
callq 0x3390
movq %rax, %rdi
movq 0x6668(%rip), %rsi      # 0xcfc0
callq 0x32f0
movq 0x50(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x3c(%rsp), %eax
movl %eax, %edx
shlq $0x0, %rdx
callq 0x84d0
movq 0x40(%rsp), %rax
movzbl (%rax), %eax
imull 0x3c(%rsp), %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3030
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rax
movzbl (%rax), %eax
imull 0x3c(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x0, %rdx
callq 0x8410
movq 0x661c(%rip), %rdi      # 0xcfd8
leaq 0x3923(%rip), %rsi      # 0xa2e6
callq 0x32a0
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl (%rax), %esi
callq 0x3390
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x1(%rax), %esi
callq 0x3390
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x2(%rax), %esi
callq 0x3390
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x3(%rax), %esi
callq 0x3390
movq %rax, %rdi
movq 0x65ab(%rip), %rsi      # 0xcfc0
callq 0x32f0
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0x3c(%rsp), %r8d
movl $0x8, %r9d
movl $0x8, (%rsp)
callq 0x6510
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x6a5f
movq 0x18(%rsp), %rdi
callq 0x3370
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x6a79
movq 0x10(%rsp), %rdi
callq 0x3370
addq $0x58, %rsp
retq
nop