// File: cloudinary[P]fuif/transform/squeeze.h
// Function: inv_vsqueeze(Image&, int, int)
void inv_vsqueeze(Image &input, int c, int rc) {
    const Channel &chin = input.channel[c];
    const Channel &chin_residual = input.channel[rc];
    Channel chout(chin.w, chin.h + chin_residual.h,chin.minval,chin.maxval, chin.q, chin.hshift,chin.vshift-1,chin.hcshift,chin.vcshift-1);
    chout.component = chin.component;
    v_printf(4,"Undoing vertical squeeze of channel %i using residuals in channel %i (going from height %i to %i)\n",c,rc,chin.h,chout.h);

      for (int x=0; x<chin.w; x++) {
        pixel_type diff_minus_tendency = chin_residual.value(0,x);
        pixel_type avg = chin.value_nocheck(0,x);

        pixel_type next_avg = avg;
        if (1<chin.h) next_avg = chin.value_nocheck(1,x);

        pixel_type tendency=smooth_tendency(avg,avg,next_avg);

        pixel_type diff = diff_minus_tendency + tendency;

        pixel_type A = ((avg<<1)+diff+(diff>0?-(diff&1):(diff&1)))>>1;
        chout.value(0,x) = A;
        pixel_type B = A-diff;
        chout.value(1,x) = B;
      }

    for (int y=1; y<chin_residual.h; y++) {
      for (int x=0; x<chin.w; x++) {
        pixel_type diff_minus_tendency = chin_residual.value(y,x);
        pixel_type avg = chin.value_nocheck(y,x);

        pixel_type next_avg = avg;
        if (y+1<chin.h) next_avg = chin.value_nocheck(y+1,x);

//        pixel_type top = (y>0 ? chout.value_nocheck((y<<1)-1,x) : avg);
        pixel_type top = chout.value_nocheck((y<<1)-1,x);
        pixel_type tendency=smooth_tendency(top,avg,next_avg);

        pixel_type diff = diff_minus_tendency + tendency;

        pixel_type A = ((avg<<1)+diff+(diff>0?-(diff&1):(diff&1)))>>1;
        chout.value(y<<1,x) = A;
        pixel_type B = A-diff;
        chout.value((y<<1)+1,x) = B;
      }
    }
    if (chout.h & 1) { int y = chin.h-1;
      for (int x=0; x<chin.w; x++) {
        pixel_type avg = chin.value(y,x);
        chout.value(y<<1,x) = avg;
      }
    }
    input.channel[c] = chout;
}

