// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
movq %rsi, %rbx
movq %rdi, 0x50(%rsp)
xorl %ecx, %ecx
movl %ecx, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movl %ecx, 0x2c(%rsp)
cmpb $0x1, 0x2072(%rsi)
jne 0x4706
movb 0x2056(%rbx), %cl
movl $0x1, 0x1c(%rsp)
movl $0x1, 0x18(%rsp)
testb %cl, %cl
jne 0x4725
movzbl 0x209d(%rbx), %eax
movl %eax, 0x18(%rsp)
testb %cl, %cl
jne 0x4734
movzbl 0x209c(%rbx), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x208c(%rbx)
je 0x49ac
movl 0x1c(%rsp), %eax
imull 0x18(%rsp), %eax
imull 0x2078(%rbx), %eax
movl %eax, 0x24(%rsp)
leaq 0x2050(%rbx), %rsi
leaq 0x410(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x1230(%rbx), %rax
movq %rax, 0x60(%rsp)
movl $0x0, 0x10(%rsp)
movl %ecx, 0x3c(%rsp)
movq %rsi, 0x58(%rsp)
cmpl $0x0, 0x2090(%rbx)
je 0x4994
movq $0x0, 0x30(%rsp)
cmpl $0x0, 0x24(%rsp)
je 0x47d7
movl 0x2098(%rbx), %eax
imull 0x10(%rsp), %eax
addl 0x30(%rsp), %eax
xorl %edx, %edx
divl 0x24(%rsp)
testl %edx, %edx
jne 0x47d7
movq $0x0, 0x40(%rsp)
xorl %eax, %eax
movl %eax, 0x48(%rsp)
movl %eax, 0x2c(%rsp)
movq 0x50(%rsp), %rax
movb $0x0, 0x1(%rax)
cmpb $0x0, 0x2070(%rbx)
je 0x4966
xorl %r14d, %r14d
leaq (,%r14,8), %rbp
subq %r14, %rbp
cmpb $0x1, 0x6(%rsi,%rbp)
jne 0x494d
addq %rsi, %rbp
movl $0x1, 0x14(%rsp)
movl $0x1, 0x20(%rsp)
testb %cl, %cl
jne 0x481c
movzbl 0x1(%rbp), %eax
movl %eax, 0x20(%rsp)
testb %cl, %cl
jne 0x4828
movzbl (%rbp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x4932
cmpl $0x0, 0x14(%rsp)
setne 0xf(%rsp)
leaq (%rsp,%r14,4), %rax
addq $0x40, %rax
movq %rax, 0x70(%rsp)
xorl %eax, %eax
movl 0x10(%rsp), %r15d
movl $0xe, %edx
cmpl $0x0, 0x14(%rsp)
je 0x490d
movl %eax, 0x28(%rsp)
xorl %r12d, %r12d
movb 0xf(%rsp), %r13b
movl 0x2098(%rbx), %eax
imull %r15d, %eax
movq 0x30(%rsp), %rcx
addl %r12d, %ecx
addl %ecx, %eax
leaq (%rax,%rax,2), %rdx
shlq $0x8, %rdx
addq 0x2080(%rbx), %rdx
testl %r14d, %r14d
je 0x48b5
cmpl $0x2, %r14d
je 0x48aa
cmpl $0x1, %r14d
jne 0x48b3
addq $0x100, %rdx            # imm = 0x100
jmp 0x48b5
addq $0x200, %rdx            # imm = 0x200
jmp 0x48b5
xorl %edx, %edx
movzbl 0x3(%rbp), %eax
imulq $0x388, %rax, %r9       # imm = 0x388
addq 0x68(%rsp), %r9
movzbl 0x4(%rbp), %eax
imulq $0x388, %rax, %rax      # imm = 0x388
addq 0x60(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
movq 0x70(%rsp), %rcx
leaq 0x2c(%rsp), %r8
callq 0x4cda
testb %al, %al
je 0x4914
incl %r12d
cmpl 0x14(%rsp), %r12d
setb %r13b
jne 0x486d
movl $0xe, %edx
jmp 0x4919
movb 0xf(%rsp), %r13b
jmp 0x491d
movl $0x1, %edx
movl 0x28(%rsp), %eax
testb $0x1, %r13b
jne 0x4937
incl %eax
incl %r15d
cmpl 0x20(%rsp), %eax
jne 0x4851
movl $0xb, %edx
cmpl $0xb, %edx
movl $0x0, %eax
cmovel %eax, %edx
movl 0x3c(%rsp), %ecx
movq 0x58(%rsp), %rsi
jne 0x494f
xorl %edx, %edx
testl %edx, %edx
jne 0x496b
incq %r14
movzbl 0x2070(%rbx), %eax
cmpq %rax, %r14
jb 0x47e7
movl $0x8, %edx
cmpl $0x8, %edx
jne 0x498f
movq 0x30(%rsp), %rax
addl 0x1c(%rsp), %eax
movq %rax, 0x30(%rsp)
cmpl 0x2090(%rbx), %eax
jb 0x479b
movl $0x5, %edx
cmpl $0x5, %edx
jne 0x49ac
movl 0x10(%rsp), %eax
addl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
cmpl 0x208c(%rbx), %eax
jb 0x4785
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq