// File: bchu7796[P]p2p-file-sharing/server.cpp
// Function: server::location_reply(int)
int server::location_reply(int process_fd){
    std::string file_name;
    recv(process_fd, &file_name, sizeof(file_name), 0);
    int i;
    for(i = 0; i < files.size(); i++){
        if(files[i].file_name == file_name){
            uint16_t number_of_address = files[i].peers.size();
            send(process_fd, &number_of_address, sizeof(number_of_address), 0);
            send(process_fd, &files[i].file_length, sizeof(files[i].file_length), 0);
            for(int j=0; j<number_of_address; j++){
                send(process_fd, &files[i].peers[j].address, sizeof(files[i].peers[j].address), 0);
                send(process_fd, &files[i].peers[j].port, sizeof(files[i].peers[j].port), 0);
                uint16_t number_of_chunks = files[i].peers[j].chunks.size();
                send(process_fd, &number_of_chunks, sizeof(number_of_chunks), 0);
                for(int k = 0; k < number_of_chunks; k++){
                    send(process_fd, &files[i].peers[j].chunks[k], sizeof(files[i].peers[j].chunks[k]), 0);
                }
            }
        }
    }
    if( i == files.size()){
        uint16_t number_of_address = 0;
        send(process_fd, &number_of_address, sizeof(number_of_address), 0);
    }
    close(process_fd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x60(%rbp)
callq 0x2300
movq -0x60(%rbp), %rsi
movl -0xc(%rbp), %edi
movl $0x20, %edx
xorl %ecx, %ecx
callq 0x20a0
jmp 0x2c14
movl $0x0, -0x40(%rbp)
movslq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq 0xd5e6(%rip), %rdi      # 0x10210
callq 0x3cc0
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jae 0x2e3c
movslq -0x40(%rbp), %rsi
leaq 0xd5c6(%rip), %rdi      # 0x10210
callq 0x3ce0
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x3d00
testb $0x1, %al
jne 0x2c64
jmp 0x2e2c
movslq -0x40(%rbp), %rsi
leaq 0xd5a1(%rip), %rdi      # 0x10210
callq 0x3ce0
movq %rax, %rdi
addq $0x28, %rdi
callq 0x3d90
movw %ax, -0x42(%rbp)
movl -0xc(%rbp), %edi
leaq -0x42(%rbp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2c99
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
movslq -0x40(%rbp), %rsi
leaq 0xd566(%rip), %rdi      # 0x10210
callq 0x3ce0
movl -0x6c(%rbp), %edi
movq %rax, %rsi
addq $0x20, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2cc7
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movzwl -0x42(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2e2a
movl -0xc(%rbp), %eax
movl %eax, -0x70(%rbp)
movslq -0x40(%rbp), %rsi
leaq 0xd522(%rip), %rdi      # 0x10210
callq 0x3ce0
movq %rax, %rdi
addq $0x28, %rdi
movslq -0x48(%rbp), %rsi
callq 0x3db0
movl -0x70(%rbp), %edi
movq %rax, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2d17
movl -0xc(%rbp), %eax
movl %eax, -0x74(%rbp)
movslq -0x40(%rbp), %rsi
leaq 0xd4e8(%rip), %rdi      # 0x10210
callq 0x3ce0
movq %rax, %rdi
addq $0x28, %rdi
movslq -0x48(%rbp), %rsi
callq 0x3db0
movl -0x74(%rbp), %edi
movq %rax, %rsi
addq $0x4, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2d55
movslq -0x40(%rbp), %rsi
leaq 0xd4b0(%rip), %rdi      # 0x10210
callq 0x3ce0
movq %rax, %rdi
addq $0x28, %rdi
movslq -0x48(%rbp), %rsi
callq 0x3db0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x3dd0
movw %ax, -0x4a(%rbp)
movl -0xc(%rbp), %edi
leaq -0x4a(%rbp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2d9a
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movzwl -0x4a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2e1a
movl -0xc(%rbp), %eax
movl %eax, -0x78(%rbp)
movslq -0x40(%rbp), %rsi
leaq 0xd453(%rip), %rdi      # 0x10210
callq 0x3ce0
movq %rax, %rdi
addq $0x28, %rdi
movslq -0x48(%rbp), %rsi
callq 0x3db0
movq %rax, %rdi
addq $0x8, %rdi
movslq -0x50(%rbp), %rsi
callq 0x3df0
movl -0x78(%rbp), %edi
movq %rax, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2df6
jmp 0x2df8
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2da1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2160
jmp 0x2e97
jmp 0x2e1c
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2cce
jmp 0x2e2c
jmp 0x2e2e
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2c1b
movslq -0x40(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq 0xd3c5(%rip), %rdi      # 0x10210
callq 0x3cc0
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jne 0x2e79
movw $0x0, -0x52(%rbp)
movl -0xc(%rbp), %edi
leaq -0x52(%rbp), %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x2120
jmp 0x2e77
jmp 0x2e79
movl -0xc(%rbp), %edi
callq 0x23b0
jmp 0x2e83
leaq -0x30(%rbp), %rdi
callq 0x2160
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2380