// File: cloudinary[P]fuif/transform/ycbcr.h
// Function: inv_YCbCr(Image&)
bool inv_YCbCr(Image &input) {
    int nb_channels = input.channel.size();
    if (nb_channels < 3) {
        e_printf("Invalid number of channels to apply inverse YCbCr.\n");
        return false;
    }
    int w = input.channel[0].w;
    int h = input.channel[0].h;
    if (input.channel[1].w < w
     || input.channel[1].h < h
     || input.channel[2].w < w
     || input.channel[2].h < h) {
        e_printf("Invalid channel dimensions to apply inverse YCbCr (maybe chroma is subsampled?).\n");
        return false;
    }

    float half = (input.maxval+1)/2;
    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
        float yy = input.channel[0].value(y,x);
        float cb = input.channel[1].value(y,x) - half;
        float cr = input.channel[2].value(y,x) - half;

        input.channel[0].value(y,x) = CLAMP(yy + 1.402*cr + 0.5, input.minval, input.maxval);
        input.channel[1].value(y,x) = CLAMP(yy - 0.344136*cb - 0.714136*cr  + 0.5, input.minval, input.maxval);
        input.channel[2].value(y,x) = CLAMP(yy + 1.772*cb  + 0.5, input.minval, input.maxval);
      }
    }

    return true;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq 0x78(%rsp), %rdi
callq 0x4b80
movl %eax, 0x74(%rsp)
cmpl $0x3, 0x74(%rsp)
jge 0x623c
leaq 0x40438(%rip), %rdi     # 0x46660
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x87(%rsp)
jmp 0x678d
movq 0x78(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4ba0
movl 0x18(%rax), %eax
movl %eax, 0x70(%rsp)
movq 0x78(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4ba0
movl 0x1c(%rax), %eax
movl %eax, 0x6c(%rsp)
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x70(%rsp), %eax
jl 0x62c6
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x6c(%rsp), %eax
jl 0x62c6
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x70(%rsp), %eax
jl 0x62c6
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x6c(%rsp), %eax
jge 0x62e1
leaq 0x403c7(%rip), %rdi     # 0x46694
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x87(%rsp)
jmp 0x678d
movq 0x78(%rsp), %rax
movl 0x60(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x6785
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0x70(%rsp), %eax
jge 0x6773
movq 0x78(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4ba0
movq %rax, %rdi
movl 0x64(%rsp), %esi
movl 0x60(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x5c(%rsp)
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x4ba0
movq %rax, %rdi
movl 0x64(%rsp), %esi
movl 0x60(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
cvtsi2ss %eax, %xmm0
subss 0x68(%rsp), %xmm0
movss %xmm0, 0x58(%rsp)
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x4ba0
movq %rax, %rdi
movl 0x64(%rsp), %esi
movl 0x60(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
cvtsi2ss %eax, %xmm0
subss 0x68(%rsp), %xmm0
movss %xmm0, 0x54(%rsp)
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x54(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3fdb3(%rip), %xmm2    # 0x46188
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x3fd9b(%rip), %xmm0    # 0x46180
addsd %xmm0, %xmm1
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x640e
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x64a2
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fd5e(%rip), %xmm2    # 0x46188
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x3fd46(%rip), %xmm1    # 0x46180
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6460
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x6496
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fd0c(%rip), %xmm2    # 0x46188
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x3fcf4(%rip), %xmm1    # 0x46180
addsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movw %ax, 0x3e(%rsp)
movq 0x78(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4ba0
movq %rax, %rdi
movl 0x64(%rsp), %esi
movl 0x60(%rsp), %edx
callq 0x12110
movw 0x3e(%rsp), %cx
movw %cx, (%rax)
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fca5(%rip), %xmm2    # 0x46198
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x54(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3fc83(%rip), %xmm2    # 0x46190
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x3fc63(%rip), %xmm0    # 0x46180
addsd %xmm0, %xmm1
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6546
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
jmp 0x660e
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3fc36(%rip), %xmm2    # 0x46198
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fc14(%rip), %xmm2    # 0x46190
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x3fbf4(%rip), %xmm1    # 0x46180
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x65b2
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0x6602
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3fbca(%rip), %xmm2    # 0x46198
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fba8(%rip), %xmm2    # 0x46190
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x3fb88(%rip), %xmm1    # 0x46180
addsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movw %ax, 0x26(%rsp)
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x4ba0
movq %rax, %rdi
movl 0x64(%rsp), %esi
movl 0x60(%rsp), %edx
callq 0x12110
movw 0x26(%rsp), %cx
movw %cx, (%rax)
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3fb40(%rip), %xmm2    # 0x461a0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x3fb10(%rip), %xmm0    # 0x46180
addsd %xmm0, %xmm1
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6699
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x672d
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3faeb(%rip), %xmm2    # 0x461a0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x3fabb(%rip), %xmm1    # 0x46180
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x66eb
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x6721
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fa99(%rip), %xmm2    # 0x461a0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x3fa69(%rip), %xmm1    # 0x46180
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movw %ax, 0xe(%rsp)
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x4ba0
movq %rax, %rdi
movl 0x64(%rsp), %esi
movl 0x60(%rsp), %edx
callq 0x12110
movw 0xe(%rsp), %cx
movw %cx, (%rax)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x631c
jmp 0x6775
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x6306
movb $0x1, 0x87(%rsp)
movb 0x87(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
nop