// File: /workspace/github_cpp_makefile_star2_O3/dannye[P]jed/src/decoder.cpp
// Function: readJPG(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
JPGImage* readJPG(const std::string& filename) {
    // open file
    std::cout << "Reading " << filename << "...\n";
    BitReader bitReader(filename);
    if (!bitReader.hasBits()) {
        std::cout << "Error - Error opening input file\n";
        return nullptr;
    }

    JPGImage* image = new (std::nothrow) JPGImage;
    if (image == nullptr) {
        std::cout << "Error - Memory error\n";
        return nullptr;
    }

    readFrameHeader(bitReader, image);

    if (!image->valid) {
        return image;
    }

    printFrameInfo(image);

    image->blocks = new (std::nothrow) Block[image->blockHeightReal * image->blockWidthReal];
    if (image->blocks == nullptr) {
        std::cout << "Error - Memory error\n";
        image->valid = false;
        return image;
    }

    readScans(bitReader, image);

    return image;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, %rbx
movq 0x5716(%rip), %r14      # 0x9fd8
leaq 0x30fc(%rip), %rsi      # 0x79c5
movl $0x8, %edx
movq %r14, %rdi
callq 0x2130
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x2130
leaq 0x30e2(%rip), %rsi      # 0x79ce
movl $0x4, %edx
movq %rax, %rdi
callq 0x2130
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6304
movq 0x8(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x30(%rsp,%rax)
je 0x494e
movq 0x56b9(%rip), %rdi      # 0x9fd8
leaq 0x30ad(%rip), %rsi      # 0x79d3
movl $0x21, %edx
callq 0x2130
xorl %ebx, %ebx
leaq 0x8(%rsp), %rdi
callq 0x634a
movq %rbx, %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x5663(%rip), %rsi      # 0x9fb8
movl $0x20a0, %edi           # imm = 0x20A0
callq 0x2210
testq %rax, %rax
je 0x4b21
movq %rax, %rbx
movl $0x101, %edx            # imm = 0x101
movq %rax, %rdi
xorl %esi, %esi
callq 0x2090
leaq 0x104(%rbx), %rdi
movl $0x101, %edx            # imm = 0x101
xorl %esi, %esi
callq 0x2090
leaq 0x208(%rbx), %rdi
movl $0x101, %edx            # imm = 0x101
xorl %esi, %esi
callq 0x2090
leaq 0x30c(%rbx), %rdi
movl $0x101, %edx            # imm = 0x101
xorl %esi, %esi
callq 0x2090
movl $0x4d4, %r15d           # imm = 0x4D4
leaq (%rbx,%r15), %r14
leaq (%rbx,%r15), %rdi
addq $-0xc4, %rdi
movl $0xc1, %edx
xorl %esi, %esi
callq 0x2090
movl $0x2c1, %edx            # imm = 0x2C1
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
addq $0x388, %r15            # imm = 0x388
cmpq $0x12f4, %r15           # imm = 0x12F4
jne 0x49b9
movl $0x1230, %r15d          # imm = 0x1230
leaq (%rbx,%r15), %rdi
leaq (%rbx,%r15), %r14
addq $0xc4, %r14
movl $0xc1, %edx
xorl %esi, %esi
callq 0x2090
movl $0x2c1, %edx            # imm = 0x2C1
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
addq $0x388, %r15            # imm = 0x388
cmpq $0x2050, %r15           # imm = 0x2050
jne 0x49f9
movl $0x0, 0x2078(%rbx)
xorl %eax, %eax
movq %rax, 0x2080(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x2050(%rbx)
movq %rax, 0x205e(%rbx)
movq %rax, 0x2068(%rbx)
movq %rax, 0x206f(%rbx)
movb $0x1, 0x2088(%rbx)
movups %xmm0, 0x208c(%rbx)
movw $0x0, 0x209c(%rbx)
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x40ba
cmpb $0x1, 0x2088(%rbx)
jne 0x4932
movq %rbx, %rdi
callq 0x37d8
movl 0x2098(%rbx), %r12d
imull 0x2094(%rbx), %r12d
movq %r12, %rax
shlq $0x8, %rax
leaq (%rax,%rax,2), %r15
movq 0x54f9(%rip), %rsi      # 0x9fb8
movq %r15, %rdi
callq 0x21b0
testq %rax, %rax
je 0x4b3e
movq %rax, %r14
testl %r12d, %r12d
je 0x4b08
addq $-0x300, %r15           # imm = 0xFD00
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %r15, %rax
mulq %rcx
shrq $0x9, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x8, %rdx
addq $0x300, %rdx            # imm = 0x300
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
movq %r14, 0x2080(%rbx)
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4405
jmp 0x4932
movq 0x54b0(%rip), %rdi      # 0x9fd8
leaq 0x2ec6(%rip), %rsi      # 0x79f5
movl $0x15, %edx
callq 0x2130
jmp 0x4930
movq $0x0, 0x2080(%rbx)
movq 0x5488(%rip), %rdi      # 0x9fd8
leaq 0x2e9e(%rip), %rsi      # 0x79f5
movl $0x15, %edx
callq 0x2130
movb $0x0, 0x2088(%rbx)
jmp 0x4932
jmp 0x4b6f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x634a
movq %rbx, %rdi
callq 0x21c0