// File: /workspace/github_cpp_makefile_star2_O3/awbrenn[P]robot-controller/Middleware.cpp
// Function: sendRobotResponseToClient()
void sendRobotResponseToClient() {
    //cout << HTTP_RESPONSE << endl; // test - remove later
    vector<string> fragmented_response;

    /* first remove the header from the HTTP response */
    removeHeaderFromHTTPResponse();

    /* then fragement the response into 1000 Byte chunks */
    if (HTTP_RESPONSE.length() > UDP_PACKET_MAX_SIZE - 12) // subtract 12 for header
        fragmented_response = fragmentHTTPResponse();
    else // only one UDP packet needed
        fragmented_response.push_back(HTTP_RESPONSE);

    /* add the header to the fragments of the response */
    fragmented_response = addHeaderToResponseToClient(fragmented_response);

    // cout << HTTP_RESPONSE.length() << endl;

    // cout << "\n\nNEW MESSASGE:" << endl;

    // for (int i = 0; i < (int)fragmented_response.size(); i++) {
    //     cout << fragmented_response.at(i) << "\n" << endl;
    // }

    for (int i = 0; i < fragmented_response.size(); ++i) {
        cout << fragmented_response.at(i) << "\n" << endl;
        sendto(PROXY_SOCKET, fragmented_response.at(i).data(), fragmented_response.at(i).length(),
               0, (struct sockaddr *) &CLIENT_ADDR, sizeof(CLIENT_ADDR));
    }

    // char * hello_world = "hello world";
    // sendto(PROXY_SOCKET, hello_world, strlen(hello_world), 0, (struct sockaddr *) &CLIENT_ADDR, sizeof(CLIENT_ADDR));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
callq 0x36b2
cmpq $0x3dd, 0x458e(%rip) # imm = 0x3DD
jb 0x2d1b
leaq -0x60(%rbp), %rdi
callq 0x3725
movaps -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
leaq -0x60(%rbp), %rbx
movaps (%rbx), %xmm1
movaps %xmm1, -0x40(%rbp)
movq 0x10(%rbx), %rcx
movq %rcx, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x3ac2
movq %rbx, %rdi
callq 0x3ac2
jmp 0x2d2b
leaq 0x452e(%rip), %rsi      # 0x7250
leaq -0x40(%rbp), %rdi
callq 0x3b30
leaq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3b7c
leaq -0x60(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3800
movaps -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
leaq -0x60(%rbp), %rbx
movaps (%rbx), %xmm1
movaps %xmm1, -0x40(%rbp)
movq 0x10(%rbx), %rcx
movq %rcx, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x3ac2
movq %rbx, %rdi
callq 0x3ac2
leaq -0x78(%rbp), %rdi
callq 0x3ac2
movq -0x40(%rbp), %rax
cmpq %rax, -0x38(%rbp)
je 0x2e58
movl $0x8, %r14d
xorl %ebx, %ebx
leaq 0x2380(%rip), %r15      # 0x512f
leaq 0x4562(%rip), %r12      # 0x7318
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq 0x420a(%rip), %rdi      # 0x6fd0
callq 0x2240
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2240
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %rbx, %rdx
jbe 0x2e70
movl 0x44d4(%rip), %edi      # 0x72f4
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
xorl %ecx, %ecx
movq %r12, %r8
movl $0x10, %r9d
callq 0x2040
incq %rbx
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
addq $0x20, %r14
cmpq %rbx, %rcx
ja 0x2db6
leaq -0x40(%rbp), %rdi
callq 0x3ac2
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2438(%rip), %rdi      # 0x52af
movq %rbx, %rsi
xorl %eax, %eax
callq 0x22b0
jmp 0x2e97
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x3ac2
jmp 0x2e9a
jmp 0x2e97
jmp 0x2e97
jmp 0x2e97
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x3ac2
movq %rbx, %rdi
callq 0x2340