// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
cmpl $0x3, 0x64(%rdi)
jge 0x3bac
leaq 0x19e10(%rip), %rdi     # 0x1d9ba
jmp 0x3c07
movq %rdi, %rbx
movslq 0x6c(%rdi), %rdx
movq (%rdi), %rax
movq %rdx, %rbp
shlq $0x6, %rbp
movl 0x18(%rax,%rbp), %ecx
leaq 0x1(%rdx), %r12
shlq $0x6, %r12
leaq 0x19e1e(%rip), %rdi     # 0x1d9ee
cmpl %ecx, 0x18(%rax,%r12)
jl 0x3c07
movq %rdx, %r8
movl %ecx, %edx
movl 0x1c(%rax,%rbp), %esi
leaq (%rax,%r12), %rcx
cmpl %esi, 0x1c(%rcx)
jl 0x3c07
addq $0x2, %r8
shlq $0x6, %r8
movq %r8, 0x8(%rsp)
cmpl %edx, 0x18(%rax,%r8)
jl 0x3c07
addq 0x8(%rsp), %rax
cmpl %esi, 0x1c(%rax)
jge 0x3c21
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x16b80
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %edx
movl %edx, 0x20(%rsp)
testl %esi, %esi
cmovlel %eax, %esi
xorl %r13d, %r13d
movl %esi, 0x1c(%rsp)
movq %rbx, 0x10(%rsp)
movq %rbp, 0x30(%rsp)
movq %r12, 0x28(%rsp)
cmpl %esi, %r13d
je 0x3dc1
xorl %r15d, %r15d
movl %r13d, 0x4(%rsp)
cmpl %r15d, 0x20(%rsp)
je 0x3db9
movq (%rbx), %rdi
addq %rbp, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0xa44a
cmpw $0x0, (%rax)
js 0x3cb6
movq (%rbx), %rdi
addq %rbp, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0xa44a
movswl (%rax), %eax
movl %r15d, %ecx
movl 0x60(%rbx), %r15d
cmpl %eax, %r15d
jl 0x3cbc
movq (%rbx), %rdi
addq %rbp, %rdi
movl %r13d, %esi
movl %ecx, %r15d
movl %ecx, %edx
callq 0xa44a
movl %r15d, %ecx
movswl (%rax), %r15d
jmp 0x3cbc
movl %r15d, %ecx
xorl %r15d, %r15d
movq (%rbx), %rdi
addq %r12, %rdi
movl %r13d, %esi
movl %ecx, %r14d
movl %ecx, %edx
movl %ecx, 0x24(%rsp)
callq 0xa44a
movswl (%rax), %ebp
movq (%rbx), %rdi
addq 0x8(%rsp), %rdi
movl %r13d, %esi
movl %r14d, %edx
callq 0xa44a
movswl (%rax), %eax
movl %eax, %ecx
negl %ecx
sarl %ecx
movl %r15d, %ebx
subl %ecx, %ebx
movq 0x10(%rsp), %rcx
movl 0x60(%rcx), %r12d
cmpl %r12d, %ebx
movl %r12d, %r13d
cmovll %ebx, %r13d
pushq $0x1
popq %rcx
subl %eax, %ecx
sarl %ecx
movl %ebp, %eax
sarl %eax
subl %eax, %r15d
addl %ecx, %r15d
cmpl %r12d, %r15d
movl %r12d, %r14d
cmovll %r15d, %r14d
testl %r15d, %r15d
movl $0x0, %eax
cmovsl %eax, %r14d
addl %r14d, %ebp
cmpl %r12d, %ebp
cmovll %ebp, %r12d
testl %ebp, %ebp
movq 0x30(%rsp), %rbp
cmovsl %eax, %r12d
movq 0x10(%rsp), %rax
movq (%rax), %rdi
addq %rbp, %rdi
movl 0x4(%rsp), %esi
movl 0x24(%rsp), %r15d
movl %r15d, %edx
callq 0xa44a
testl %ebx, %ebx
movq 0x10(%rsp), %rbx
movw %r12w, (%rax)
movl $0x0, %eax
cmovsl %eax, %r13d
movq (%rbx), %rdi
movq 0x28(%rsp), %r12
addq %r12, %rdi
movl 0x4(%rsp), %esi
movl %r15d, %edx
callq 0xa44a
movw %r13w, (%rax)
movl 0x4(%rsp), %r13d
movq (%rbx), %rdi
addq 0x8(%rsp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0xa44a
movw %r14w, (%rax)
incl %r15d
movl 0x1c(%rsp), %esi
jmp 0x3c58
incl %r13d
jmp 0x3c47
movb $0x1, %bl
jmp 0x3c10