// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movl %esi, %ebx
testl %esi, %esi
jle 0x24b6
movq %rdi, %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x2140
leaq 0x30(%rsp), %rbp
movq %rbp, -0x10(%rbp)
xorl %eax, %eax
movq %rax, -0x8(%rbp)
movb $0x0, (%rbp)
movq %rsp, %rdi
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
leaq 0x18(%rsp), %rdx
movq %rax, (%rdx)
xorl %esi, %esi
callq 0x265e
leaq 0x20(%rsp), %r15
movq %rsp, %r12
leaq 0x18(%rsp), %r13
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20d0
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x21a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x23be
movq %r14, %rdi
callq 0x2170
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x23b1
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x2358
movq %r12, %rdi
movq %r13, %rdx
callq 0x265e
jmp 0x2358
movq (%rsp), %r12
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2160
movl %ebx, %eax
subq %r12, %r15
sarq $0x3, %r15
xorl %ecx, %ecx
subq %rax, %r15
cmovbq %rcx, %r15
movq (%rsp), %rax
movq (%rax,%r15,8), %rsi
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2110
leaq 0x20(%rsp), %r14
movq 0x2bc9(%rip), %r15      # 0x4fd8
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20d0
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x247f
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rdi
callq 0x2100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x20d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2080
jmp 0x240f
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2495
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x20f0
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x24ac
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x20f0
leaq 0x40(%rsp), %rdi
callq 0x2040
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24d0
jmp 0x24d0
jmp 0x24d0
jmp 0x24d0
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x24e9
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x20f0
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2500
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x20f0
leaq 0x40(%rsp), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2180