// File: /workspace/github_cpp_makefile_star2_O1/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 0x36be
cmpq $0x3dd, 0x458e(%rip) # imm = 0x3DD
jb 0x2d21
leaq -0x70(%rbp), %rdi
callq 0x3731
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
leaq -0x70(%rbp), %rbx
movups (%rbx), %xmm1
movaps %xmm1, -0x40(%rbp)
movq 0x10(%rbx), %rcx
movq %rcx, -0x30(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x3ab4
movq %rbx, %rdi
callq 0x3ab4
jmp 0x2d31
leaq 0x4528(%rip), %rsi      # 0x7250
leaq -0x40(%rbp), %rdi
callq 0x3b1e
leaq -0x58(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3b6a
leaq -0x70(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x380c
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps -0x40(%rbp), %xmm0
movq -0x30(%rbp), %rax
leaq -0x70(%rbp), %rbx
movups (%rbx), %xmm1
movaps %xmm1, -0x40(%rbp)
movq 0x10(%rbx), %rcx
movq %rcx, -0x30(%rbp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%rbx)
movq $0x0, 0x10(%rbx)
callq 0x3ab4
movq %rbx, %rdi
callq 0x3ab4
leaq -0x58(%rbp), %rdi
callq 0x3ab4
movq -0x40(%rbp), %rax
cmpq %rax, -0x38(%rbp)
je 0x2e64
movl $0x8, %r14d
xorl %ebx, %ebx
leaq 0x2374(%rip), %r15      # 0x512f
leaq 0x4556(%rip), %r12      # 0x7318
movq -0x8(%rax,%r14), %rsi
movq (%rax,%r14), %rdx
movq 0x41fe(%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 0x2e7c
movl 0x44c8(%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 0x2dc2
leaq -0x40(%rbp), %rdi
callq 0x3ab4
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x242c(%rip), %rdi      # 0x52af
movq %rbx, %rsi
xorl %eax, %eax
callq 0x22b0
jmp 0x2ea3
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x3ab4
jmp 0x2ea6
jmp 0x2ea3
jmp 0x2ea3
jmp 0x2ea3
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x3ab4
movq %rbx, %rdi
callq 0x2340