// File: /workspace/github_cpp_makefile_star2_O3/cloudinary[P]fuif/transform/ycocg.h
// Function: inv_YCoCg(Image&)
bool inv_YCoCg(Image &input) {
    int m = input.nb_meta_channels;
    int nb_channels = input.nb_channels;
    if (nb_channels < 3) {
        e_printf("Invalid number of channels to apply inverse YCoCg.\n");
        return false;
    }
    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 inverse YCoCg (maybe chroma is subsampled?).\n");
        return false;
    }
    for (int y=0; y<h; y++) {
      for (int x=0; x<w; x++) {
        int Y = CLAMP(input.channel[m+0].value(y,x), 0, input.maxval);
        int Co = input.channel[m+1].value(y,x);
        int Cg = input.channel[m+2].value(y,x);
        int G = CLAMP(Y - ((-Cg)>>1), 0, input.maxval);
        int B = CLAMP(Y + ((1-Cg)>>1) - (Co>>1), 0, input.maxval);
        int R = CLAMP(Co + B, 0, input.maxval);
        input.channel[m+0].value(y,x) = R;
        input.channel[m+1].value(y,x) = G;
        input.channel[m+2].value(y,x) = B;
      }
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
cmpl $0x3, 0x64(%rdi)
jge 0x4131
leaq 0x2190b(%rip), %rax     # 0x25a3a
jmp 0x4181
movslq 0x6c(%rdi), %rcx
movq (%rdi), %rdx
shlq $0x6, %rcx
movl 0x18(%rdx,%rcx), %esi
movslq 0x58(%rdx,%rcx), %r9
leaq 0x21922(%rip), %rax     # 0x25a6e
movq %rsi, (%rsp)
movq %r9, 0x40(%rsp)
cmpl %esi, %r9d
jl 0x4181
leaq (%rdx,%rcx), %rsi
movl 0x1c(%rdx,%rcx), %ecx
cmpl %ecx, 0x5c(%rsi)
jl 0x4181
movslq 0x98(%rsi), %r8
movq %r8, 0x38(%rsp)
cmpl (%rsp), %r8d
jl 0x4181
cmpl %ecx, 0x9c(%rsi)
jge 0x41a1
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x379e
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
testl %ecx, %ecx
jle 0x418d
movslq (%rsp), %rax
leaq 0x24(%rsi), %rdx
movq %rdx, 0x90(%rsp)
leaq 0x64(%rsi), %rdx
movq %rdx, 0x88(%rsp)
movq %rsi, 0x48(%rsp)
leaq 0xa4(%rsi), %rdx
movq %rdx, 0x80(%rsp)
movq %rax, 0x68(%rsp)
addq %rax, %rax
movq %rax, 0x60(%rsp)
movq 0x40(%rsp), %rax
leaq (%rax,%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x38(%rsp), %rax
addq %rax, %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
xorl %edx, %edx
movq %rdi, 0x98(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdx, 0x78(%rsp)
cmpl $0x0, (%rsp)
jle 0x43cd
movq 0x48(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq %rdx
movq %rdx, 0xb0(%rsp)
movq 0x48(%rax), %rdx
movq 0x40(%rax), %rsi
subq %rsi, %rdx
sarq %rdx
movq %rdx, 0xa8(%rsp)
movq 0x88(%rax), %rdx
movq 0x80(%rax), %r12
subq %r12, %rdx
sarq %rdx
movq %rdx, 0xa0(%rsp)
addq 0x8(%rsp), %rcx
addq 0x20(%rsp), %rsi
addq 0x30(%rsp), %r12
movq (%rsp), %rdx
movq 0x28(%rsp), %r9
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %rax
movq %rdx, 0xb8(%rsp)
cmpq %rax, 0xb0(%rsp)
movq 0x90(%rsp), %r10
movq %rcx, 0xc0(%rsp)
cmovaq %rcx, %r10
movswl (%r10), %edx
movl 0x60(%rdi), %ebx
cmpl %edx, %ebx
movl %edx, %ecx
cmovll %ebx, %ecx
xorl %edi, %edi
testl %edx, %edx
cmovsl %edi, %ecx
cmpq %r13, 0xa8(%rsp)
movq 0x88(%rsp), %r11
cmovaq %rsi, %r11
cmpq %r9, 0xa0(%rsp)
movq 0x80(%rsp), %r14
cmovaq %r12, %r14
movswl (%r11), %ebp
movswl (%r14), %r15d
movl %r15d, %edi
negl %edi
sarl %edi
movl %ecx, %r8d
subl %edi, %r8d
cmpl %ebx, %r8d
movl %ebx, %edi
cmovll %r8d, %edi
movl $0x1, %edx
subl %r15d, %edx
movl %ebp, %r15d
sarl %r15d
subl %r15d, %ecx
sarl %edx
addl %edx, %ecx
movl %ecx, %r15d
cmpl %ebx, %ecx
jl 0x435f
movl %ebx, %r15d
testl %ecx, %ecx
movl $0x0, %ecx
cmovsl %ecx, %r15d
addl %r15d, %ebp
movl %ebp, %ecx
cmpl %ebx, %ebp
jl 0x4375
movl %ebx, %ecx
movl $0x0, %ebx
testl %ebp, %ebp
movq 0xb8(%rsp), %rdx
js 0x4388
movl %ecx, %ebx
testl %r8d, %r8d
movw %bx, (%r10)
movl $0x0, %ecx
cmovsl %ecx, %edi
movw %di, (%r11)
movw %r15w, (%r14)
movq 0xc0(%rsp), %rcx
addq $0x2, %rcx
incq %rax
incq %r13
addq $0x2, %rsi
incq %r9
addq $0x2, %r12
decq %rdx
movq 0x98(%rsp), %rdi
jne 0x42c1
movq 0x78(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %rax
addq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
addq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rcx
cmpq %rcx, %rdx
jne 0x4244
movb $0x1, %bl
jmp 0x418d