// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/transform/ycocg.h
// Function: fwd_YCoCg(Image&)
bool fwd_YCoCg(Image &input) {
    int nb_channels = input.nb_channels;
    if (nb_channels < 3) {
        //e_printf("Invalid number of channels to apply YCoCg.\n");
        return false;
    }
    int m = input.nb_meta_channels;
    int w = input.channel[m+0].w;
    int h = input.channel[m+0].h;
    if (input.channel[m+1].w < w
     || input.channel[m+1].h < h
     || input.channel[m+2].w < w
     || input.channel[m+2].h < h) {
        e_printf("Invalid channel dimensions to apply YCoCg.\n");
        return false;
    }
    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
        int R = input.channel[m+0].value(y,x);
        int G = input.channel[m+1].value(y,x);
        int B = input.channel[m+2].value(y,x);
        int Y = (((R + B)>>1) + G)>>1;
        int Co = R - B;
        int Cg = G - ((R + B)>>1);
        input.channel[m+0].value(y,x) = Y;
        input.channel[m+1].value(y,x) = Co;
        input.channel[m+2].value(y,x) = Cg;
      }
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
cmpl $0x3, 0x64(%rdi)
jge 0x8dc5
xorl %ebx, %ebx
jmp 0x8e33
movslq 0x6c(%rdi), %rax
movq (%rdi), %rcx
shlq $0x6, %rax
movl 0x18(%rcx,%rax), %edx
movslq 0x58(%rcx,%rax), %rdi
movq %rdx, 0x8(%rsp)
movq %rdi, 0x58(%rsp)
cmpl %edx, %edi
jl 0x8e23
leaq (%rcx,%rax), %rdx
movl 0x1c(%rcx,%rax), %esi
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
cmpl %esi, 0x5c(%rdx)
jl 0x8e23
movslq 0x98(%rcx,%rax), %rcx
movq %rcx, 0x50(%rsp)
cmpl 0x8(%rsp), %ecx
jl 0x8e23
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpl %ecx, 0x9c(%rax)
jge 0x8e47
leaq 0x1cc96(%rip), %rdi     # 0x25ac0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x3796
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
cmpl $0x0, 0x18(%rsp)
jle 0x8e33
movslq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
leaq 0x24(%rax), %r9
leaq 0x64(%rax), %r10
leaq 0xa4(%rax), %rsi
movq %rcx, 0x78(%rsp)
leaq (%rcx,%rcx), %rax
movq %rax, 0x70(%rsp)
movq 0x58(%rsp), %rax
addq %rax, %rax
movq %rax, 0x68(%rsp)
movq 0x50(%rsp), %rax
addq %rax, %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ecx, %ecx
movq %r9, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x8ff0
movq 0x10(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq %rdx
movq %rdx, 0xa8(%rsp)
movq 0x40(%rax), %rbx
movq 0x48(%rax), %rdx
subq %rbx, %rdx
sarq %rdx
movq %rdx, 0xa0(%rsp)
movq 0x80(%rax), %rdx
movq 0x88(%rax), %rax
subq %rdx, %rax
sarq %rax
movq %rax, 0x98(%rsp)
addq 0x20(%rsp), %rcx
addq 0x38(%rsp), %rbx
addq 0x48(%rsp), %rdx
movq 0x8(%rsp), %r14
movq 0x40(%rsp), %rbp
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r8
movq %rcx, 0xb0(%rsp)
cmpq %r8, 0xa8(%rsp)
movq 0x90(%rsp), %r9
cmovaq %rcx, %r9
movswl (%r9), %edi
cmpq %r15, 0xa0(%rsp)
movq %r10, %rsi
cmovaq %rbx, %r10
cmpq %rbp, 0x98(%rsp)
movq 0x88(%rsp), %r11
cmovaq %rdx, %r11
movswl (%r10), %r12d
movswl (%r11), %ecx
leal (%rcx,%rdi), %eax
movl %eax, %r13d
sarl %eax
addl %r12d, %eax
shrl %eax
movw %ax, (%r9)
subl %ecx, %edi
movq 0xb0(%rsp), %rcx
movw %di, (%r10)
movq %rsi, %r10
shrl %r13d
subl %r13d, %r12d
movw %r12w, (%r11)
addq $0x2, %rcx
incq %r8
incq %r15
addq $0x2, %rbx
incq %rbp
addq $0x2, %rdx
decq %r14
jne 0x8f5b
movq 0x80(%rsp), %rcx
incq %rcx
movq 0x20(%rsp), %rax
addq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
addq 0x78(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
addq 0x60(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq 0x18(%rsp), %rcx
jne 0x8ed9
movb $0x1, %bl
jmp 0x8e33