// File: awbrenn[P]robot-controller/Middleware.cpp
// Function: addHeaderToResponseToClient(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>)
vector<string> addHeaderToResponseToClient(vector<string> fragmented_response) {
    uint32_t number_of_messages = fragmented_response.size();
    uint32_t sequence_number = 0;
    string body;
    int i;

    number_of_messages = fragmented_response.size();

    /* add header to each of the fragmented responses */
    for (i = 0; i < (int) number_of_messages; i++) {
        sequence_number = i;
        int body_length = fragmented_response[i].length();
        cout << "Body length: " << body_length << endl;
        char * body = (char *) calloc(body_length + 12, sizeof(char));
        memcpy(body, &REQUEST_ID, 4);
        memcpy(body + 4, &number_of_messages, 4);
        memcpy(body + 8, &sequence_number, 4);
        memcpy(body + 12, fragmented_response[i].data(), body_length);
        fragmented_response.at(i).assign(body, body_length + 12);
    }

    return fragmented_response;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rsi, -0x60(%rbp)
movq %rdi, %rax
movq -0x60(%rbp), %rdi
movq %rax, -0x70(%rbp)
movq %rax, %rcx
movq %rcx, -0x68(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
callq 0x5140
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x33e0
movq -0x60(%rbp), %rdi
callq 0x5140
movl %eax, -0x14(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4d61
movq -0x60(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, -0x18(%rbp)
movslq -0x3c(%rbp), %rsi
callq 0x51a0
movq %rax, %rdi
callq 0x3420
movl %eax, -0x40(%rbp)
movq 0x536b(%rip), %rdi      # 0x9fd0
leaq 0x242f(%rip), %rsi      # 0x709b
callq 0x32b0
movq %rax, -0x78(%rbp)
jmp 0x4c77
movq -0x78(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x3480
movq %rax, -0x80(%rbp)
jmp 0x4c89
movq -0x80(%rbp), %rdi
movq 0x5324(%rip), %rsi      # 0x9fb8
callq 0x3300
jmp 0x4c9b
movl -0x40(%rbp), %eax
addl $0xc, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x31c0
movq -0x60(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x55dc(%rip), %ecx      # 0xa29c
movl %ecx, (%rax)
movq -0x58(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, 0x4(%rax)
movq -0x58(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x90(%rbp)
movslq -0x3c(%rbp), %rsi
callq 0x51a0
movq %rax, %rdi
callq 0x3190
movq -0x90(%rbp), %rdi
movq %rax, %rsi
movslq -0x40(%rbp), %rdx
callq 0x3240
movq -0x60(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x5160
movq %rax, -0x88(%rbp)
jmp 0x4d1f
movq -0x88(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x40(%rbp), %eax
addl $0xc, %eax
movslq %eax, %rdx
callq 0x33c0
jmp 0x4d3a
jmp 0x4d3c
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4c34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3518
jmp 0x4d84
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdi
callq 0x51c0
leaq -0x38(%rbp), %rdi
callq 0x3518
movq -0x68(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3490
nopl (%rax)