// File: dannye[P]jed/src/decoder.cpp
// Function: YCbCrToRGBBlock(Block&, Block const&, unsigned int, unsigned int, unsigned int, unsigned int)
void YCbCrToRGBBlock(Block& yBlock, const Block& cbcrBlock, const uint vSamp, const uint hSamp, const uint v, const uint h) {
    for (uint y = 7; y < 8; --y) {
        for (uint x = 7; x < 8; --x) {
            const uint pixel = y * 8 + x;
            const uint cbcrPixelRow = y / vSamp + 4 * v;
            const uint cbcrPixelColumn = x / hSamp + 4 * h;
            const uint cbcrPixel = cbcrPixelRow * 8 + cbcrPixelColumn;
            int r = yBlock.y[pixel]                                    + 1.402f * cbcrBlock.cr[cbcrPixel] + 128;
            int g = yBlock.y[pixel] - 0.344f * cbcrBlock.cb[cbcrPixel] - 0.714f * cbcrBlock.cr[cbcrPixel] + 128;
            int b = yBlock.y[pixel] + 1.772f * cbcrBlock.cb[cbcrPixel]                                    + 128;
            if (r < 0)   r = 0;
            if (r > 255) r = 255;
            if (g < 0)   g = 0;
            if (g > 255) g = 255;
            if (b < 0)   b = 0;
            if (b > 255) b = 255;
            yBlock.r[pixel] = r;
            yBlock.g[pixel] = g;
            yBlock.b[pixel] = b;
        }
    }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movl %edx, -0x14(%rsp)
movl %ecx, -0x18(%rsp)
movl %r8d, -0x1c(%rsp)
movl %r9d, -0x20(%rsp)
movl $0x7, -0x24(%rsp)
cmpl $0x8, -0x24(%rsp)
jae 0x6fb9
movl $0x7, -0x28(%rsp)
cmpl $0x8, -0x28(%rsp)
jae 0x6fa7
movl -0x24(%rsp), %eax
shll $0x3, %eax
addl -0x28(%rsp), %eax
movl %eax, -0x2c(%rsp)
movl -0x24(%rsp), %eax
xorl %edx, %edx
divl -0x14(%rsp)
movl -0x1c(%rsp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rsp)
movl -0x28(%rsp), %eax
xorl %edx, %edx
divl -0x18(%rsp)
movl -0x20(%rsp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
movl %eax, -0x34(%rsp)
movl -0x30(%rsp), %eax
shll $0x3, %eax
addl -0x34(%rsp), %eax
movl %eax, -0x38(%rsp)
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
cvtsi2ssl (%rax,%rcx,4), %xmm1
movq -0x10(%rsp), %rax
movl -0x38(%rsp), %ecx
cvtsi2ssl 0x200(%rax,%rcx,4), %xmm0
movss 0x2226(%rip), %xmm2     # 0x905c
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss 0x2206(%rip), %xmm1     # 0x904c
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x3c(%rsp)
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
cvtsi2ssl (%rax,%rcx,4), %xmm0
movq -0x10(%rsp), %rax
movl -0x38(%rsp), %ecx
cvtsi2ssl 0x100(%rax,%rcx,4), %xmm1
movss 0x21de(%rip), %xmm2     # 0x9058
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movq -0x10(%rsp), %rax
movl -0x38(%rsp), %ecx
cvtsi2ssl 0x200(%rax,%rcx,4), %xmm0
movss 0x21b8(%rip), %xmm2     # 0x9054
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss 0x21a0(%rip), %xmm1     # 0x904c
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x40(%rsp)
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
cvtsi2ssl (%rax,%rcx,4), %xmm1
movq -0x10(%rsp), %rax
movl -0x38(%rsp), %ecx
cvtsi2ssl 0x100(%rax,%rcx,4), %xmm0
movss 0x2170(%rip), %xmm2     # 0x9050
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss 0x215c(%rip), %xmm1     # 0x904c
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x44(%rsp)
cmpl $0x0, -0x3c(%rsp)
jge 0x6f0b
movl $0x0, -0x3c(%rsp)
cmpl $0xff, -0x3c(%rsp)
jle 0x6f1d
movl $0xff, -0x3c(%rsp)
cmpl $0x0, -0x40(%rsp)
jge 0x6f2c
movl $0x0, -0x40(%rsp)
cmpl $0xff, -0x40(%rsp)
jle 0x6f3e
movl $0xff, -0x40(%rsp)
cmpl $0x0, -0x44(%rsp)
jge 0x6f4d
movl $0x0, -0x44(%rsp)
cmpl $0xff, -0x44(%rsp)
jle 0x6f5f
movl $0xff, -0x44(%rsp)
movl -0x3c(%rsp), %edx
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x40(%rsp), %edx
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %edx, 0x100(%rax,%rcx,4)
movl -0x44(%rsp), %edx
movq -0x8(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %edx, 0x200(%rax,%rcx,4)
movl -0x28(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rsp)
jmp 0x6db7
jmp 0x6fa9
movl -0x24(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x6da4
retq
nopw (%rax,%rax)