// File: maclellant[P]ReliableGoBackN/server.cpp
// Function: parse_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::vector<Packet, std::allocator<Packet>>&, std::vector<Timer, std::allocator<Timer>>&)
void parse_file(std::string& filename, vector<Packet>& packets, vector<Timer>& timers)
{
    FILE *infile;
    infile = fopen(filename.c_str(), "rb");
    if (infile == NULL)
    {
        std::cerr << "Error: Could not open file: " << filename << std::endl;
        return;
    }

    int current_seq = 0;
    size_t numread = 0;

    while(!feof(infile))
    {
        char data[PACKET_SIZE - HEADER_SIZE];
        bzero(data, PACKET_SIZE - HEADER_SIZE);
        numread = fread(data, 1, PACKET_SIZE - HEADER_SIZE, infile);
        if (numread != PACKET_SIZE - HEADER_SIZE && !feof(infile))
        {
            fclose(infile);
            std::cerr << "Error: Could not properly read file: " << filename << std::endl;
            exit(EXIT_FAILURE);
        }

        Packet packet = Packet(data, numread, current_seq, TRN);
        Timer timer = Timer();
        packets.push_back(packet);
        timers.push_back(timer);
        current_seq = (current_seq + 1) % SEQ_NUM;
    }

    Packet final_packet = Packet(current_seq, TRN);
    Timer final_timer = Timer();
    packets.push_back(final_packet);
    timers.push_back(final_timer);

    fclose(infile);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x650, %rsp            # imm = 0x650
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20f0
movq %rax, %rdi
leaq 0x3c40(%rip), %rsi      # 0x712a
callq 0x22b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x352d
movq 0x7aef(%rip), %rdi      # 0xaff0
leaq 0x3c25(%rip), %rsi      # 0x712d
callq 0x2220
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x2200
movq %rax, %rdi
movq 0x7a95(%rip), %rsi      # 0xafb8
callq 0x2260
jmp 0x36a5
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2320
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3556
jmp 0x3652
leaq -0x230(%rbp), %rdi
xorl %esi, %esi
movl $0x1fa, %edx            # imm = 0x1FA
callq 0x2130
leaq -0x230(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x1, %esi
movl $0x1fa, %edx            # imm = 0x1FA
callq 0x2300
movq %rax, -0x30(%rbp)
cmpq $0x1fa, -0x30(%rbp)     # imm = 0x1FA
je 0x35e0
movq -0x20(%rbp), %rdi
callq 0x2320
cmpl $0x0, %eax
jne 0x35e0
movq -0x20(%rbp), %rdi
callq 0x2230
movq 0x7a41(%rip), %rdi      # 0xaff0
leaq 0x3b94(%rip), %rsi      # 0x714a
callq 0x2220
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x2200
movq %rax, %rdi
movq 0x79e7(%rip), %rsi      # 0xafb8
callq 0x2260
movl $0x1, %edi
callq 0x22c0
leaq -0x230(%rbp), %rsi
movq -0x30(%rbp), %rax
movw %ax, %cx
movl -0x24(%rbp), %eax
leaq -0x430(%rbp), %rdi
movl $0x3, %r8d
movzwl %cx, %edx
movzbl %al, %ecx
callq 0x6250
leaq -0x440(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2130
movq -0x10(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x3e60
movq -0x18(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x3ed0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %edx, -0x24(%rbp)
jmp 0x353c
movl -0x24(%rbp), %eax
leaq -0x640(%rbp), %rdi
movl $0x3, %edx
movzbl %al, %esi
callq 0x6180
leaq -0x650(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2130
movq -0x10(%rbp), %rdi
leaq -0x640(%rbp), %rsi
callq 0x3e60
movq -0x18(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x3ed0
movq -0x20(%rbp), %rdi
callq 0x2230
addq $0x650, %rsp            # imm = 0x650
popq %rbp
retq
nop