// File: /workspace/github_cpp_makefile_star2_O2/awbrenn[P]robot-controller/Client.cpp
// Function: recieveAckFromMiddleware()
void recieveAckFromMiddleware() 
{
  uint32_t *id = (uint32_t *) malloc(sizeof(uint32_t));
  uint32_t *total_messages = (uint32_t *) malloc(sizeof(uint32_t));
  uint32_t *sequence_number = (uint32_t *) malloc(sizeof(uint32_t));
  vector<string> fragmented_response;
  int recvMsgSize;

  cout << "\nGOT HERE\n" << endl;

  clntAddrLen = sizeof(clntAddr);

  do {
    string response_chunk;

    if ((recvMsgSize = recvfrom(sock, recvBuffer, UDP_PACKET_MAX_SIZE, 0, 
       (struct sockaddr *) &clntAddr, &clntAddrLen )) < 0 )
         cout << ("error on recvFrom") << endl;

    //Check for timeout
    if (recvMsgSize == -1) 
       if (errno == EINTR)
       {
          cout << "Timeout occured. Program Ending." << endl;
          exit(0);
       }

    recvBuffer[recvMsgSize] = '\0';

    cout << "\nmessageLen: " << recvMsgSize << endl;
    memcpy(id, recvBuffer, 4);
    memcpy(total_messages, recvBuffer + 4, 4);
    memcpy(sequence_number, recvBuffer + 8, 4);

    cout << "\nMessage ID: " << *id << endl;
    cout << "\nTotal Messages: " << *total_messages << endl;
    cout << "\nSequence Number: " << *sequence_number << endl;

    response_chunk.assign(recvBuffer + 12, recvMsgSize - 11);
    fragmented_response.push_back(response_chunk);
    //printf("%s\n\n", recvBuffer + 12);
 } while (*sequence_number < (*total_messages - 1));

  alarm(0);

  PROXY_RESPONSE = "";

  for (int i = 0; i < (int)fragmented_response.size(); i++) {
        PROXY_RESPONSE += fragmented_response.at(i);
  }


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
andq $0x0, -0x30(%rbp)
movq 0x322f(%rip), %rdi      # 0x5fd0
leaq 0x13c5(%rip), %rsi      # 0x416d
callq 0x2190
movq %rax, %rdi
callq 0x20d0
movl $0x10, 0x3489(%rip)     # 0x6248
movq 0x320a(%rip), %r12      # 0x5fd0
leaq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
andq $0x0, -0x58(%rbp)
movb $0x0, -0x50(%rbp)
movl 0x343b(%rip), %edi      # 0x6218
movl $0x3e8, %edx            # imm = 0x3E8
leaq 0x3477(%rip), %rsi      # 0x6260
xorl %ecx, %ecx
leaq 0x343a(%rip), %r8       # 0x622c
leaq 0x344f(%rip), %r9       # 0x6248
callq 0x2130
movq %rax, %r14
testl %r14d, %r14d
jns 0x2e31
movq %r12, %rdi
leaq 0x1368(%rip), %rsi      # 0x4178
callq 0x2190
movq %rax, %rdi
callq 0x20d0
cmpl $-0x1, %r14d
jne 0x2e31
callq 0x2030
cmpl $0x4, (%rax)
je 0x2f92
movslq %r14d, %rax
leaq 0x3425(%rip), %rcx      # 0x6260
movb $0x0, (%rax,%rcx)
movq %r12, %rdi
leaq 0x1362(%rip), %rsi      # 0x41ab
callq 0x2190
movq %rax, %rdi
movl %r14d, %esi
callq 0x22b0
movq %rax, %rdi
callq 0x20d0
movl 0x33f8(%rip), %r15d     # 0x6260
movl 0x33f5(%rip), %r13d     # 0x6264
movl 0x33f3(%rip), %ebx      # 0x6268
movq %r12, %rdi
leaq 0x133a(%rip), %rsi      # 0x41b9
callq 0x2190
movq %rax, %rdi
movq %r15, %rsi
callq 0x2110
movq %rax, %rdi
callq 0x20d0
movq %r12, %rdi
leaq 0x1326(%rip), %rsi      # 0x41c7
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x2110
movq %rax, %rdi
callq 0x20d0
movq %r12, %rdi
leaq 0x1316(%rip), %rsi      # 0x41d9
callq 0x2190
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2110
movq %rax, %rdi
callq 0x20d0
shlq $0x20, %r14
movabsq $-0xb00000000, %rax     # imm = 0xFFFFFFF500000000
addq %rax, %r14
sarq $0x20, %r14
leaq -0x60(%rbp), %rdi
leaq 0x3371(%rip), %rsi      # 0x626c
movq %r14, %rdx
callq 0x2220
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x32fc
leaq -0x60(%rbp), %rdi
callq 0x2328
decl %r13d
cmpl %r13d, %ebx
jb 0x2dc6
xorl %edi, %edi
callq 0x22e0
leaq 0x3295(%rip), %rdi      # 0x61c8
leaq 0x13bf(%rip), %rsi      # 0x42f9
callq 0x22f0
xorl %ebx, %ebx
leaq -0x40(%rbp), %r14
leaq 0x327c(%rip), %r15      # 0x61c8
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
shrq $0x5, %rax
cltq
cmpq %rax, %rbx
jge 0x2f7a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32b2
movq %r15, %rdi
movq %rax, %rsi
callq 0x2300
incq %rbx
jmp 0x2f4c
leaq -0x40(%rbp), %rdi
callq 0x3286
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3037(%rip), %rdi      # 0x5fd0
leaq 0x11ea(%rip), %rsi      # 0x418a
callq 0x2190
movq %rax, %rdi
callq 0x20d0
xorl %edi, %edi
callq 0x21e0
jmp 0x2fb8
jmp 0x2fbd
movq %rax, %rbx
jmp 0x2fc9
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2328
leaq -0x40(%rbp), %rdi
callq 0x3286
movq %rbx, %rdi
callq 0x22c0