// File: bchu7796[P]p2p-file-sharing/peers.cpp
// Function: client::read_log(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<chunk, std::allocator<chunk>>&, int)
int client::read_log(std::string file_name, std::vector<chunk>& chunks, int file_length){
    std::ifstream log;
    std::ofstream download_file;
    char buffer[10];
    std::string log_line;
    std::vector<std::string> elements;

    
    if(!file_exist(file_name + ".log")){
        /*
        download_file.open(file_name);
        for(int i=0; i < file_length; i++){
            download_file << "0";
        }
        download_file.close();
        */
        return 0;
    }
    

    log.open((file_name + ".log").c_str());
    
    while(log.getline(buffer, 10)){
        log_line = buffer;
        std::stringstream s(log_line);
        int index = 0;
        s >> index;
        chunks[index].is_possessed = true;
        std::stringstream().swap(s);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x810, %rsp            # imm = 0x810
movq %rsi, -0x7f0(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x7e8(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x3330
leaq -0x430(%rbp), %rdi
callq 0x3470
jmp 0x4236
leaq -0x468(%rbp), %rdi
callq 0x33c0
leaq -0x480(%rbp), %rdi
callq 0x61f0
movq -0x7f0(%rbp), %rsi
leaq 0x8e2a(%rip), %rdx      # 0xd086
leaq -0x4a0(%rbp), %rdi
callq 0x6170
jmp 0x426a
movq -0x7e8(%rbp), %rdi
leaq -0x4a0(%rbp), %rsi
callq 0x4000
xorb $-0x1, %al
movb %al, -0x7f1(%rbp)
leaq -0x4a0(%rbp), %rdi
callq 0x31d0
movb -0x7f1(%rbp), %al
testb $0x1, %al
jne 0x429d
jmp 0x42e1
movl $0x0, -0x4(%rbp)
movl $0x1, -0x4a4(%rbp)
jmp 0x44a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x438(%rbp)
movl %eax, -0x43c(%rbp)
jmp 0x4507
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x438(%rbp)
movl %eax, -0x43c(%rbp)
jmp 0x44e3
movq -0x7f0(%rbp), %rsi
leaq 0x8d97(%rip), %rdx      # 0xd086
leaq -0x4c8(%rbp), %rdi
callq 0x6170
jmp 0x42fd
leaq -0x4c8(%rbp), %rdi
callq 0x3120
movq %rax, %rsi
leaq -0x230(%rbp), %rdi
movl $0x8, %edx
callq 0x31e0
jmp 0x431f
leaq -0x4c8(%rbp), %rdi
callq 0x31d0
leaq -0x230(%rbp), %rdi
leaq -0x446(%rbp), %rsi
movl $0xa, %edx
callq 0x30d0
movq %rax, -0x800(%rbp)
jmp 0x434c
movq -0x800(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3360
movb %al, -0x801(%rbp)
jmp 0x436a
movb -0x801(%rbp), %al
testb $0x1, %al
jne 0x4379
jmp 0x4496
leaq -0x468(%rbp), %rdi
leaq -0x446(%rbp), %rsi
callq 0x33b0
jmp 0x438e
movl $0x10, %edi
movl $0x8, %esi
callq 0x6210
movl %eax, -0x808(%rbp)
jmp 0x43a5
movl -0x808(%rbp), %edx
leaq -0x650(%rbp), %rdi
leaq -0x468(%rbp), %rsi
callq 0x3420
jmp 0x43c0
movl $0x0, -0x654(%rbp)
leaq -0x650(%rbp), %rdi
leaq -0x654(%rbp), %rsi
callq 0x31c0
jmp 0x43df
movq -0x20(%rbp), %rdi
movslq -0x654(%rbp), %rsi
callq 0x6020
movb $0x1, 0x4(%rax)
leaq -0x7e0(%rbp), %rdi
callq 0x3200
jmp 0x4401
leaq -0x7e0(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x34d0
jmp 0x4416
leaq -0x7e0(%rbp), %rdi
callq 0x3210
leaq -0x650(%rbp), %rdi
callq 0x3210
jmp 0x432b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x438(%rbp)
movl %eax, -0x43c(%rbp)
leaq -0x4c8(%rbp), %rdi
callq 0x31d0
jmp 0x44e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x438(%rbp)
movl %eax, -0x43c(%rbp)
jmp 0x4488
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x438(%rbp)
movl %eax, -0x43c(%rbp)
leaq -0x7e0(%rbp), %rdi
callq 0x3210
leaq -0x650(%rbp), %rdi
callq 0x3210
jmp 0x44e3
movl $0x0, -0x4(%rbp)
movl $0x1, -0x4a4(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x6230
leaq -0x468(%rbp), %rdi
callq 0x31d0
leaq -0x430(%rbp), %rdi
callq 0x3400
leaq -0x230(%rbp), %rdi
callq 0x3090
movl -0x4(%rbp), %eax
addq $0x810, %rsp            # imm = 0x810
popq %rbp
retq
leaq -0x480(%rbp), %rdi
callq 0x6230
leaq -0x468(%rbp), %rdi
callq 0x31d0
leaq -0x430(%rbp), %rdi
callq 0x3400
leaq -0x230(%rbp), %rdi
callq 0x3090
movq -0x438(%rbp), %rdi
callq 0x34a0
nop