// File: eschwabe[P]interview-practice/src/printlastlines.cpp
// Function: PrintLastLines(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int)
void PrintLastLines(const string& filename, const int K) {
    if(K <= 0) {
        return;
    }
    ifstream filestream(filename);
    string tmp;
    vector<off_t> offsets;
    offsets.push_back(0);
    while(getline(filestream, tmp)) {
        offsets.push_back(filestream.tellg());
    }
    size_t start_line = (static_cast<size_t>(K) < offsets.size()) ? (offsets.size() - static_cast<size_t>(K)) : 0;
    filestream.clear();
    filestream.seekg(offsets[start_line]);
    while(getline(filestream,tmp)) {
        cout << tmp << endl;
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jg 0x241d
jmp 0x26c2
movq -0x8(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x2230
leaq -0x238(%rbp), %rdi
callq 0x21f0
leaq -0x250(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x27e0
movq -0x2a0(%rbp), %rdi
movq $0x0, -0x258(%rbp)
leaq -0x258(%rbp), %rsi
callq 0x2800
jmp 0x2471
jmp 0x2473
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x2040
movq %rax, -0x2a8(%rbp)
jmp 0x248f
movq -0x2a8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21d0
movb %al, -0x2a9(%rbp)
jmp 0x24ad
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x24bc
jmp 0x256c
leaq -0x218(%rbp), %rdi
callq 0x2270
movq %rdx, -0x2c0(%rbp)
movq %rax, -0x2b8(%rbp)
jmp 0x24d8
movq -0x2c0(%rbp), %rax
movq -0x2b8(%rbp), %rcx
movq %rcx, -0x280(%rbp)
movq %rax, -0x278(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x2830
movq %rax, -0x2c8(%rbp)
jmp 0x2509
movq -0x2c8(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x2800
jmp 0x252c
jmp 0x2473
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x28d0
leaq -0x238(%rbp), %rdi
callq 0x20c0
leaq -0x218(%rbp), %rdi
callq 0x2050
jmp 0x26cb
movslq -0xc(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x2850
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x25ae
leaq -0x250(%rbp), %rdi
callq 0x2850
movslq -0xc(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x2d8(%rbp)
jmp 0x25b9
xorl %eax, %eax
movq %rax, -0x2d8(%rbp)
jmp 0x25b9
movq -0x2d8(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
xorl %esi, %esi
callq 0x2260
jmp 0x25e3
movq -0x288(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x2870
movq (%rax), %rsi
leaq -0x298(%rbp), %rdi
callq 0x2890
jmp 0x2607
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rdx
leaq -0x218(%rbp), %rdi
callq 0x21e0
jmp 0x2623
jmp 0x2625
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x2040
movq %rax, -0x2e0(%rbp)
jmp 0x2641
movq -0x2e0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21d0
movb %al, -0x2e1(%rbp)
jmp 0x265f
movb -0x2e1(%rbp), %al
testb $0x1, %al
jne 0x266b
jmp 0x269e
movq 0x3966(%rip), %rdi      # 0x5fd8
leaq -0x238(%rbp), %rsi
callq 0x2130
movq %rax, -0x2f0(%rbp)
jmp 0x2687
movq -0x2f0(%rbp), %rdi
movq 0x3933(%rip), %rsi      # 0x5fc8
callq 0x2170
jmp 0x269c
jmp 0x2625
leaq -0x250(%rbp), %rdi
callq 0x28d0
leaq -0x238(%rbp), %rdi
callq 0x20c0
leaq -0x218(%rbp), %rdi
callq 0x2050
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
movq -0x260(%rbp), %rdi
callq 0x2280
nopw (%rax,%rax)