// File: /workspace/github_cpp_makefile_star2_O3/dannye[P]jed/src/decoder.cpp
// Function: decodeHuffmanData(BitReader&, JPGImage*)
void decodeHuffmanData(BitReader& bitReader, JPGImage* const image) {
    int previousDCs[3] = { 0 };
    uint skips = 0;

    const bool luminanceOnly = image->componentsInScan == 1 && image->colorComponents[0].usedInScan;
    const uint yStep = luminanceOnly ? 1 : image->verticalSamplingFactor;
    const uint xStep = luminanceOnly ? 1 : image->horizontalSamplingFactor;
    const uint restartInterval = image->restartInterval * xStep * yStep;

    for (uint y = 0; y < image->blockHeight; y += yStep) {
        for (uint x = 0; x < image->blockWidth; x += xStep) {
            if (restartInterval != 0 && (y * image->blockWidthReal + x) % restartInterval == 0) {
                previousDCs[0] = 0;
                previousDCs[1] = 0;
                previousDCs[2] = 0;
                skips = 0;
                bitReader.align();
            }

            for (uint i = 0; i < image->numComponents; ++i) {
                const ColorComponent& component = image->colorComponents[i];
                if (component.usedInScan) {
                    const uint vMax = luminanceOnly ? 1 : component.verticalSamplingFactor;
                    const uint hMax = luminanceOnly ? 1 : component.horizontalSamplingFactor;
                    for (uint v = 0; v < vMax; ++v) {
                        for (uint h = 0; h < hMax; ++h) {
                            if (!decodeBlockComponent(
                                    image,
                                    bitReader,
                                    image->blocks[(y + v) * image->blockWidthReal + (x + h)][i],
                                    previousDCs[i],
                                    skips,
                                    image->huffmanDCTables[component.huffmanDCTableID],
                                    image->huffmanACTables[component.huffmanACTableID])) {
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
movq %rdi, 0x50(%rsp)
xorl %eax, %eax
movl %eax, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movl %eax, 0x24(%rsp)
cmpb $0x1, 0x2072(%rsi)
jne 0x465c
cmpb $0x0, 0x2056(%rbx)
je 0x465c
movb $0x1, %al
movl %eax, 0x1c(%rsp)
movl $0x1, 0xc(%rsp)
movl $0x1, 0x10(%rsp)
jmp 0x467a
movzbl 0x209d(%rbx), %eax
movl %eax, 0xc(%rsp)
movzbl 0x209c(%rbx), %eax
movl %eax, 0x10(%rsp)
movl $0x0, 0x1c(%rsp)
movl 0x208c(%rbx), %eax
testl %eax, %eax
je 0x489b
movl 0x10(%rsp), %ecx
imull 0xc(%rsp), %ecx
imull 0x2078(%rbx), %ecx
movl %ecx, 0x18(%rsp)
leaq 0x2050(%rbx), %rcx
movq %rcx, 0x48(%rsp)
leaq 0x410(%rbx), %rcx
movq %rcx, 0x60(%rsp)
leaq 0x1230(%rbx), %rcx
movq %rcx, 0x58(%rsp)
movl 0x2090(%rbx), %ecx
movl %ecx, %edx
movl $0x0, 0x8(%rsp)
testl %edx, %edx
je 0x4885
movq $0x0, 0x28(%rsp)
movl 0x18(%rsp), %esi
testl %esi, %esi
je 0x471c
movl 0x2098(%rbx), %eax
imull 0x8(%rsp), %eax
addl 0x28(%rsp), %eax
xorl %edx, %edx
divl %esi
testl %edx, %edx
jne 0x471c
movq $0x0, 0x38(%rsp)
xorl %eax, %eax
movl %eax, 0x40(%rsp)
movl %eax, 0x24(%rsp)
movq 0x50(%rsp), %rax
movb $0x0, 0x1(%rax)
movb 0x2070(%rbx), %al
testb %al, %al
movq 0x48(%rsp), %rdx
je 0x4865
xorl %r14d, %r14d
leaq (,%r14,8), %rbp
subq %r14, %rbp
cmpb $0x1, 0x6(%rdx,%rbp)
jne 0x484c
addq %rdx, %rbp
movl $0x1, 0x14(%rsp)
movl $0x1, 0x20(%rsp)
cmpb $0x0, 0x1c(%rsp)
jne 0x477a
movzbl 0x1(%rbp), %ecx
movl %ecx, 0x20(%rsp)
testl %ecx, %ecx
je 0x484c
movzbl (%rbp), %eax
movl %eax, 0x14(%rsp)
leaq (%rsp,%r14,4), %r12
addq $0x38, %r12
xorl %eax, %eax
movl 0x8(%rsp), %r15d
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x482e
xorl %r13d, %r13d
movl 0x2098(%rbx), %eax
imull %r15d, %eax
movq 0x28(%rsp), %rcx
addl %r13d, %ecx
addl %ecx, %eax
leaq (%rax,%rax,2), %rdx
shlq $0x8, %rdx
addq 0x2080(%rbx), %rdx
testl %r14d, %r14d
je 0x47e3
cmpl $0x2, %r14d
je 0x47d8
cmpl $0x1, %r14d
jne 0x47e1
addq $0x100, %rdx            # imm = 0x100
jmp 0x47e3
addq $0x200, %rdx            # imm = 0x200
jmp 0x47e3
xorl %edx, %edx
movzbl 0x3(%rbp), %eax
imulq $0x388, %rax, %r9       # imm = 0x388
addq 0x60(%rsp), %r9
movzbl 0x4(%rbp), %eax
imulq $0x388, %rax, %rax      # imm = 0x388
addq 0x58(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
movq %r12, %rcx
leaq 0x24(%rsp), %r8
callq 0x4be9
testb %al, %al
je 0x489b
incl %r13d
cmpl %r13d, 0x14(%rsp)
jne 0x479b
movl 0x34(%rsp), %eax
incl %eax
incl %r15d
cmpl 0x20(%rsp), %eax
jne 0x4789
movb 0x2070(%rbx), %al
movq 0x48(%rsp), %rdx
incq %r14
movzbl %al, %ecx
cmpq %rcx, %r14
jb 0x4732
movl 0x2090(%rbx), %ecx
movl 0x18(%rsp), %esi
movq 0x28(%rsp), %rax
addl 0x10(%rsp), %eax
movq %rax, 0x28(%rsp)
cmpl %ecx, %eax
jb 0x46e5
movl 0x208c(%rbx), %eax
movl %ecx, %edx
jmp 0x4887
xorl %edx, %edx
movl 0x8(%rsp), %esi
addl 0xc(%rsp), %esi
movl %esi, 0x8(%rsp)
cmpl %eax, %esi
jb 0x46d0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq