// File: 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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rax
movl 0x6c(%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x58(%rsp), %rax
movl 0x64(%rax), %eax
movl %eax, 0x50(%rsp)
cmpl $0x3, 0x50(%rsp)
jge 0x9cc0
leaq 0x3ccbb(%rip), %rdi     # 0x4696a
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x67(%rsp)
jmp 0xa0b0
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
movl %eax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x4c(%rsp), %eax
jl 0x9d6a
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x48(%rsp), %eax
jl 0x9d6a
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
cmpl 0x4c(%rsp), %eax
jl 0x9d6a
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
cmpl 0x48(%rsp), %eax
jge 0x9d82
leaq 0x3cc2d(%rip), %rdi     # 0x4699e
movb $0x0, %al
callq 0x3a670
movb $0x0, 0x67(%rsp)
jmp 0xa0b0
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x48(%rsp), %eax
jge 0xa0ab
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0xa099
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
cmpl $0x0, %eax
jge 0x9de2
xorl %eax, %eax
movl %eax, 0x24(%rsp)
jmp 0x9e54
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movq 0x58(%rsp), %rcx
cmpl 0x60(%rcx), %eax
jle 0x9e21
movq 0x58(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x20(%rsp)
jmp 0x9e4c
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movl %eax, 0x38(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movswl (%rax), %eax
movl %eax, 0x34(%rsp)
movl 0x3c(%rsp), %eax
xorl %ecx, %ecx
subl 0x34(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jge 0x9ecd
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
jmp 0x9f0d
movl 0x3c(%rsp), %eax
xorl %ecx, %ecx
subl 0x34(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movq 0x58(%rsp), %rcx
cmpl 0x60(%rcx), %eax
jle 0x9ef3
movq 0x58(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x18(%rsp)
jmp 0x9f05
movl 0x3c(%rsp), %eax
xorl %ecx, %ecx
subl 0x34(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x3c(%rsp), %eax
movl $0x1, %ecx
subl 0x34(%rsp), %ecx
sarl %ecx
addl %ecx, %eax
movl 0x38(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jge 0x9f3b
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0x9f91
movl 0x3c(%rsp), %eax
movl $0x1, %ecx
subl 0x34(%rsp), %ecx
sarl %ecx
addl %ecx, %eax
movl 0x38(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movq 0x58(%rsp), %rcx
cmpl 0x60(%rcx), %eax
jle 0x9f6c
movq 0x58(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x10(%rsp)
jmp 0x9f89
movl 0x3c(%rsp), %eax
movl $0x1, %ecx
subl 0x34(%rsp), %ecx
sarl %ecx
addl %ecx, %eax
movl 0x38(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x38(%rsp), %eax
addl 0x2c(%rsp), %eax
cmpl $0x0, %eax
jge 0x9fae
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x9fe2
movl 0x38(%rsp), %eax
addl 0x2c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl 0x60(%rcx), %eax
jle 0x9fce
movq 0x58(%rsp), %rax
movl 0x60(%rax), %eax
movl %eax, 0x8(%rsp)
jmp 0x9fda
movl 0x38(%rsp), %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
movw %ax, 0x2(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movw 0x2(%rsp), %cx
movw %cx, (%rax)
movl 0x30(%rsp), %eax
movw %ax, 0x4(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movw 0x4(%rsp), %cx
movw %cx, (%rax)
movl 0x2c(%rsp), %eax
movw %ax, 0x6(%rsp)
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x44(%rsp), %esi
movl 0x40(%rsp), %edx
callq 0x12110
movw 0x6(%rsp), %cx
movw %cx, (%rax)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x9da0
jmp 0xa09b
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x9d8a
movb $0x1, 0x67(%rsp)
movb 0x67(%rsp), %al
andb $0x1, %al
addq $0x68, %rsp
retq
nopl (%rax,%rax)