// File: /workspace/github_cpp_makefile_star2_O1/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 0x4121
leaq 0x2191b(%rip), %rax     # 0x25a3a
jmp 0x417e
movslq 0x6c(%rdi), %rcx
movq (%rdi), %rdx
shlq $0x6, %rcx
movl 0x18(%rdx,%rcx), %esi
movslq 0x58(%rdx,%rcx), %r9
leaq 0x21932(%rip), %rax     # 0x25a6e
movq %rsi, (%rsp)
movq %r9, 0x48(%rsp)
cmpl %esi, %r9d
jl 0x417e
leaq (%rdx,%rcx), %rsi
movl 0x1c(%rdx,%rcx), %r8d
movq %rsi, 0x8(%rsp)
cmpl %r8d, 0x5c(%rsi)
jl 0x417e
movslq 0x98(%rdx,%rcx), %rdx
movq %rdx, 0x40(%rsp)
cmpl (%rsp), %edx
jl 0x417e
movq 0x8(%rsp), %rcx
cmpl %r8d, 0x9c(%rcx)
jge 0x419e
xorl %ebx, %ebx
movq %rax, %rdi
xorl %eax, %eax
callq 0x3796
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
testl %r8d, %r8d
jle 0x418a
movslq (%rsp), %rcx
movq 0x8(%rsp), %rax
leaq 0x24(%rax), %rdx
movq %rdx, 0x90(%rsp)
leaq 0x64(%rax), %rdx
movq %rdx, 0x88(%rsp)
addq $0xa4, %rax
movq %rax, 0x80(%rsp)
movq %rcx, 0x68(%rsp)
leaq (%rcx,%rcx), %rax
movq %rax, 0x60(%rsp)
movq 0x48(%rsp), %rax
leaq (%rax,%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x40(%rsp), %rax
addq %rax, %rax
movq %rax, 0x50(%rsp)
movq $0x0, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
movq %rdi, 0x98(%rsp)
movq %r8, 0x70(%rsp)
movq %rcx, 0x78(%rsp)
cmpl $0x0, (%rsp)
jle 0x43ce
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x8(%rax), %rcx
subq %rdx, %rcx
sarq %rcx
movq %rcx, 0xb0(%rsp)
movq 0x40(%rax), %rcx
movq 0x48(%rax), %rsi
subq %rcx, %rsi
sarq %rsi
movq %rsi, 0xa8(%rsp)
movq 0x80(%rax), %rbp
movq 0x88(%rax), %rax
subq %rbp, %rax
sarq %rax
movq %rax, 0xa0(%rsp)
addq 0x10(%rsp), %rdx
addq 0x28(%rsp), %rcx
addq 0x38(%rsp), %rbp
movq (%rsp), %r12
movq 0x30(%rsp), %r9
movq 0x20(%rsp), %r13
movq 0x18(%rsp), %rax
movq %r12, 0xb8(%rsp)
cmpq %rax, 0xb0(%rsp)
movq 0x90(%rsp), %r10
movq %rdx, 0xc0(%rsp)
cmovaq %rdx, %r10
movswl (%r10), %edx
movl 0x60(%rdi), %ebx
cmpl %edx, %ebx
movl %edx, %esi
cmovll %ebx, %esi
xorl %edi, %edi
testl %edx, %edx
cmovsl %edi, %esi
cmpq %r13, 0xa8(%rsp)
movq 0x88(%rsp), %r11
cmovaq %rcx, %r11
cmpq %r9, 0xa0(%rsp)
movq 0x80(%rsp), %r14
cmovaq %rbp, %r14
movswl (%r11), %r12d
movswl (%r14), %r15d
movl %r15d, %edi
negl %edi
sarl %edi
movl %esi, %r8d
subl %edi, %r8d
cmpl %ebx, %r8d
movl %ebx, %edi
cmovll %r8d, %edi
movl $0x1, %edx
subl %r15d, %edx
movl %r12d, %r15d
sarl %r15d
subl %r15d, %esi
sarl %edx
addl %edx, %esi
movl %esi, %r15d
cmpl %ebx, %esi
jl 0x435d
movl %ebx, %r15d
testl %esi, %esi
movl $0x0, %edx
cmovsl %edx, %r15d
addl %r15d, %r12d
movl %r12d, %esi
cmpl %ebx, %r12d
jl 0x4375
movl %ebx, %esi
movl $0x0, %ebx
testl %r12d, %r12d
movq 0xc0(%rsp), %rdx
movq 0xb8(%rsp), %r12
js 0x4391
movl %esi, %ebx
testl %r8d, %r8d
movw %bx, (%r10)
movl $0x0, %esi
cmovsl %esi, %edi
movw %di, (%r11)
movw %r15w, (%r14)
addq $0x2, %rdx
incq %rax
incq %r13
addq $0x2, %rcx
incq %r9
addq $0x2, %rbp
decq %r12
movq 0x98(%rsp), %rdi
jne 0x42bf
movq 0x78(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rax
addq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
addq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rax
addq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x70(%rsp), %r8
cmpq %r8, %rcx
jne 0x4242
movb $0x1, %bl
jmp 0x418a