// File: /workspace/github_cpp_makefile_star2_O2/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
andl $0x0, 0x38(%rsp)
andq $0x0, 0x30(%rsp)
andl $0x0, 0x14(%rsp)
movq %rsi, %rbx
movq %rdi, 0x48(%rsp)
cmpb $0x1, 0x2072(%rsi)
jne 0x39b0
cmpb $0x0, 0x2056(%rbx)
je 0x39b0
movb $0x1, %al
movl %eax, 0x8(%rsp)
pushq $0x1
popq %rax
movl %eax, %ecx
jmp 0x39c6
movzbl 0x209d(%rbx), %eax
movzbl 0x209c(%rbx), %ecx
movl $0x0, 0x8(%rsp)
movl %ecx, 0x20(%rsp)
movl %eax, 0x28(%rsp)
imull %eax, %ecx
imull 0x2078(%rbx), %ecx
movl %ecx, 0xc(%rsp)
leaq 0x2050(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x410(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x1230(%rbx), %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq %rax, 0x18(%rsp)
cmpl 0x208c(%rbx), %eax
jae 0x3b9b
xorl %ecx, %ecx
cmpl 0x2090(%rbx), %ecx
movl 0x28(%rsp), %eax
jae 0x3b8c
cmpl $0x0, 0xc(%rsp)
je 0x3a5c
movl 0x2098(%rbx), %eax
imull 0x18(%rsp), %eax
addl %ecx, %eax
xorl %edx, %edx
divl 0xc(%rsp)
testl %edx, %edx
jne 0x3a5c
andq $0x0, 0x30(%rsp)
andl $0x0, 0x38(%rsp)
andl $0x0, 0x14(%rsp)
movq 0x48(%rsp), %rax
movb $0x0, 0x1(%rax)
xorl %r14d, %r14d
movzbl 0x2070(%rbx), %eax
cmpq %rax, %r14
jae 0x3b83
imulq $0x7, %r14, %rbp
movq 0x40(%rsp), %rax
cmpb $0x1, 0x6(%rax,%rbp)
jne 0x3b7b
addq 0x40(%rsp), %rbp
pushq $0x1
popq %rax
movl %eax, %edx
movl %eax, 0x10(%rsp)
cmpb $0x0, 0x8(%rsp)
jne 0x3aa4
movzbl 0x1(%rbp), %edx
movzbl (%rbp), %eax
movl %eax, 0x10(%rsp)
leaq (%rsp,%r14,4), %rax
addq $0x30, %rax
movq %rax, 0x60(%rsp)
xorl %esi, %esi
movq 0x18(%rsp), %rax
movl %eax, %r15d
movl %edx, 0x24(%rsp)
cmpl %edx, %esi
je 0x3b7b
movl %esi, 0x2c(%rsp)
xorl %r13d, %r13d
cmpl %r13d, 0x10(%rsp)
je 0x3b69
movl 0x2098(%rbx), %eax
imull %r15d, %eax
movq %rcx, %r12
addl %r13d, %ecx
addl %ecx, %eax
imulq $0x300, %rax, %rdx      # imm = 0x300
addq 0x2080(%rbx), %rdx
testl %r14d, %r14d
je 0x3b1e
cmpl $0x2, %r14d
je 0x3b13
cmpl $0x1, %r14d
jne 0x3b1c
addq $0x100, %rdx            # imm = 0x100
jmp 0x3b1e
addq $0x200, %rdx            # imm = 0x200
jmp 0x3b1e
xorl %edx, %edx
movzbl 0x3(%rbp), %eax
imulq $0x388, %rax, %r9       # imm = 0x388
addq 0x58(%rsp), %r9
movzbl 0x4(%rbp), %eax
imulq $0x388, %rax, %rax      # imm = 0x388
addq 0x50(%rsp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
movq 0x60(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x3da7
incl %r13d
testb %al, %al
movq %r12, %rcx
jne 0x3ace
jmp 0x3b9b
movl 0x2c(%rsp), %esi
incl %esi
incl %r15d
movl 0x24(%rsp), %edx
jmp 0x3abf
incq %r14
jmp 0x3a5f
addl 0x20(%rsp), %ecx
jmp 0x3a15
movq 0x18(%rsp), %rcx
addl %eax, %ecx
movq %rcx, %rax
jmp 0x3a02
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq