// File: /workspace/github_cpp_makefile_star2_O1/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, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq 0x3d1e(%rip), %rbx      # 0x6fd0
leaq 0x1eb4(%rip), %rsi      # 0x516d
movl $0xa, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x3cec(%rip), %rbx      # 0x6fd0
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x10, 0x3f4a(%rip)     # 0x7248
leaq -0x38(%rbp), %r15
movq %r15, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movl 0x3f00(%rip), %edi      # 0x7218
movl $0x3e8, %edx            # imm = 0x3E8
leaq 0x3f3c(%rip), %rsi      # 0x7260
xorl %ecx, %ecx
leaq 0x3eff(%rip), %r8       # 0x722c
leaq 0x3f14(%rip), %r9       # 0x7248
callq 0x2160
movq %rax, %r15
testl %r15d, %r15d
jns 0x337c
movl $0x11, %edx
movq %rbx, %rdi
leaq 0x1e28(%rip), %rsi      # 0x5178
callq 0x21f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
cmpl $-0x1, %r15d
jne 0x3390
callq 0x2040
cmpl $0x4, (%rax)
je 0x35e3
movslq %r15d, %rax
leaq 0x3ec6(%rip), %rcx      # 0x7260
movb $0x0, (%rax,%rcx)
movl $0xd, %edx
movq %rbx, %rdi
leaq 0x1dfe(%rip), %rsi      # 0x51ab
callq 0x21f0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x22d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl 0x3e72(%rip), %r12d     # 0x7260
movl 0x3e6f(%rip), %r13d     # 0x7264
movl 0x3e6c(%rip), %r14d     # 0x7268
movl $0xd, %edx
movq %rbx, %rdi
leaq 0x1dae(%rip), %rsi      # 0x51b9
callq 0x21f0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2130
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x11, %edx
movq %rbx, %rdi
leaq 0x1d73(%rip), %rsi      # 0x51c7
callq 0x21f0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2130
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0x12, %edx
movq %rbx, %rdi
leaq 0x1d3c(%rip), %rsi      # 0x51d9
callq 0x21f0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2130
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
shlq $0x20, %r15
movabsq $-0xb00000000, %rax     # imm = 0xFFFFFFF500000000
addq %rax, %r15
sarq $0x20, %r15
movq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
leaq 0x3d6f(%rip), %rcx      # 0x726c
movq %r15, %r8
callq 0x2290
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x3ac8
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %r15
cmpq %r15, %rdi
je 0x352b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
decl %r13d
cmpl %r13d, %r14d
jb 0x3302
xorl %edi, %edi
callq 0x2310
movq 0x3c8b(%rip), %rdx      # 0x71d0
leaq 0x3c7c(%rip), %rdi      # 0x71c8
leaq 0x1da6(%rip), %rcx      # 0x52f9
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x2290
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
testl %edx, %edx
jle 0x35ba
movl $0x8, %r15d
xorl %ebx, %ebx
leaq 0x3c49(%rip), %r14      # 0x71c8
cmpq %rbx, %rdx
jbe 0x35d2
movq -0x8(%rax,%r15), %rsi
movq (%rax,%r15), %rdx
movq %r14, %rdi
callq 0x20a0
incq %rbx
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x5, %rdx
shrq $0x5, %rcx
movslq %ecx, %rcx
addq $0x20, %r15
cmpq %rcx, %rbx
jl 0x357f
leaq -0x60(%rbp), %rdi
callq 0x3a5e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c3d(%rip), %rdi      # 0x5216
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2270
movq 0x39e6(%rip), %rdi      # 0x6fd0
leaq 0x1b99(%rip), %rsi      # 0x518a
movl $0x20, %edx
callq 0x21f0
movq 0x39ce(%rip), %rdi      # 0x6fd0
callq 0x20f0
xorl %edi, %edi
callq 0x2210
jmp 0x3614
jmp 0x3619
jmp 0x3614
movq %rax, %rbx
jmp 0x3635
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3635
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
leaq -0x60(%rbp), %rdi
callq 0x3a5e
movq %rbx, %rdi
callq 0x22f0