// File: CMU-SAFARI[P]ramulator/src/Processor.cpp
// Function: ramulator::Trace::get_filtered_request(long&, long&, ramulator::Request::Type&)
bool Trace::get_filtered_request(long& bubble_cnt, long& req_addr, Request::Type& req_type)
{
    static bool has_write = false;
    static long write_addr;
    static int line_num = 0;
    if (has_write){
        bubble_cnt = 0;
        req_addr = write_addr;
        req_type = Request::Type::WRITE;
        has_write = false;
        return true;
    }
    string line;
    getline(file, line);
    line_num ++;
    if (file.eof() || line.size() == 0) {
        file.clear();
        file.seekg(0, file.beg);
        line_num = 0;

        if(expected_limit_insts == 0) {
            has_write = false;
            return false;
        }
        else { // starting over the input trace file
            getline(file, line);
            line_num++;
        }
    }

    size_t pos, end;
    bubble_cnt = std::stoul(line, &pos, 10);

    pos = line.find_first_not_of(' ', pos+1);
    req_addr = stoul(line.substr(pos), &end, 0);
    req_type = Request::Type::READ;

    pos = line.find_first_not_of(' ', pos+end);
    if (pos != string::npos){
        has_write = true;
        write_addr = stoul(line.substr(pos), NULL, 0);
    }
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
testb $0x1, 0x155894(%rip)    # 0x34eed1
je 0x1f9672
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movq 0x155887(%rip), %rcx    # 0x34eed8
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movb $0x0, 0x155868(%rip)    # 0x34eed1
movb $0x1, -0x1(%rbp)
jmp 0x1f98fd
leaq -0x48(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0xc480
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
addq $0x8, %rdi
callq 0xc0e0
jmp 0x1f969b
movq -0xb0(%rbp), %rax
movl 0x155838(%rip), %ecx    # 0x34eee0
incl %ecx
movl %ecx, 0x155830(%rip)    # 0x34eee0
movq 0x8(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x8(%rax,%rcx), %rdi
callq 0xc620
movb %al, -0xb9(%rbp)
jmp 0x1f96ca
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0x1f96e9
jmp 0x1f96d6
leaq -0x48(%rbp), %rdi
callq 0xc2b0
cmpq $0x0, %rax
jne 0x1f9782
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x18(%rcx), %rcx
leaq 0x8(%rax,%rcx), %rdi
xorl %esi, %esi
callq 0xc580
jmp 0x1f9706
movq -0xb0(%rbp), %rdi
addq $0x8, %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xc460
jmp 0x1f971c
movq -0xb0(%rbp), %rax
movl $0x0, 0x1557b3(%rip)    # 0x34eee0
cmpq $0x0, (%rax)
jne 0x1f975b
movb $0x0, 0x155797(%rip)    # 0x34eed1
movb $0x0, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x1f98e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1f98f2
movq -0xb0(%rbp), %rdi
addq $0x8, %rdi
leaq -0x48(%rbp), %rsi
callq 0xc0e0
jmp 0x1f9771
movl 0x155769(%rip), %eax    # 0x34eee0
addl $0x1, %eax
movl %eax, 0x155760(%rip)    # 0x34eee0
jmp 0x1f9782
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0xa, %edx
callq 0x1fb020
movq %rax, -0xc8(%rbp)
jmp 0x1f979d
movq -0xc8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rdx
incq %rdx
leaq -0x48(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
movl $0x20, %esi
callq 0xc340
movq -0xd0(%rbp), %rsi
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdx
leaq -0x88(%rbp), %rdi
movq $-0x1, %rcx
callq 0xc380
jmp 0x1f97eb
leaq -0x88(%rbp), %rdi
leaq -0x68(%rbp), %rsi
xorl %edx, %edx
callq 0x1fb020
movq %rax, -0xd8(%rbp)
jmp 0x1f9806
movq -0xd8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
leaq -0x88(%rbp), %rdi
callq 0xc6b8
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x60(%rbp), %rdx
addq -0x68(%rbp), %rdx
leaq -0x48(%rbp), %rdi
movl $0x20, %esi
callq 0xc340
movq %rax, -0x60(%rbp)
cmpq $-0x1, -0x60(%rbp)
je 0x1f98dc
movb $0x1, 0x15567b(%rip)    # 0x34eed1
movq -0x60(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movq $-0x1, %rcx
callq 0xc380
jmp 0x1f9873
xorl %edx, %edx
movl %edx, %esi
leaq -0xa8(%rbp), %rdi
callq 0x1fb020
movq %rax, -0xe0(%rbp)
jmp 0x1f988c
movq -0xe0(%rbp), %rax
movq %rax, 0x15563e(%rip)    # 0x34eed8
leaq -0xa8(%rbp), %rdi
callq 0xc6b8
jmp 0x1f98dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xc6b8
jmp 0x1f98f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xc6b8
jmp 0x1f98f2
movb $0x1, -0x1(%rbp)
movl $0x1, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xc6b8
jmp 0x1f98fd
leaq -0x48(%rbp), %rdi
callq 0xc6b8
jmp 0x1f990b
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xe0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0xc5d0
nopw %cs:(%rax,%rax)