// File: bchu7796[P]p2p-file-sharing/peers.cpp
// Function: client::combine_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
int client::combine_file(std::string file_name, int chunk_number){
    std::ifstream read;
    std::ofstream write(file_name);
    std::string temp_file_name;
    std::string index_string;
    std::stringstream ss;
    char buffer[CHUNK_SIZE];

    for(int i = 0; i < chunk_number; i++){
        ss << i;
        ss >> index_string;
        temp_file_name = file_name + index_string; 
        read.open(temp_file_name);
        read.read(buffer, sizeof(buffer));
        write << buffer;
        std::stringstream().swap(ss);
        read.close();
        remove(temp_file_name.c_str());
    }
    write.close();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xbd0, %rsp            # imm = 0xBD0
movq %rsi, -0xbb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3330
movq -0xbb8(%rbp), %rsi
leaq -0x420(%rbp), %rdi
movl $0x10, %edx
callq 0x34f0
jmp 0x4a93
leaq -0x450(%rbp), %rdi
callq 0x33c0
leaq -0x470(%rbp), %rdi
callq 0x33c0
leaq -0x5f8(%rbp), %rdi
callq 0x3200
jmp 0x4ab9
movl $0x0, -0xa04(%rbp)
movl -0xa04(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4c54
leaq -0x5e8(%rbp), %rdi
movl -0xa04(%rbp), %esi
callq 0x3480
jmp 0x4ae6
leaq -0x5f8(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x3380
jmp 0x4afb
movq -0xbb8(%rbp), %rsi
leaq -0xa28(%rbp), %rdi
leaq -0x470(%rbp), %rdx
callq 0x63f0
jmp 0x4b17
leaq -0x450(%rbp), %rdi
movq %rdi, -0xbc0(%rbp)
leaq -0xa28(%rbp), %rsi
movq %rsi, -0xbc8(%rbp)
callq 0x3350
movq -0xbc8(%rbp), %rdi
callq 0x31d0
movq -0xbc0(%rbp), %rsi
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x3260
jmp 0x4b5e
leaq -0x220(%rbp), %rdi
leaq -0xa00(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x3370
jmp 0x4b78
leaq -0x420(%rbp), %rdi
leaq -0xa00(%rbp), %rsi
callq 0x32d0
jmp 0x4b8d
leaq -0xbb0(%rbp), %rdi
callq 0x3200
jmp 0x4b9b
leaq -0xbb0(%rbp), %rdi
leaq -0x5f8(%rbp), %rsi
callq 0x34d0
jmp 0x4bb0
leaq -0xbb0(%rbp), %rdi
callq 0x3210
leaq -0x220(%rbp), %rdi
callq 0x3070
jmp 0x4bca
leaq -0x450(%rbp), %rdi
callq 0x3120
movq %rax, %rdi
callq 0x34b0
movl -0xa04(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa04(%rbp)
jmp 0x4ac3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x428(%rbp)
movl %eax, -0x42c(%rbp)
jmp 0x4cd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x428(%rbp)
movl %eax, -0x42c(%rbp)
jmp 0x4cb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x428(%rbp)
movl %eax, -0x42c(%rbp)
jmp 0x4ca9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x428(%rbp)
movl %eax, -0x42c(%rbp)
leaq -0xbb0(%rbp), %rdi
callq 0x3210
jmp 0x4ca9
leaq -0x420(%rbp), %rdi
callq 0x33d0
jmp 0x4c62
leaq -0x5f8(%rbp), %rdi
callq 0x3210
leaq -0x470(%rbp), %rdi
callq 0x31d0
leaq -0x450(%rbp), %rdi
callq 0x31d0
leaq -0x420(%rbp), %rdi
callq 0x3400
leaq -0x220(%rbp), %rdi
callq 0x3090
xorl %eax, %eax
addq $0xbd0, %rsp            # imm = 0xBD0
popq %rbp
retq
leaq -0x5f8(%rbp), %rdi
callq 0x3210
leaq -0x470(%rbp), %rdi
callq 0x31d0
leaq -0x450(%rbp), %rdi
callq 0x31d0
leaq -0x420(%rbp), %rdi
callq 0x3400
leaq -0x220(%rbp), %rdi
callq 0x3090
movq -0x428(%rbp), %rdi
callq 0x34a0
nopw %cs:(%rax,%rax)