// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb78, %rsp            # imm = 0xB78
movl %edx, 0xc(%rsp)
movq %rsi, %rbx
leaq 0x568(%rsp), %rdi
callq 0x3320
leaq 0x368(%rsp), %rdi
movq %rbx, 0x30(%rsp)
movq %rbx, %rsi
movl $0x10, %edx
callq 0x34f0
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x48(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x58(%rsp), %rdi
callq 0x31e0
cmpl $0x0, 0xc(%rsp)
jle 0x4ac1
xorl %ebp, %ebp
leaq 0x38(%rsp), %r15
leaq 0x1e0(%rsp), %r12
leaq 0x10(%rsp), %rbx
leaq 0x568(%rsp), %r14
leaq 0x770(%rsp), %r13
leaq 0x68(%rsp), %rdi
movl %ebp, %esi
callq 0x3460
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x3370
movq %r12, %rdi
movq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0x5dac
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3350
movq 0x1e0(%rsp), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0x4a37
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x3300
movq %r14, %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x3270
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r13, %rsi
callq 0x3360
movq %r13, %rdi
callq 0x3120
leaq 0x368(%rsp), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x3330
movq %r12, %rdi
callq 0x31e0
movq %r12, %rdi
leaq 0x58(%rsp), %rsi
callq 0x34c0
movq %r12, %rdi
movq 0x6517(%rip), %rsi      # 0xafa8
callq 0x3200
leaq 0x260(%rsp), %rdi
callq 0x30f0
movq %r14, %rdi
callq 0x3060
movq 0x10(%rsp), %rdi
callq 0x34a0
incl %ebp
cmpl %ebp, 0xc(%rsp)
jne 0x49de
leaq 0x368(%rsp), %rdi
callq 0x3390
movq 0x64d3(%rip), %rsi      # 0xafa8
leaq 0x58(%rsp), %rdi
callq 0x3200
leaq 0xd8(%rsp), %rdi
callq 0x30f0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x4b08
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4b24
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x6495(%rip), %rax      # 0xafc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x370(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x368(%rsp,%rcx)
callq 0x3260
leaq 0x460(%rsp), %rdi
callq 0x30f0
leaq 0x568(%rsp), %rdi
callq 0x3080
xorl %eax, %eax
addq $0xb78, %rsp            # imm = 0xB78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4bb6
movq %rax, %rbx
jmp 0x4bd7
movq %rax, %rbx
jmp 0x4c1c
jmp 0x4bb6
jmp 0x4bb6
movq %rax, %rbx
movq 0x640e(%rip), %rsi      # 0xafa8
leaq 0x1e0(%rsp), %rdi
callq 0x3200
leaq 0x260(%rsp), %rdi
callq 0x30f0
jmp 0x4bb9
movq %rax, %rbx
movq 0x63e8(%rip), %rsi      # 0xafa8
leaq 0x58(%rsp), %rdi
callq 0x3200
leaq 0xd8(%rsp), %rdi
callq 0x30f0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x4bf3
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3300
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4c0f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3300
leaq 0x368(%rsp), %rdi
callq 0x33d0
leaq 0x568(%rsp), %rdi
callq 0x3080
movq %rbx, %rdi
callq 0x3480
nop