// File: 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:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq 0x38(%rsp), %rax
movl 0x64(%rax), %eax
movl %eax, 0x34(%rsp)
cmpl $0x3, 0x34(%rsp)
jge 0xa0e6
movb $0x0, 0x47(%rsp)
jmp 0xa35b
movq 0x38(%rsp), %rax
movl 0x6c(%rax), %eax
movl %eax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x2c(%rsp), %eax
jl 0xa19c
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x28(%rsp), %eax
jl 0xa19c
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x2c(%rsp), %eax
jl 0xa19c
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x28(%rsp), %eax
jge 0xa1b4
leaq 0x3c84d(%rip), %rdi     # 0x469f0
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x47(%rsp)
jmp 0xa35b
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x28(%rsp), %eax
jge 0xa356
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0xa344
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movl %eax, 0x14(%rsp)
movl 0x1c(%rsp), %eax
addl 0x14(%rsp), %eax
sarl %eax
addl 0x18(%rsp), %eax
sarl %eax
movl %eax, 0x10(%rsp)
movl 0x1c(%rsp), %eax
subl 0x14(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
addl 0x14(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movl %eax, 0x8(%rsp)
movl 0x10(%rsp), %eax
movw %ax, 0x2(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq 0x12110
movw 0x2(%rsp), %cx
movw %cx, (%rax)
movl 0xc(%rsp), %eax
movw %ax, 0x4(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq 0x12110
movw 0x4(%rsp), %cx
movw %cx, (%rax)
movl 0x8(%rsp), %eax
movw %ax, 0x6(%rsp)
movq 0x38(%rsp), %rdi
movl 0x30(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x24(%rsp), %esi
movl 0x20(%rsp), %edx
callq 0x12110
movw 0x6(%rsp), %cx
movw %cx, (%rax)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xa1d2
jmp 0xa346
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xa1bc
movb $0x1, 0x47(%rsp)
movb 0x47(%rsp), %al
andb $0x1, %al
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)