// File: dannye[P]jed/src/encoder.cpp
// Function: RGBToYCbCrBlock(Block&)
void RGBToYCbCrBlock(Block& block) {
    for (uint y = 0; y < 8; ++y) {
        for (uint x = 0; x < 8; ++x) {
            const uint pixel = y * 8 + x;
            int y  =  0.2990 * block.r[pixel] + 0.5870 * block.g[pixel] + 0.1140 * block.b[pixel] - 128;
            int cb = -0.1687 * block.r[pixel] - 0.3313 * block.g[pixel] + 0.5000 * block.b[pixel];
            int cr =  0.5000 * block.r[pixel] - 0.4187 * block.g[pixel] - 0.0813 * block.b[pixel];
            if (y  < -128) y  = -128;
            if (y  >  127) y  =  127;
            if (cb < -128) cb = -128;
            if (cb >  127) cb =  127;
            if (cr < -128) cr = -128;
            if (cr >  127) cr =  127;
            block.y[pixel]  = y;
            block.cb[pixel] = cb;
            block.cr[pixel] = cr;
        }
    }
}

// Assembly:
movq %rdi, -0x8(%rsp)
movl $0x0, -0xc(%rsp)
cmpl $0x8, -0xc(%rsp)
jae 0x307a
movl $0x0, -0x10(%rsp)
cmpl $0x8, -0x10(%rsp)
jae 0x3068
movl -0xc(%rsp), %eax
shll $0x3, %eax
addl -0x10(%rsp), %eax
movl %eax, -0x14(%rsp)
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl (%rax,%rcx,4), %xmm1
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl 0x100(%rax,%rcx,4), %xmm2
movsd 0x4206(%rip), %xmm0     # 0x7088
mulsd %xmm2, %xmm0
movsd 0x41f2(%rip), %xmm2     # 0x7080
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl 0x200(%rax,%rcx,4), %xmm0
movsd 0x41c8(%rip), %xmm2     # 0x7078
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x41b0(%rip), %xmm1     # 0x7070
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x18(%rsp)
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl (%rax,%rcx,4), %xmm1
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl 0x100(%rax,%rcx,4), %xmm2
movsd 0x4174(%rip), %xmm0     # 0x7068
mulsd %xmm2, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x4149(%rip), %xmm2     # 0x7060
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl 0x200(%rax,%rcx,4), %xmm0
movsd 0x4117(%rip), %xmm2     # 0x7050
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rsp)
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl (%rax,%rcx,4), %xmm1
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl 0x100(%rax,%rcx,4), %xmm2
movsd 0x40e7(%rip), %xmm0     # 0x7058
mulsd %xmm2, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x40bc(%rip), %xmm2     # 0x7050
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
cvtsi2sdl 0x200(%rax,%rcx,4), %xmm0
movsd 0x4092(%rip), %xmm2     # 0x7048
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x20(%rsp)
cmpl $-0x80, -0x18(%rsp)
jge 0x2fd5
movl $0xffffff80, -0x18(%rsp) # imm = 0xFFFFFF80
cmpl $0x7f, -0x18(%rsp)
jle 0x2fe4
movl $0x7f, -0x18(%rsp)
cmpl $-0x80, -0x1c(%rsp)
jge 0x2ff3
movl $0xffffff80, -0x1c(%rsp) # imm = 0xFFFFFF80
cmpl $0x7f, -0x1c(%rsp)
jle 0x3002
movl $0x7f, -0x1c(%rsp)
cmpl $-0x80, -0x20(%rsp)
jge 0x3011
movl $0xffffff80, -0x20(%rsp) # imm = 0xFFFFFF80
cmpl $0x7f, -0x20(%rsp)
jle 0x3020
movl $0x7f, -0x20(%rsp)
movl -0x18(%rsp), %edx
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rsp), %edx
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
movl %edx, 0x100(%rax,%rcx,4)
movl -0x20(%rsp), %edx
movq -0x8(%rsp), %rax
movl -0x14(%rsp), %ecx
movl %edx, 0x200(%rax,%rcx,4)
movl -0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rsp)
jmp 0x2e40
jmp 0x306a
movl -0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rsp)
jmp 0x2e2d
retq
nopl (%rax,%rax)