// File: dannye[P]jed/src/decoder.cpp
// Function: printFrameInfo(JPGImage const*)
void printFrameInfo(const JPGImage* const image) {
    if (image == nullptr) return;
    std::cout << "SOF=============\n";
    std::cout << "Frame Type: 0x" << std::hex << (uint)image->frameType << std::dec << '\n';
    std::cout << "Height: " << image->height << '\n';
    std::cout << "Width: " << image->width << '\n';
    std::cout << "Color Components:\n";
    for (uint i = 0; i < image->numComponents; ++i) {
        if (image->colorComponents[i].usedInFrame) {
            std::cout << "Component ID: " << (i + 1) << '\n';
            std::cout << "Horizontal Sampling Factor: " << (uint)image->colorComponents[i].horizontalSamplingFactor << '\n';
            std::cout << "Vertical Sampling Factor: " << (uint)image->colorComponents[i].verticalSamplingFactor << '\n';
            std::cout << "Quantization Table ID: " << (uint)image->colorComponents[i].quantizationTableID << '\n';
        }
    }
    std::cout << "DQT=============\n";
    for (uint i = 0; i < 4; ++i) {
        if (image->quantizationTables[i].set) {
            std::cout << "Table ID: " << i << '\n';
            std::cout << "Table Data:";
            for (uint j = 0; j < 64; ++j) {
                if (j % 8 == 0) {
                    std::cout << '\n';
                }
                std::cout << image->quantizationTables[i].table[j] << ' ';
            }
            std::cout << '\n';
        }
    }
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x39e6
jmp 0x3d1e
movq 0x85eb(%rip), %rdi      # 0xbfd8
leaq 0x5bec(%rip), %rsi      # 0x95e0
callq 0x2110
movq 0x85d8(%rip), %rdi      # 0xbfd8
leaq 0x5beb(%rip), %rsi      # 0x95f2
callq 0x2110
movq %rax, %rdi
leaq 0x408a(%rip), %rsi      # 0x7aa0
callq 0x2050
movq %rax, %rdi
movq 0x10(%rsp), %rax
movzbl 0x2065(%rax), %esi
callq 0x21b0
movq %rax, %rdi
leaq 0x4087(%rip), %rsi      # 0x7ac0
callq 0x2050
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8586(%rip), %rdi      # 0xbfd8
leaq 0x5ba8(%rip), %rsi      # 0x9601
callq 0x2110
movq %rax, %rdi
movq 0x10(%rsp), %rax
movl 0x2068(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8553(%rip), %rdi      # 0xbfd8
leaq 0x5b7e(%rip), %rsi      # 0x960a
callq 0x2110
movq %rax, %rdi
movq 0x10(%rsp), %rax
movl 0x206c(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8520(%rip), %rdi      # 0xbfd8
leaq 0x5b53(%rip), %rsi      # 0x9612
callq 0x2110
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %rcx
movzbl 0x2070(%rcx), %ecx
cmpl %ecx, %eax
jae 0x3c0a
movq 0x10(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0xc(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
testb $0x1, 0x5(%rax)
je 0x3bf8
movq 0x84cd(%rip), %rdi      # 0xbfd8
leaq 0x5b13(%rip), %rsi      # 0x9625
callq 0x2110
movq %rax, %rdi
movl 0xc(%rsp), %esi
addl $0x1, %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x849e(%rip), %rdi      # 0xbfd8
leaq 0x5af3(%rip), %rsi      # 0x9634
callq 0x2110
movq %rax, %rdi
movq 0x10(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0xc(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
movzbl (%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x845d(%rip), %rdi      # 0xbfd8
leaq 0x5acf(%rip), %rsi      # 0x9651
callq 0x2110
movq %rax, %rdi
movq 0x10(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0xc(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
movzbl 0x1(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x841b(%rip), %rdi      # 0xbfd8
leaq 0x5aa8(%rip), %rsi      # 0x966c
callq 0x2110
movq %rax, %rdi
movq 0x10(%rsp), %rax
addq $0x2050, %rax           # imm = 0x2050
movl 0xc(%rsp), %ecx
imulq $0x7, %rcx, %rcx
addq %rcx, %rax
movzbl 0x2(%rax), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
jmp 0x3bfa
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3acc
movq 0x83c7(%rip), %rdi      # 0xbfd8
leaq 0x5a6c(%rip), %rsi      # 0x9684
callq 0x2110
movl $0x0, 0x8(%rsp)
cmpl $0x4, 0x8(%rsp)
jae 0x3d1e
movq 0x10(%rsp), %rax
movl 0x8(%rsp), %ecx
imulq $0x104, %rcx, %rcx      # imm = 0x104
addq %rcx, %rax
testb $0x1, 0x100(%rax)
je 0x3d0c
movq 0x8381(%rip), %rdi      # 0xbfd8
leaq 0x5ade(%rip), %rsi      # 0x973c
callq 0x2110
movq %rax, %rdi
movl 0x8(%rsp), %esi
callq 0x21b0
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
movq 0x8355(%rip), %rdi      # 0xbfd8
leaq 0x5a0c(%rip), %rsi      # 0x9696
callq 0x2110
movl $0x0, 0x4(%rsp)
cmpl $0x40, 0x4(%rsp)
jae 0x3cfb
movl 0x4(%rsp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
jne 0x3cbb
movq 0x8327(%rip), %rdi      # 0xbfd8
movl $0xa, %esi
callq 0x2160
movq 0x10(%rsp), %rax
movl 0x8(%rsp), %ecx
imulq $0x104, %rcx, %rcx      # imm = 0x104
addq %rcx, %rax
movl 0x4(%rsp), %ecx
movl (%rax,%rcx,4), %esi
movq 0x82fc(%rip), %rdi      # 0xbfd8
callq 0x21b0
movq %rax, %rdi
movl $0x20, %esi
callq 0x2160
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x3c97
movq 0x82d6(%rip), %rdi      # 0xbfd8
movl $0xa, %esi
callq 0x2160
jmp 0x3d0e
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x3c25
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)