// File: cloudinary[P]fuif/transform/ycbcr.h
// Function: fwd_YCbCr(Image&)
bool fwd_YCbCr(Image &input) {
    int nb_channels = input.channel.size();
    if (nb_channels < 3) {
        e_printf("Invalid number of channels to apply 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 YCbCr.\n");
        return false;
    }

    float half = (input.maxval+1)/2;
    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
        float r = input.channel[0].value(y,x);
        float g = input.channel[1].value(y,x);
        float b = input.channel[2].value(y,x);

        input.channel[0].value(y,x) = CLAMP(0.299*r + 0.587*g + 0.114*b, input.minval, input.maxval);
        input.channel[1].value(y,x) = CLAMP(half - 0.168736*r - 0.331264*g + 0.5*b, input.minval, input.maxval);
        input.channel[2].value(y,x) = CLAMP(half + 0.5*r - 0.418688*g - 0.081312*b, 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 0x67dc
leaq 0x3ff1e(%rip), %rdi     # 0x466e6
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x87(%rsp)
jmp 0x6e11
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 0x6866
movq 0x78(%rsp), %rdi
movl $0x1, %esi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x6c(%rsp), %eax
jl 0x6866
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x70(%rsp), %eax
jl 0x6866
movq 0x78(%rsp), %rdi
movl $0x2, %esi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x6c(%rsp), %eax
jge 0x6881
leaq 0x3fea5(%rip), %rdi     # 0x46712
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x87(%rsp)
jmp 0x6e11
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 0x6e09
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0x70(%rsp), %eax
jge 0x6df7
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
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
movss %xmm0, 0x54(%rsp)
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm2
movsd 0x3f84f(%rip), %xmm1    # 0x461b8
mulsd %xmm2, %xmm1
movsd 0x3f83b(%rip), %xmm2    # 0x461b0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x54(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f819(%rip), %xmm2    # 0x461a8
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x69bc
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x6a84
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm2
movsd 0x3f7e0(%rip), %xmm0    # 0x461b8
mulsd %xmm2, %xmm0
movsd 0x3f7cc(%rip), %xmm2    # 0x461b0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f7aa(%rip), %xmm2    # 0x461a8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6a28
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x6a78
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm2
movsd 0x3f774(%rip), %xmm0    # 0x461b8
mulsd %xmm2, %xmm0
movsd 0x3f760(%rip), %xmm2    # 0x461b0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f73e(%rip), %xmm2    # 0x461a8
mulsd %xmm2, %xmm0
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 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x5c(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f6f3(%rip), %xmm2    # 0x461c8
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f6d1(%rip), %xmm2    # 0x461c0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x54(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f677(%rip), %xmm2    # 0x46180
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6b36
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
jmp 0x6c1a
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f676(%rip), %xmm2    # 0x461c8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f654(%rip), %xmm2    # 0x461c0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f5fa(%rip), %xmm2    # 0x46180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6bb0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
jmp 0x6c0e
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f5fc(%rip), %xmm2    # 0x461c8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f5da(%rip), %xmm2    # 0x461c0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f580(%rip), %xmm2    # 0x46180
mulsd %xmm2, %xmm0
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 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x5c(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f514(%rip), %xmm2    # 0x46180
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x58(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f552(%rip), %xmm2    # 0x461d8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x54(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f530(%rip), %xmm2    # 0x461d0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6ccd
movq 0x78(%rsp), %rax
cvtsi2sdl 0x5c(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x6db1
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f497(%rip), %xmm2    # 0x46180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f4d5(%rip), %xmm2    # 0x461d8
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f4b3(%rip), %xmm2    # 0x461d0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6d47
movq 0x78(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x6da5
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x5c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f41d(%rip), %xmm2    # 0x46180
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movss 0x58(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x3f45b(%rip), %xmm2    # 0x461d8
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3f439(%rip), %xmm2    # 0x461d0
mulsd %xmm2, %xmm0
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 0x68bc
jmp 0x6df9
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x68a6
movb $0x1, 0x87(%rsp)
movb 0x87(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)