// Assembly:
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rdi, 0x138(%rsp)
movl %esi, 0x134(%rsp)
movl %edx, 0x130(%rsp)
movq 0x138(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0x4ba0
movq %rax, 0x128(%rsp)
movq 0x138(%rsp), %rdi
movslq 0x130(%rsp), %rsi
callq 0x4ba0
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0x18(%rax), %esi
movl 0x1c(%rax), %edx
movq 0x120(%rsp), %rcx
movl 0x1c(%rcx), %ecx
addl %ecx, %edx
movswl 0x20(%rax), %ecx
movswl 0x22(%rax), %r8d
movl 0x28(%rax), %r9d
movl 0x2c(%rax), %edi
movl 0x30(%rax), %r10d
decl %r10d
movl 0x34(%rax), %r11d
movl 0x38(%rax), %ebx
decl %ebx
movq %rsp, %rax
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %edi, (%rax)
leaq 0xe0(%rsp), %rdi
callq 0x12200
movq 0x128(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x11c(%rsp)
movl 0x134(%rsp), %edx
movl 0x130(%rsp), %ecx
movq 0x128(%rsp), %rax
movl 0x1c(%rax), %r8d
movl 0xfc(%rsp), %r9d
leaq 0x3a64b(%rip), %rsi     # 0x46bae
xorl %eax, %eax
movl $0x4, %edi
callq 0x3a770
jmp 0xc571
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xc7c9
movq 0x120(%rsp), %rdi
movl 0xd0(%rsp), %edx
xorl %esi, %esi
callq 0x12ba0
movw %ax, 0x8e(%rsp)
jmp 0xc5b4
movw 0x8e(%rsp), %ax
movw %ax, 0xce(%rsp)
movq 0x128(%rsp), %rdi
movl 0xd0(%rsp), %edx
xorl %esi, %esi
callq 0x131b0
movw %ax, 0x8c(%rsp)
jmp 0xc5e4
movw 0x8c(%rsp), %ax
movw %ax, 0xcc(%rsp)
movw 0xcc(%rsp), %ax
movw %ax, 0xca(%rsp)
movq 0x128(%rsp), %rcx
movl $0x1, %eax
cmpl 0x1c(%rcx), %eax
jge 0xc671
movq 0x128(%rsp), %rdi
movl 0xd0(%rsp), %edx
movl $0x1, %esi
callq 0x131b0
movw %ax, 0x8a(%rsp)
jmp 0xc639
movw 0x8a(%rsp), %ax
movw %ax, 0xca(%rsp)
jmp 0xc671
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x12380
jmp 0xcb77
movswl 0xcc(%rsp), %esi
movswl 0xca(%rsp), %edx
movl %esi, %edi
callq 0x131f0
movw %ax, 0x88(%rsp)
jmp 0xc692
movw 0x88(%rsp), %ax
movw %ax, 0xc8(%rsp)
movswl 0xce(%rsp), %eax
movswl 0xc8(%rsp), %ecx
addl %ecx, %eax
movw %ax, 0xc6(%rsp)
movswl 0xcc(%rsp), %eax
shll %eax
movswl 0xc6(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x84(%rsp)
movswl 0xc6(%rsp), %eax
cmpl $0x0, %eax
jle 0xc6fc
movswl 0xc6(%rsp), %ecx
andl $0x1, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, 0x80(%rsp)
jmp 0xc70e
movswl 0xc6(%rsp), %eax
andl $0x1, %eax
movl %eax, 0x80(%rsp)
movl 0x84(%rsp), %eax
movl 0x80(%rsp), %ecx
addl %ecx, %eax
shrl %eax
movw %ax, 0xc4(%rsp)
movw 0xc4(%rsp), %ax
movw %ax, 0x76(%rsp)
movl 0xd0(%rsp), %edx
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
callq 0x12110
movq %rax, 0x78(%rsp)
jmp 0xc752
movq 0x78(%rsp), %rax
movw 0x76(%rsp), %cx
movw %cx, (%rax)
movzwl 0xc4(%rsp), %eax
movzwl 0xc6(%rsp), %ecx
subl %ecx, %eax
movw %ax, 0xc2(%rsp)
movw 0xc2(%rsp), %ax
movw %ax, 0x66(%rsp)
movl 0xd0(%rsp), %edx
leaq 0xe0(%rsp), %rdi
movl $0x1, %esi
callq 0x12110
movq %rax, 0x68(%rsp)
jmp 0xc7a6
movq 0x68(%rsp), %rax
movw 0x66(%rsp), %cx
movw %cx, (%rax)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0xc57c
movl $0x1, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
movq 0x120(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0xca6a
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xca52
movq 0x120(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
callq 0x12ba0
movw %ax, 0x64(%rsp)
jmp 0xc831
movw 0x64(%rsp), %ax
movw %ax, 0xb6(%rsp)
movq 0x128(%rsp), %rdi
movl 0xbc(%rsp), %esi
movl 0xb8(%rsp), %edx
callq 0x131b0
movw %ax, 0x62(%rsp)
jmp 0xc860
movw 0x62(%rsp), %ax
movw %ax, 0xb4(%rsp)
movw 0xb4(%rsp), %ax
movw %ax, 0xb2(%rsp)
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movq 0x128(%rsp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0xc8c5
movq 0x128(%rsp), %rdi
movl 0xbc(%rsp), %esi
incl %esi
movl 0xb8(%rsp), %edx
callq 0x131b0
movw %ax, 0x60(%rsp)
jmp 0xc8b8
movw 0x60(%rsp), %ax
movw %ax, 0xb2(%rsp)
movl 0xbc(%rsp), %ecx
movl %ecx, %eax
leal -0x1(%rax,%rax), %esi
movl 0xb8(%rsp), %edx
leaq 0xe0(%rsp), %rdi
callq 0x131b0
movw %ax, 0x5e(%rsp)
jmp 0xc8ed
movw 0x5e(%rsp), %ax
movw %ax, 0xb0(%rsp)
movswl 0xb0(%rsp), %edi
movswl 0xb4(%rsp), %esi
movswl 0xb2(%rsp), %edx
callq 0x131f0
movw %ax, 0x5c(%rsp)
jmp 0xc91e
movw 0x5c(%rsp), %ax
movw %ax, 0xae(%rsp)
movswl 0xb6(%rsp), %eax
movswl 0xae(%rsp), %ecx
addl %ecx, %eax
movw %ax, 0xac(%rsp)
movswl 0xb4(%rsp), %eax
shll %eax
movswl 0xac(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x58(%rsp)
movswl 0xac(%rsp), %eax
cmpl $0x0, %eax
jle 0xc97f
movswl 0xac(%rsp), %ecx
andl $0x1, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, 0x54(%rsp)
jmp 0xc98e
movswl 0xac(%rsp), %eax
andl $0x1, %eax
movl %eax, 0x54(%rsp)
movl 0x58(%rsp), %eax
movl 0x54(%rsp), %ecx
addl %ecx, %eax
shrl %eax
movw %ax, 0xaa(%rsp)
movw 0xaa(%rsp), %ax
movw %ax, 0x46(%rsp)
movl 0xbc(%rsp), %esi
addl %esi, %esi
movl 0xb8(%rsp), %edx
leaq 0xe0(%rsp), %rdi
callq 0x12110
movq %rax, 0x48(%rsp)
jmp 0xc9d3
movq 0x48(%rsp), %rax
movw 0x46(%rsp), %cx
movw %cx, (%rax)
movzwl 0xaa(%rsp), %eax
movzwl 0xac(%rsp), %ecx
subl %ecx, %eax
movw %ax, 0xa8(%rsp)
movw 0xa8(%rsp), %ax
movw %ax, 0x36(%rsp)
movl 0xbc(%rsp), %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax), %esi
movl 0xb8(%rsp), %edx
leaq 0xe0(%rsp), %rdi
callq 0x12110
movq %rax, 0x38(%rsp)
jmp 0xca2f
movq 0x38(%rsp), %rax
movw 0x36(%rsp), %cx
movw %cx, (%rax)
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0xc7f7
jmp 0xca54
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0xc7d4
movl 0xfc(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xcb3a
movq 0x128(%rsp), %rax
movl 0x1c(%rax), %eax
subl $0x1, %eax
movl %eax, 0xa4(%rsp)
movl $0x0, 0xa0(%rsp)
movl 0xa0(%rsp), %eax
movq 0x128(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xcb38
movq 0x128(%rsp), %rdi
movl 0xa4(%rsp), %esi
movl 0xa0(%rsp), %edx
callq 0x12ba0
movw %ax, 0x34(%rsp)
jmp 0xcad7
movw 0x34(%rsp), %ax
movw %ax, 0x9e(%rsp)
movw 0x9e(%rsp), %ax
movw %ax, 0x26(%rsp)
movl 0xa4(%rsp), %esi
addl %esi, %esi
movl 0xa0(%rsp), %edx
leaq 0xe0(%rsp), %rdi
callq 0x12110
movq %rax, 0x28(%rsp)
jmp 0xcb15
movq 0x28(%rsp), %rax
movw 0x26(%rsp), %cx
movw %cx, (%rax)
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0xca9d
jmp 0xcb3a
movq 0x138(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x12390
jmp 0xcb61
leaq 0xe0(%rsp), %rdi
callq 0x12380
addq $0x140, %rsp            # imm = 0x140
popq %rbx
retq
movq 0xd8(%rsp), %rdi
callq 0x36a0
nopw %cs:(%rax,%rax)