// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movslq %esi, %rbp
movq %rbp, 0x10(%rsp)
movq %rdi, 0x38(%rsp)
movq (%rdi), %r13
shlq $0x6, %rbp
movslq %edx, %r14
movq %r14, %rbx
shlq $0x6, %rbx
movl 0x1c(%r13,%rbx), %edx
addl 0x1c(%r13,%rbp), %edx
movswl 0x20(%r13,%rbp), %ecx
movswl 0x22(%r13,%rbp), %r8d
movl 0x18(%r13,%rbp), %esi
movl 0x28(%r13,%rbp), %r9d
movl 0x2c(%r13,%rbp), %eax
movl 0x30(%r13,%rbp), %r10d
decl %r10d
movl 0x34(%r13,%rbp), %r11d
movl 0x38(%r13,%rbp), %r12d
decl %r12d
leaq 0x48(%rsp), %r15
movq %r15, %rdi
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0xa470
addq $0x20, %rsp
movl 0x3c(%r13,%rbp), %eax
movl %eax, 0x3c(%r15)
movl 0x1c(%r13,%rbp), %r8d
movl 0x1c(%r15), %r9d
leaq 0x19adf(%rip), %rsi     # 0x1dbfe
pushq $0x4
popq %rdi
movq 0x10(%rsp), %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x16c30
movq %rbp, 0x30(%rsp)
movq %r13, %r12
addq %rbp, %r12
addq %r13, %rbx
leaq 0x24(%rbx), %r14
leaq 0x6c(%rsp), %r15
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rbx, 0x28(%rsp)
movslq 0x18(%r12), %rax
cmpq %rax, %r13
jge 0x4208
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
subq %rcx, %rdx
sarq %rdx
cmpq %r13, %rdx
leaq (%rcx,%r13,2), %rcx
cmovbeq %r14, %rcx
movq (%r12), %rsi
movzwl (%rsi,%r13,2), %edx
cmpl $0x2, 0x1c(%r12)
movl %edx, %edi
jl 0x4195
addl %r13d, %eax
cltq
movzwl (%rsi,%rax,2), %edi
movzwl (%rcx), %ebp
movswl %dx, %ebx
movswl %di, %edx
movl %ebx, %edi
movl %ebx, %esi
callq 0xa8fe
addl %eax, %ebp
movswl %bp, %ecx
movl %ecx, %edx
andl $0x1, %edx
movl %edx, %eax
negl %eax
testw %cx, %cx
cmovlel %edx, %eax
leal (%rcx,%rbx,2), %ecx
addl %ecx, %eax
sarl %eax
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rdx
subq %rcx, %rdx
sarq %rdx
cmpq %r13, %rdx
leaq (%rcx,%r13,2), %rsi
cmovbeq %r15, %rsi
movw %ax, (%rsi)
subl %ebp, %eax
movslq 0x60(%rsp), %rsi
movslq %r13d, %rdi
addq %rsi, %rdi
cmpq %rdi, %rdx
leaq (%rcx,%rdi,2), %rcx
cmovbeq %r15, %rcx
movw %ax, (%rcx)
incq %r13
movq 0x28(%rsp), %rdi
jmp 0x4153
pushq $0x1
popq %rcx
pushq $0x2
popq %rdx
movl %edx, 0xc(%rsp)
movl %ecx, %ebp
cmpl 0x1c(%rdi), %ebp
jge 0x4331
leal 0x1(%rbp), %edx
movl %edx, 0x10(%rsp)
leal (,%rbp,2), %edx
movl %edx, 0x24(%rsp)
leal 0x1(,%rbp,2), %edx
movl %edx, 0x20(%rsp)
movl %ecx, 0x1c(%rsp)
movslq %ecx, %rcx
movq %rcx, 0x40(%rsp)
xorl %r15d, %r15d
cmpl %eax, %r15d
jge 0x431b
movl %ebp, %esi
movl %r15d, %edx
callq 0xa79e
movl %eax, %r13d
movl 0x18(%r12), %eax
movl %ebp, %ecx
imull %eax, %ecx
movslq %ecx, %rcx
addq %r15, %rcx
movq (%r12), %rsi
movzwl (%rsi,%rcx,2), %ecx
movl %ecx, %edx
movl 0x10(%rsp), %edi
cmpl 0x1c(%r12), %edi
jge 0x4292
imull 0xc(%rsp), %eax
addl %r15d, %eax
cltq
movzwl (%rsi,%rax,2), %edx
movswl %cx, %r14d
movslq 0x60(%rsp), %rax
imulq 0x40(%rsp), %rax
addq %r15, %rax
movq 0x48(%rsp), %rcx
movswl (%rcx,%rax,2), %edi
movswl %dx, %edx
movl %r14d, %esi
callq 0xa8fe
addl %eax, %r13d
movswl %r13w, %eax
leal (%rax,%r14,2), %ecx
movl %eax, %edx
andl $0x1, %edx
movl %edx, %r14d
negl %r14d
testw %ax, %ax
cmovlel %edx, %r14d
addl %ecx, %r14d
sarl %r14d
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movl 0x24(%rsp), %esi
movl %r15d, %edx
callq 0xa44a
movw %r14w, (%rax)
subl %r13d, %r14d
movq %rbx, %rdi
movl 0x20(%rsp), %esi
movl %r15d, %edx
callq 0xa44a
movw %r14w, (%rax)
movl 0x18(%r12), %eax
incq %r15
movq 0x28(%rsp), %rdi
jmp 0x4249
movl 0x1c(%rsp), %ecx
addl $0x2, %ecx
incl 0xc(%rsp)
movl 0x10(%rsp), %edx
movl %edx, %ebp
jmp 0x4214
testb $0x1, 0x64(%rsp)
jne 0x436b
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
addq (%rax), %rdi
leaq 0x48(%rsp), %rsi
callq 0xa526
leaq 0x48(%rsp), %rdi
callq 0xabc2
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x1c(%r12), %ecx
leal -0x2(,%rcx,2), %ebx
movl %ecx, %ebp
decl %ebp
xorl %r14d, %r14d
leaq 0x48(%rsp), %r15
cmpl %eax, %r14d
jge 0x4338
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0xa79e
movl %eax, %r13d
movq %r15, %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0xa44a
movw %r13w, (%rax)
incl %r14d
movl 0x18(%r12), %eax
jmp 0x4383
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xabc2
movq %rbx, %rdi
callq 0x35d0