// File: /workspace/github_cpp_makefile_star2_O2/cloudinary[P]fuif/transform/squeeze.h
// Function: fwd_vsqueeze(Image&, int, int)
void fwd_vsqueeze(Image &input, int c, int rc) {
    const Channel &chin = input.channel[c];

    v_printf(4,"Doing vertical squeeze of channel %i to new channel %i\n",c,rc);

    Channel chout(chin.w,(chin.h+1)/2, chin.minval, chin.maxval, chin.q, chin.hshift,chin.vshift+1,chin.hcshift,chin.vcshift+1);
    Channel chout_residual(chin.w,chin.h-chout.h,chout.minval-chout.maxval,chout.maxval-chout.minval,1, chin.hshift,chin.vshift+1,chin.hcshift,chin.vcshift);
    chout.component = chin.component;
    chout_residual.component = chin.component;
    for (int y=0; y<chout_residual.h; y++) {
      for (int x=0; x<chout.w; x++) {
        pixel_type A = chin.value(y*2,x);
        pixel_type B = chin.value(y*2+1,x);
        pixel_type avg = (A+B+(A>B))>>1;
        chout.value(y,x) = avg;
        pixel_type diff = A-B;

        pixel_type next_avg = avg;
        if (y+1<chout_residual.h) next_avg = (chin.value(y*2+2,x) + chin.value(y*2+3,x) + (chin.value(y*2+2,x) > chin.value(y*2+3,x))) >> 1; // which will be chout.value(y+1,x)
        else if (chin.h & 1) next_avg = (chin.value(y*2+2,x));

        pixel_type top = (y>0 ? chin.value(y*2-1,x) : avg);
        pixel_type tendency=smooth_tendency(top,avg,next_avg);

        chout_residual.value(y,x) = diff - tendency;
      }
    }
    if (chin.h & 1) { int y = chout.h-1;
      for (int x=0; x<chout.w; x++) {
        pixel_type avg = chin.value(y*2,x);
        chout.value(y,x) = avg;
      }
    }
    input.channel[c] = chout;
//    chout_residual.actual_minmax(&chout_residual.minval, &chout_residual.maxval);
    input.channel.insert(input.channel.begin()+rc, chout_residual);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, %ecx
movslq %esi, %rdx
movq %rdi, 0x40(%rsp)
movq (%rdi), %r13
movq %rdx, %r12
shlq $0x6, %r12
leaq 0x16044(%rip), %rsi     # 0x1dc61
pushq $0x4
popq %rdi
movl %ecx, 0x18(%rsp)
xorl %eax, %eax
callq 0x16c30
movl 0x18(%r13,%r12), %esi
movl 0x1c(%r13,%r12), %eax
incl %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movswl 0x20(%r13,%r12), %ecx
movswl 0x22(%r13,%r12), %r8d
movl 0x28(%r13,%r12), %r9d
movl 0x2c(%r13,%r12), %r10d
movl 0x30(%r13,%r12), %r11d
incl %r11d
movl 0x34(%r13,%r12), %r14d
movl 0x38(%r13,%r12), %r15d
incl %r15d
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movl %eax, %edx
pushq %r15
pushq %r14
pushq %r11
pushq %r10
callq 0xa470
addq $0x20, %rsp
movl 0x18(%r13,%r12), %esi
movl 0x1c(%r13,%r12), %edx
subl 0x1c(%rbx), %edx
movl 0x20(%rbx), %eax
movzwl 0x22(%rbx), %edi
movl %eax, %ecx
subl %edi, %ecx
subl %eax, %edi
movl 0x2c(%r13,%r12), %eax
movl 0x30(%r13,%r12), %r10d
incl %r10d
movl 0x34(%r13,%r12), %r11d
movl 0x38(%r13,%r12), %ebx
movswl %cx, %ecx
movswl %di, %r8d
leaq 0x88(%rsp), %rdi
pushq $0x1
popq %r9
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xa470
addq $0x20, %rsp
addq %r12, %r13
movl 0x3c(%r13), %eax
leaq 0x48(%rsp), %rcx
movl %eax, 0x3c(%rcx)
leaq 0x88(%rsp), %rcx
movl %eax, 0x3c(%rcx)
movq %r12, 0x38(%rsp)
movq %r13, %r12
movq %r13, 0x10(%rsp)
xorl %r15d, %r15d
cmpl 0xa4(%rsp), %r15d
jge 0x7ea3
leal (%r15,%r15), %eax
movl %eax, 0x2c(%rsp)
leal 0x1(,%r15,2), %eax
movl %eax, 0x28(%rsp)
leal 0x1(%r15), %eax
movl %eax, 0xc(%rsp)
leal 0x2(%r15,%r15), %eax
movl %eax, 0x8(%rsp)
leal 0x3(%r15,%r15), %eax
movl %eax, 0x1c(%rsp)
leal -0x1(,%r15,2), %eax
movl %eax, 0x20(%rsp)
xorl %ebx, %ebx
movq %r15, 0x30(%rsp)
cmpl 0x60(%rsp), %ebx
jge 0x7e97
movq %r12, %rdi
movl 0x2c(%rsp), %esi
movl %ebx, %edx
callq 0xa79e
movl %eax, %r14d
movq %r12, %rdi
movl 0x28(%rsp), %esi
movl %ebx, %edx
callq 0xa79e
movl %eax, %ebp
movswl %r14w, %eax
movswl %bp, %ecx
xorl %r13d, %r13d
cmpw %cx, %ax
setg %r13b
addl %ecx, %r13d
addl %eax, %r13d
shrl %r13d
leaq 0x48(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xa44a
movw %r13w, (%rax)
movl 0xc(%rsp), %eax
cmpl 0xa4(%rsp), %eax
jge 0x7e2c
movq %r12, %rdi
movl 0x8(%rsp), %r15d
movl %r15d, %esi
movl %ebx, %edx
callq 0xa79e
cwtl
movl %eax, 0x4(%rsp)
movq %r12, %rdi
movl %r14d, 0x24(%rsp)
movl 0x1c(%rsp), %r14d
movl %r14d, %esi
movl %ebx, %edx
callq 0xa79e
movswl %ax, %r12d
addl 0x4(%rsp), %r12d
movq 0x10(%rsp), %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xa79e
movw %ax, 0x4(%rsp)
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movl 0x24(%rsp), %r14d
movl %ebx, %edx
callq 0xa79e
xorl %r15d, %r15d
cmpw %ax, 0x4(%rsp)
setg %r15b
addl %r12d, %r15d
movq 0x10(%rsp), %r12
shrl %r15d
jmp 0x7e48
testb $0x1, 0x1c(%r12)
movl %r13d, %r15d
je 0x7e48
movq %r12, %rdi
movl 0x8(%rsp), %esi
movl %ebx, %edx
callq 0xa79e
movl %eax, %r15d
movl %r13d, %eax
cmpl $0x0, 0x30(%rsp)
je 0x7e60
movq %r12, %rdi
movl 0x20(%rsp), %esi
movl %ebx, %edx
callq 0xa79e
movswl %ax, %edi
movswl %r13w, %esi
movswl %r15w, %edx
callq 0xa8fe
addl %eax, %ebp
subl %ebp, %r14d
leaq 0x88(%rsp), %rdi
movq 0x30(%rsp), %r15
movl %r15d, %esi
movl %ebx, %edx
callq 0xa44a
movw %r14w, (%rax)
incl %ebx
jmp 0x7d4f
movl 0xc(%rsp), %eax
movl %eax, %r15d
jmp 0x7d00
testb $0x1, 0x1c(%r12)
jne 0x7f07
movq 0x40(%rsp), %rbx
movq 0x38(%rsp), %rdi
addq (%rbx), %rdi
leaq 0x48(%rsp), %rsi
callq 0xa526
movslq 0x18(%rsp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0xa7c8
leaq 0x88(%rsp), %rdi
callq 0xabc2
leaq 0x48(%rsp), %rdi
callq 0xabc2
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48(%rsp), %rbx
movl 0x1c(%rbx), %eax
leal -0x2(,%rax,2), %ebp
movl %eax, %r14d
decl %r14d
xorl %r12d, %r12d
cmpl 0x60(%rsp), %r12d
jge 0x7eab
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0xa79e
movl %eax, %r13d
movq %rbx, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0xa44a
movw %r13w, (%rax)
incl %r12d
jmp 0x7f1f
jmp 0x7f51
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0xabc2
jmp 0x7f66
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xabc2
movq %rbx, %rdi
callq 0x35d0