// File: dannye[P]jed/src/decoder.cpp
// Function: printScanInfo(JPGImage const*)
void printScanInfo(const JPGImage* const image) {
    if (image == nullptr) return;
    std::cout << "SOS=============\n";
    std::cout << "Start of Selection: " << (uint)image->startOfSelection << '\n';
    std::cout << "End of Selection: " << (uint)image->endOfSelection << '\n';
    std::cout << "Successive Approximation High: " << (uint)image->successiveApproximationHigh << '\n';
    std::cout << "Successive Approximation Low: " << (uint)image->successiveApproximationLow << '\n';
    std::cout << "Color Components:\n";
    for (uint i = 0; i < image->numComponents; ++i) {
        if (image->colorComponents[i].usedInScan) {
            std::cout << "Component ID: " << (i + 1) << '\n';
            std::cout << "Huffman DC Table ID: " << (uint)image->colorComponents[i].huffmanDCTableID << '\n';
            std::cout << "Huffman AC Table ID: " << (uint)image->colorComponents[i].huffmanACTableID << '\n';
        }
    }
    std::cout << "DHT=============\n";
    std::cout << "DC Tables:\n";
    for (uint i = 0; i < 4; ++i) {
        if (image->huffmanDCTables[i].set) {
            std::cout << "Table ID: " << i << '\n';
            std::cout << "Symbols:\n";
            for (uint j = 0; j < 16; ++j) {
                std::cout << (j + 1) << ": ";
                for (uint k = image->huffmanDCTables[i].offsets[j]; k < image->huffmanDCTables[i].offsets[j + 1]; ++k) {
                    std::cout << std::hex << (uint)image->huffmanDCTables[i].symbols[k] << std::dec << ' ';
                }
                std::cout << '\n';
            }
        }
    }
    std::cout << "AC Tables:\n";
    for (uint i = 0; i < 4; ++i) {
        if (image->huffmanACTables[i].set) {
            std::cout << "Table ID: " << i << '\n';
            std::cout << "Symbols:\n";
            for (uint j = 0; j < 16; ++j) {
                std::cout << (j + 1) << ": ";
                for (uint k = image->huffmanACTables[i].offsets[j]; k < image->huffmanACTables[i].offsets[j + 1]; ++k) {
                    std::cout << std::hex << (uint)image->huffmanACTables[i].symbols[k] << std::dec << ' ';
                }
                std::cout << '\n';
            }
        }
    }
    std::cout << "DRI=============\n";
    std::cout << "Restart Interval: " << image->restartInterval << '\n';
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x3d46
jmp 0x42fe
movq 0x828b(%rip), %rdi      # 0xbfd8
leaq 0x594e(%rip), %rsi      # 0x96a2
callq 0x2110
movq 0x8278(%rip), %rdi      # 0xbfd8
leaq 0x594d(%rip), %rsi      # 0x96b4
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x2073(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8244(%rip), %rdi      # 0xbfd8
leaq 0x592e(%rip), %rsi      # 0x96c9
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x2074(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8210(%rip), %rdi      # 0xbfd8
leaq 0x590d(%rip), %rsi      # 0x96dc
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x2075(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x81dc(%rip), %rdi      # 0xbfd8
leaq 0x58f9(%rip), %rsi      # 0x96fc
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
movzbl 0x2076(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x81a8(%rip), %rdi      # 0xbfd8
leaq 0x57db(%rip), %rsi      # 0x9612
callq 0x2110
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x20(%rsp), %rcx
movzbl 0x2070(%rcx), %ecx
cmpl %ecx, %eax
jae 0x3f41
movq 0x20(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0x1c(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
testb $0x1, 0x6(%rax)
je 0x3f2f
movq 0x8155(%rip), %rdi      # 0xbfd8
leaq 0x579b(%rip), %rsi      # 0x9625
callq 0x2110
movq %rax, %rdi
movl 0x1c(%rsp), %esi
addl $0x1, %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8126(%rip), %rdi      # 0xbfd8
leaq 0x5862(%rip), %rsi      # 0x971b
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0x1c(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
movzbl 0x3(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x80e4(%rip), %rdi      # 0xbfd8
leaq 0x5836(%rip), %rsi      # 0x9731
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0x1c(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
movzbl 0x4(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
jmp 0x3f31
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x3e44
movq 0x8090(%rip), %rdi      # 0xbfd8
leaq 0x57f8(%rip), %rsi      # 0x9747
callq 0x2110
movq 0x807d(%rip), %rdi      # 0xbfd8
leaq 0x57f7(%rip), %rsi      # 0x9759
callq 0x2110
movl $0x0, 0x18(%rsp)
cmpl $0x4, 0x18(%rsp)
jae 0x4106
movq 0x20(%rsp), %rax
addq $0x410, %rax            # imm = 0x410
movl 0x18(%rsp), %ecx
imulq $0x388, %rcx, %rcx      # imm = 0x388
addq %rcx, %rax
testb $0x1, 0x384(%rax)
je 0x40f4
movq 0x8031(%rip), %rdi      # 0xbfd8
leaq 0x578e(%rip), %rsi      # 0x973c
callq 0x2110
movq %rax, %rdi
movl 0x18(%rsp), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8005(%rip), %rdi      # 0xbfd8
leaq 0x578b(%rip), %rsi      # 0x9765
callq 0x2110
movl $0x0, 0x14(%rsp)
cmpl $0x10, 0x14(%rsp)
jae 0x40f2
movl 0x14(%rsp), %esi
addl $0x1, %esi
movq 0x7fd8(%rip), %rdi      # 0xbfd8
callq 0x21b0
movq %rax, %rdi
leaq 0x5735(%rip), %rsi      # 0x9744
callq 0x2110
movq 0x20(%rsp), %rax
addq $0x410, %rax            # imm = 0x410
movl 0x18(%rsp), %ecx
imulq $0x388, %rcx, %rcx      # imm = 0x388
addq %rcx, %rax
movl 0x14(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x20(%rsp), %rcx
addq $0x410, %rcx            # imm = 0x410
movl 0x18(%rsp), %edx
imulq $0x388, %rdx, %rdx      # imm = 0x388
addq %rdx, %rcx
movl 0x14(%rsp), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jae 0x40d1
movq 0x7f69(%rip), %rdi      # 0xbfd8
leaq 0x3a2a(%rip), %rsi      # 0x7aa0
callq 0x2050
movq %rax, %rdi
movq 0x20(%rsp), %rax
addq $0x410, %rax            # imm = 0x410
movl 0x18(%rsp), %ecx
imulq $0x388, %rcx, %rcx      # imm = 0x388
addq %rcx, %rax
movl 0x10(%rsp), %ecx
movzbl 0x11(%rax,%rcx), %esi
callq 0x21b0
movq %rax, %rdi
leaq 0x3a11(%rip), %rsi      # 0x7ac0
callq 0x2050
movq %rax, %rdi
movl $0x20, %esi
callq 0x2160
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x4039
movq 0x7f00(%rip), %rdi      # 0xbfd8
movl $0xa, %esi
callq 0x2160
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x3fe7
jmp 0x40f4
jmp 0x40f6
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x3f6f
movq 0x7ecb(%rip), %rdi      # 0xbfd8
leaq 0x565b(%rip), %rsi      # 0x976f
callq 0x2110
movl $0x0, 0xc(%rsp)
cmpl $0x4, 0xc(%rsp)
jae 0x42b8
movq 0x20(%rsp), %rax
addq $0x1230, %rax           # imm = 0x1230
movl 0xc(%rsp), %ecx
imulq $0x388, %rcx, %rcx      # imm = 0x388
addq %rcx, %rax
testb $0x1, 0x384(%rax)
je 0x42a6
movq 0x7e7f(%rip), %rdi      # 0xbfd8
leaq 0x55dc(%rip), %rsi      # 0x973c
callq 0x2110
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x7e53(%rip), %rdi      # 0xbfd8
leaq 0x55d9(%rip), %rsi      # 0x9765
callq 0x2110
movl $0x0, 0x8(%rsp)
cmpl $0x10, 0x8(%rsp)
jae 0x42a4
movl 0x8(%rsp), %esi
addl $0x1, %esi
movq 0x7e26(%rip), %rdi      # 0xbfd8
callq 0x21b0
movq %rax, %rdi
leaq 0x5583(%rip), %rsi      # 0x9744
callq 0x2110
movq 0x20(%rsp), %rax
addq $0x1230, %rax           # imm = 0x1230
movl 0xc(%rsp), %ecx
imulq $0x388, %rcx, %rcx      # imm = 0x388
addq %rcx, %rax
movl 0x8(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movq 0x20(%rsp), %rcx
addq $0x1230, %rcx           # imm = 0x1230
movl 0xc(%rsp), %edx
imulq $0x388, %rdx, %rdx      # imm = 0x388
addq %rdx, %rcx
movl 0x8(%rsp), %edx
addl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jae 0x4283
movq 0x7db7(%rip), %rdi      # 0xbfd8
leaq 0x3878(%rip), %rsi      # 0x7aa0
callq 0x2050
movq %rax, %rdi
movq 0x20(%rsp), %rax
addq $0x1230, %rax           # imm = 0x1230
movl 0xc(%rsp), %ecx
imulq $0x388, %rcx, %rcx      # imm = 0x388
addq %rcx, %rax
movl 0x4(%rsp), %ecx
movzbl 0x11(%rax,%rcx), %esi
callq 0x21b0
movq %rax, %rdi
leaq 0x385f(%rip), %rsi      # 0x7ac0
callq 0x2050
movq %rax, %rdi
movl $0x20, %esi
callq 0x2160
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x41eb
movq 0x7d4e(%rip), %rdi      # 0xbfd8
movl $0xa, %esi
callq 0x2160
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x4199
jmp 0x42a6
jmp 0x42a8
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x4121
movq 0x7d19(%rip), %rdi      # 0xbfd8
leaq 0x54b5(%rip), %rsi      # 0x977b
callq 0x2110
movq 0x7d06(%rip), %rdi      # 0xbfd8
leaq 0x54b4(%rip), %rsi      # 0x978d
callq 0x2110
movq %rax, %rdi
movq 0x20(%rsp), %rax
movl 0x2078(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)