// File: /workspace/github_cpp_makefile_star2_O1/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 0x5605(%rip), %r14      # 0x9fd8
leaq 0x2feb(%rip), %rsi      # 0x79c5
movl $0x8, %edx
movq %r14, %rdi
callq 0x2130
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x2130
leaq 0x2fd1(%rip), %rsi      # 0x79ce
movl $0x4, %edx
movq %rax, %rdi
callq 0x2130
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x660c
movq 0x8(%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x30(%rsp,%rax)
je 0x4a5f
movq 0x55a8(%rip), %rdi      # 0x9fd8
leaq 0x2f9c(%rip), %rsi      # 0x79d3
movl $0x21, %edx
callq 0x2130
xorl %ebx, %ebx
leaq 0x8(%rsp), %rdi
callq 0x6652
movq %rbx, %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x5552(%rip), %rsi      # 0x9fb8
movl $0x20a0, %edi           # imm = 0x20A0
callq 0x2210
testq %rax, %rax
je 0x4b6a
movq %rax, %rbx
xorl %r14d, %r14d
leaq (%rbx,%r14), %rdi
addq $0x104, %r14            # imm = 0x104
movl $0x101, %edx            # imm = 0x101
xorl %esi, %esi
callq 0x2090
cmpq $0x410, %r14            # imm = 0x410
jne 0x4a7f
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 0x4aa5
movl $0x1230, %r15d          # imm = 0x1230
leaq (%rbx,%r15), %rdi
leaq (%rbx,%r15), %r14
addq $0xc4, %r14
addq $0x388, %r15            # imm = 0x388
movl $0xc1, %edx
xorl %esi, %esi
callq 0x2090
movl $0x2c1, %edx            # imm = 0x2C1
movq %r14, %rdi
xorl %esi, %esi
callq 0x2090
cmpq $0x2050, %r15           # imm = 0x2050
jne 0x4ae5
movl $0x0, 0x2078(%rbx)
xorl %eax, %eax
movq %rax, 0x2080(%rbx)
movq %rax, 0x2068(%rbx)
movq %rax, 0x206f(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x2050(%rbx)
movq %rax, 0x205e(%rbx)
movb $0x1, 0x2088(%rbx)
movups %xmm0, 0x208c(%rbx)
movw $0x0, 0x209c(%rbx)
jmp 0x4b6c
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x4bea
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4130
cmpb $0x1, 0x2088(%rbx)
jne 0x4a43
movq %rbx, %rdi
callq 0x3853
movl 0x2098(%rbx), %r12d
imull 0x2094(%rbx), %r12d
movq %r12, %rax
shlq $0x8, %rax
leaq (%rax,%rax,2), %r15
movq 0x5404(%rip), %rsi      # 0x9fb8
movq %r15, %rdi
callq 0x21b0
testq %rax, %rax
je 0x4c07
movq %rax, %r14
testq %r12, %r12
je 0x4c0a
xorl %r12d, %r12d
leaq (%r14,%r12), %rdi
movl $0x300, %edx            # imm = 0x300
xorl %esi, %esi
callq 0x2090
addq $0x300, %r12            # imm = 0x300
cmpq %r12, %r15
jne 0x4bcc
jmp 0x4c0a
movq 0x53e7(%rip), %rdi      # 0x9fd8
leaq 0x2dfd(%rip), %rsi      # 0x79f5
movl $0x15, %edx
callq 0x2130
jmp 0x4a41
xorl %r14d, %r14d
movq %r14, 0x2080(%rbx)
testq %r14, %r14
je 0x4c28
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x4495
jmp 0x4a43
movq 0x53a9(%rip), %rdi      # 0x9fd8
leaq 0x2dbf(%rip), %rsi      # 0x79f5
movl $0x15, %edx
callq 0x2130
movb $0x0, 0x2088(%rbx)
jmp 0x4a43
jmp 0x4c4e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6652
movq %rbx, %rdi
callq 0x21c0