// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdx, %r14
movq %rsi, -0x30(%rbp)
movq %rdi, %r12
movq (%rdi), %rdi
leaq 0x10af(%rip), %rsi      # 0x4146
callq 0x2200
testq %rax, %rax
je 0x320e
movq %rax, %rbx
movq %r12, -0x38(%rbp)
movq %rax, %rdi
callq 0x2240
xorl %r13d, %r13d
testl %eax, %eax
jne 0x31bf
leaq -0x250(%rbp), %r12
movq %r14, -0x40(%rbp)
movl $0x1fa, %edx            # imm = 0x1FA
movq %r12, %rdi
xorl %esi, %esi
callq 0x20f0
movl $0x1, %esi
movl $0x1fa, %edx            # imm = 0x1FA
movq %rbx, %rcx
movq %r12, %rbx
movq %r12, %rdi
movq %rcx, %r14
callq 0x2220
movq %rax, %r12
cmpq $0x1fa, %rax            # imm = 0x1FA
je 0x310f
movq %r14, %rdi
callq 0x2240
testl %eax, %eax
je 0x32cb
movzbl %r13b, %ecx
movzwl %r12w, %edx
leaq -0x450(%rbp), %r15
movq %r15, %rdi
movq %rbx, %r12
movq %rbx, %rsi
movl $0x3, %r8d
callq 0x3d12
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq -0x30(%rbp), %rbx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3161
movl $0x200, %edx            # imm = 0x200
movq %rsi, %rdi
movq %r15, %rsi
callq 0x2150
addq $0x200, 0x8(%rbx)       # imm = 0x200
jmp 0x316c
movq %rbx, %rdi
movq %r15, %rdx
callq 0x39da
movq %r14, %rbx
movq -0x40(%rbp), %r14
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x318b
movaps -0x50(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0x3197
movq %r14, %rdi
leaq -0x50(%rbp), %rdx
callq 0x3b66
leal 0x1(%r13), %eax
leal 0x20(%r13), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x20, %ecx
negl %ecx
addl %ecx, %r13d
incl %r13d
movq %rbx, %rdi
callq 0x2240
testl %eax, %eax
je 0x30ca
movzbl %r13b, %esi
leaq -0x450(%rbp), %rdi
movl $0x3, %edx
callq 0x3cba
xorps %xmm0, %xmm0
movaps %xmm0, -0x250(%rbp)
movq -0x30(%rbp), %r15
movq 0x8(%r15), %rax
cmpq 0x10(%r15), %rax
je 0x3275
leaq -0x450(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
movq %rax, %rdi
callq 0x2150
addq $0x200, 0x8(%r15)       # imm = 0x200
jmp 0x3287
movq 0x2ddb(%rip), %rbx      # 0x5ff0
leaq 0xf2d(%rip), %rsi       # 0x4149
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
callq 0x21f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2110
leaq -0x450(%rbp), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x39da
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x32a2
movaps -0x250(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0x32b1
leaq -0x250(%rbp), %rdx
movq %r14, %rdi
callq 0x3b66
movq %rbx, %rdi
callq 0x21c0
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x21c0
movq 0x2d16(%rip), %rdi      # 0x5ff0
leaq 0xe85(%rip), %rsi       # 0x4166
callq 0x21b0
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movl $0x1, %edi
callq 0x2210