// File: 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 %rbx
subq $0x180, %rsp            # imm = 0x180
movq %rdi, 0x178(%rsp)
movl %esi, 0x174(%rsp)
movl %edx, 0x170(%rsp)
movq 0x178(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0x4ba0
movq %rax, 0x168(%rsp)
movl 0x174(%rsp), %edx
movl 0x170(%rsp), %ecx
leaq 0x3a031(%rip), %rsi     # 0x46c11
xorl %eax, %eax
movl $0x4, %edi
callq 0x3a770
movq 0x168(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0x18(%rax), %esi
movl 0x1c(%rax), %edx
movl %edx, %edi
incl %edi
movl %edx, %ecx
shrl $0x1f, %edi
movl %edi, %edx
leal 0x1(%rcx,%rdx), %edx
sarl %edx
movswl 0x20(%rax), %ecx
movswl 0x22(%rax), %r8d
movl 0x28(%rax), %r9d
movl 0x2c(%rax), %edi
movl 0x30(%rax), %r10d
incl %r10d
movl 0x34(%rax), %r11d
movl 0x38(%rax), %ebx
incl %ebx
movq %rsp, %rax
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %edi, (%rax)
leaq 0x128(%rsp), %rdi
callq 0x12200
movq 0x168(%rsp), %rdi
movl 0x18(%rdi), %esi
movl 0x1c(%rdi), %edx
movl 0x144(%rsp), %eax
subl %eax, %edx
movswl 0x148(%rsp), %r8d
movswl 0x14a(%rsp), %eax
movl %r8d, %ecx
subl %eax, %ecx
subl %r8d, %eax
movl 0x2c(%rdi), %r8d
movl 0x30(%rdi), %r9d
incl %r9d
movl 0x34(%rdi), %r10d
movl 0x38(%rdi), %r11d
movq %rsp, %rdi
movl %r11d, 0x18(%rdi)
movl %r10d, 0x10(%rdi)
movl %r9d, 0x8(%rdi)
movl %r8d, (%rdi)
movswl %cx, %ecx
movswl %ax, %r8d
leaq 0xe8(%rsp), %rdi
movl $0x1, %r9d
callq 0x12200
jmp 0xccc1
movq 0x168(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x164(%rsp)
movq 0x168(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x124(%rsp)
movl $0x0, 0xd8(%rsp)
movl 0xd8(%rsp), %eax
cmpl 0x104(%rsp), %eax
jge 0xd0b8
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0x140(%rsp), %eax
jge 0xd0a0
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %esi
addl %esi, %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x8e(%rsp)
jmp 0xcd4a
movw 0x8e(%rsp), %ax
movw %ax, 0xd2(%rsp)
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x8c(%rsp)
jmp 0xcd85
movw 0x8c(%rsp), %ax
movw %ax, 0xd0(%rsp)
movswl 0xd2(%rsp), %ecx
movswl 0xd0(%rsp), %edx
movl %ecx, %eax
addl %edx, %eax
subl %edx, %ecx
setg %cl
movzbl %cl, %ecx
addl %ecx, %eax
shrl %eax
movw %ax, 0xce(%rsp)
movw 0xce(%rsp), %ax
movw %ax, 0x7e(%rsp)
movl 0xd8(%rsp), %esi
movl 0xd4(%rsp), %edx
leaq 0x128(%rsp), %rdi
callq 0x12110
movq %rax, 0x80(%rsp)
jmp 0xcdef
movq 0x80(%rsp), %rax
movw 0x7e(%rsp), %cx
movw %cx, (%rax)
movswl 0xd2(%rsp), %eax
movswl 0xd0(%rsp), %ecx
subl %ecx, %eax
movw %ax, 0xcc(%rsp)
movw 0xce(%rsp), %ax
movw %ax, 0xca(%rsp)
movl 0xd8(%rsp), %eax
addl $0x1, %eax
cmpl 0x104(%rsp), %eax
jge 0xcf71
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x7c(%rsp)
jmp 0xce68
movw 0x7c(%rsp), %ax
cwtl
movl %eax, 0x74(%rsp)
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal 0x3(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x7a(%rsp)
jmp 0xce9a
movl 0x74(%rsp), %eax
movw 0x7a(%rsp), %cx
movswl %cx, %ecx
addl %ecx, %eax
movl %eax, 0x6c(%rsp)
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x72(%rsp)
jmp 0xced4
movw 0x72(%rsp), %ax
cwtl
movl %eax, 0x64(%rsp)
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal 0x3(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x6a(%rsp)
jmp 0xcf06
movl 0x6c(%rsp), %eax
movl 0x64(%rsp), %ecx
movw 0x6a(%rsp), %dx
movswl %dx, %edx
cmpl %edx, %ecx
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
sarl %eax
movw %ax, 0xca(%rsp)
jmp 0xcfbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0xd248
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x12380
jmp 0xd248
movq 0x168(%rsp), %rax
movl 0x1c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xcfb9
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal 0x2(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x62(%rsp)
jmp 0xcfac
movw 0x62(%rsp), %ax
movw %ax, 0xca(%rsp)
jmp 0xcfbb
cmpl $0x0, 0xd8(%rsp)
jle 0xcff9
movq 0x168(%rsp), %rdi
movl 0xd8(%rsp), %ecx
movl %ecx, %eax
leal -0x1(%rax,%rax), %esi
movl 0xd4(%rsp), %edx
callq 0x12ba0
movw %ax, 0x60(%rsp)
jmp 0xcfed
movw 0x60(%rsp), %ax
movw %ax, 0x5e(%rsp)
jmp 0xd006
movw 0xce(%rsp), %ax
movw %ax, 0x5e(%rsp)
movw 0x5e(%rsp), %ax
movw %ax, 0xc8(%rsp)
movswl 0xc8(%rsp), %edi
movswl 0xce(%rsp), %esi
movswl 0xca(%rsp), %edx
callq 0x131f0
movw %ax, 0x5c(%rsp)
jmp 0xd037
movw 0x5c(%rsp), %ax
movw %ax, 0xc6(%rsp)
movzwl 0xcc(%rsp), %eax
movzwl 0xc6(%rsp), %ecx
subl %ecx, %eax
movw %ax, 0x4e(%rsp)
movl 0xd8(%rsp), %esi
movl 0xd4(%rsp), %edx
leaq 0xe8(%rsp), %rdi
callq 0x12110
movq %rax, 0x50(%rsp)
jmp 0xd07d
movq 0x50(%rsp), %rax
movw 0x4e(%rsp), %cx
movw %cx, (%rax)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0xcd0f
jmp 0xd0a2
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0xccf0
movq 0x168(%rsp), %rax
movl 0x1c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd184
movl 0x144(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xc0(%rsp)
movl $0x0, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
cmpl 0x140(%rsp), %eax
jge 0xd182
movq 0x168(%rsp), %rdi
movl 0xc0(%rsp), %esi
addl %esi, %esi
movl 0xbc(%rsp), %edx
callq 0x12ba0
movw %ax, 0x4c(%rsp)
jmp 0xd123
movw 0x4c(%rsp), %ax
movw %ax, 0xba(%rsp)
movw 0xba(%rsp), %ax
movw %ax, 0x3e(%rsp)
movl 0xc0(%rsp), %esi
movl 0xbc(%rsp), %edx
leaq 0x128(%rsp), %rdi
callq 0x12110
movq %rax, 0x40(%rsp)
jmp 0xd15f
movq 0x40(%rsp), %rax
movw 0x3e(%rsp), %cx
movw %cx, (%rax)
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0xd0eb
jmp 0xd184
movq 0x178(%rsp), %rdi
movslq 0x174(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
leaq 0x128(%rsp), %rsi
callq 0x12390
jmp 0xd1ab
movq 0x178(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x127d0
movq %rax, 0xa0(%rsp)
movslq 0x170(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x12800
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x12840
movq 0x28(%rsp), %rdi
movq 0xb0(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x12c20
movq %rax, 0x30(%rsp)
jmp 0xd218
movq 0x30(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x12380
leaq 0x128(%rsp), %rdi
callq 0x12380
addq $0x180, %rsp            # imm = 0x180
popq %rbx
retq
leaq 0x128(%rsp), %rdi
callq 0x12380
movq 0xe0(%rsp), %rdi
callq 0x36a0
nopw %cs:(%rax,%rax)