// File: /workspace/github_cpp_makefile_star2_O1/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 $0x198, %rsp            # imm = 0x198
movl %edx, %ecx
movslq %esi, %rdx
movq %rdi, 0xb0(%rsp)
movq (%rdi), %r12
movq %rdx, %r14
shlq $0x6, %r14
leaq 0x1b994(%rip), %rsi     # 0x25ce1
movl $0x4, %edi
movl %ecx, 0x20(%rsp)
xorl %eax, %eax
callq 0x1d0d6
movl 0x18(%r12,%r14), %esi
movl 0x1c(%r12,%r14), %eax
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
leal (%rax,%rcx), %edx
incl %edx
sarl %edx
movswl 0x20(%r12,%r14), %ecx
movswl 0x22(%r12,%r14), %r8d
movl 0x28(%r12,%r14), %r9d
movl 0x2c(%r12,%r14), %eax
movl 0x30(%r12,%r14), %r10d
incl %r10d
movl 0x34(%r12,%r14), %r11d
movl 0x38(%r12,%r14), %ebx
incl %ebx
leaq 0x118(%rsp), %r15
movq %r15, %rdi
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdc18
addq $0x20, %rsp
movl 0x18(%r12,%r14), %esi
movl 0x1c(%r12,%r14), %edx
subl 0x1c(%r15), %edx
movl 0x20(%r15), %eax
movzwl 0x22(%r15), %edi
movl %eax, %ecx
subl %edi, %ecx
subl %eax, %edi
movl 0x2c(%r12,%r14), %eax
movl 0x30(%r12,%r14), %r10d
incl %r10d
movl 0x34(%r12,%r14), %r11d
movl 0x38(%r12,%r14), %ebx
movswl %cx, %ecx
movswl %di, %r8d
leaq 0x158(%rsp), %rdi
movl $0x1, %r9d
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdc18
addq $0x20, %rsp
movq %r14, 0xa8(%rsp)
addq %r14, %r12
movl 0x3c(%r12), %eax
movl %eax, 0x154(%rsp)
movq %r12, (%rsp)
movl 0x3c(%r12), %eax
movl %eax, 0x194(%rsp)
movslq 0x174(%rsp), %rax
movq %rax, 0x98(%rsp)
testq %rax, %rax
jle 0xa951
leaq 0x13c(%rsp), %rcx
movl -0xc(%rcx), %edx
movq (%rsp), %rax
leaq 0x24(%rax), %rbp
movq -0x24(%rcx), %rax
movq -0x1c(%rcx), %rcx
movq %rax, 0x80(%rsp)
subq %rax, %rcx
sarq %rcx
movq %rcx, 0xf0(%rsp)
leaq 0x17c(%rsp), %rax
movslq -0xc(%rax), %rcx
movq -0x24(%rax), %rsi
movq -0x1c(%rax), %rax
movq %rsi, 0x78(%rsp)
subq %rsi, %rax
sarq %rax
movq %rax, 0xe8(%rsp)
movq %rdx, 0x90(%rsp)
movslq %edx, %rax
movq %rax, 0xc8(%rsp)
addq %rax, %rax
movq %rax, 0xc0(%rsp)
movq %rcx, 0xd0(%rsp)
leaq (%rcx,%rcx), %rax
movq %rax, 0xb8(%rsp)
movl $0x1, %eax
movq %rax, 0x70(%rsp)
movl $0x2, %eax
movq %rax, 0x68(%rsp)
movl $0x4, %eax
movq %rax, 0x60(%rsp)
movl $0x3, %eax
movq %rax, 0x58(%rsp)
movl $0x6, %eax
movq %rax, 0x50(%rsp)
movq $-0x1, 0x48(%rsp)
movq $-0x2, 0x40(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x2, %eax
movq %rax, 0x38(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x8(%rsp)
movq %rbp, 0xf8(%rsp)
cmpl $0x0, 0x90(%rsp)
jle 0xa8b9
movq (%rsp), %rax
movslq 0x18(%rax), %rdi
movq (%rax), %rcx
movq 0x8(%rax), %r10
subq %rcx, %r10
sarq %r10
movq 0x8(%rsp), %rax
incq %rax
movq %rax, 0x110(%rsp)
movq 0x28(%rsp), %rax
imulq %rdi, %rax
movq %rax, 0x108(%rsp)
movq 0x30(%rsp), %r12
imulq %rdi, %r12
addq %rcx, %r12
movq 0x70(%rsp), %rax
imulq %rdi, %rax
movq %rax, 0x100(%rsp)
movq 0x38(%rsp), %r9
imulq %rdi, %r9
addq %rcx, %r9
movq 0x68(%rsp), %rax
imulq %rdi, %rax
movq %rax, 0x88(%rsp)
movq 0x60(%rsp), %r15
imulq %rdi, %r15
addq %rcx, %r15
movq 0x58(%rsp), %rax
imulq %rdi, %rax
movq %rax, 0xd8(%rsp)
movq 0x50(%rsp), %rax
imulq %rdi, %rax
addq %rcx, %rax
movq 0x48(%rsp), %rdx
imulq %rdi, %rdx
movq %rdx, 0xe0(%rsp)
imulq 0x40(%rsp), %rdi
addq %rcx, %rdi
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %r8
xorl %r14d, %r14d
movq %r10, 0xa0(%rsp)
movq 0x108(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, %r10
movq %rbp, %rcx
cmovaq %r12, %rcx
movq 0x100(%rsp), %rsi
addq %r14, %rsi
cmpq %rsi, %r10
movq %rbp, %rsi
cmovaq %r9, %rsi
movswl (%rcx), %ebx
movswl (%rsi), %esi
movl %esi, %ecx
addl %ebx, %ecx
xorl %r13d, %r13d
movl %esi, 0x24(%rsp)
cmpw %si, %bx
setg %r13b
addl %ecx, %r13d
shrl %r13d
movq 0x10(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, 0xf0(%rsp)
leaq 0x13c(%rsp), %rcx
cmovaq %r8, %rcx
movw %r13w, (%rcx)
movq 0x110(%rsp), %rcx
cmpq 0x98(%rsp), %rcx
jae 0xa701
movq 0x88(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, %r10
movq %rbp, %rcx
cmovaq %r15, %rcx
movswl (%rcx), %ecx
movq 0xd8(%rsp), %rsi
addq %r14, %rsi
cmpq %rsi, %r10
movq %rbp, %rsi
cmovaq %rax, %rsi
movswl (%rsi), %r10d
movl %r10d, %r11d
addl %ecx, %r11d
xorl %esi, %esi
cmpw %r10w, %cx
movq 0xa0(%rsp), %r10
setg %sil
addl %r11d, %esi
shrl %esi
jmp 0xa726
movq (%rsp), %rcx
testb $0x1, 0x1c(%rcx)
movl %r13d, %esi
je 0xa726
movq 0x88(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, %r10
movq %rbp, %rcx
cmovaq %r15, %rcx
movzwl (%rcx), %esi
movl %r13d, %r11d
cmpq $0x0, 0x8(%rsp)
je 0xa74a
movq 0xe0(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, %r10
movq %rbp, %rcx
cmovaq %rdi, %rcx
movzwl (%rcx), %r11d
movswl %r11w, %ecx
movswl %r13w, %ebp
cmpw %r13w, %si
jg 0xa83b
cmpw %r13w, %r11w
jl 0xa83b
movswl %si, %esi
leal (,%rcx,4), %r10d
leal (%rsi,%rsi,2), %r11d
addl %ebp, %r11d
subl %r11d, %r10d
addl $0x6, %r10d
movslq %r10d, %r10
imulq $0x2aaaaaab, %r10, %r13 # imm = 0x2AAAAAAB
movq %r13, %r10
shrq $0x3f, %r10
sarq $0x21, %r13
addl %r10d, %r13d
movswl %r13w, %r10d
movl %r13d, %r11d
andl $0x1, %r11d
subl %r11d, %r10d
subl %ebp, %ecx
leal (%rcx,%rcx), %r11d
cmpl %r11d, %r10d
jle 0xa7b8
leal 0x1(,%rcx,2), %r13d
movswl %r13w, %ecx
movl %ecx, %r10d
andl $0x1, %r10d
addl %ecx, %r10d
subl %esi, %ebp
addl %ebp, %ebp
cmpl %ebp, %r10d
jg 0xa7d2
movl %r13d, %ebp
movl %ebp, %r10d
addl 0x24(%rsp), %r10d
subl %r10d, %ebx
movq 0x18(%rsp), %rcx
addq %r14, %rcx
cmpq %rcx, 0xe8(%rsp)
leaq 0x17c(%rsp), %rcx
cmovaq %rdx, %rcx
movw %bx, (%rcx)
incq %r14
addq $0x2, %r12
addq $0x2, %r9
addq $0x2, %r8
addq $0x2, %r15
addq $0x2, %rax
addq $0x2, %rdi
addq $0x2, %rdx
cmpq %r14, 0x90(%rsp)
movq 0xf8(%rsp), %rbp
movq 0xa0(%rsp), %r10
jne 0xa637
jmp 0xa8b9
xorl %r10d, %r10d
cmpw %r13w, %si
jl 0xa7d5
cmpw %r13w, %r11w
jg 0xa7d5
movswl %si, %esi
leal (,%rcx,4), %r10d
leal (%rsi,%rsi,2), %r11d
addl %ebp, %r11d
subl %r11d, %r10d
addl $-0x6, %r10d
movslq %r10d, %r10
imulq $0x2aaaaaab, %r10, %r13 # imm = 0x2AAAAAAB
movq %r13, %r10
shrq $0x3f, %r10
sarq $0x21, %r13
addl %r10d, %r13d
movswl %r13w, %r10d
movl %r13d, %r11d
andl $0x1, %r11d
addl %r10d, %r11d
subl %ebp, %ecx
leal (%rcx,%rcx), %r10d
cmpl %r10d, %r11d
jge 0xa89c
leal -0x1(,%rcx,2), %r13d
movl %r13d, %ecx
andl $0xfffe, %ecx           # imm = 0xFFFE
movswl %cx, %ecx
subl %esi, %ebp
addl %ebp, %ebp
cmpl %ecx, %ebp
jle 0xa7cf
jmp 0xa7d2
movq 0x8(%rsp), %rcx
incq %rcx
addq $0x2, 0x28(%rsp)
addq $0x4, 0x30(%rsp)
addq $0x2, 0x70(%rsp)
addq $0x4, 0x38(%rsp)
movq 0xc0(%rsp), %rax
addq %rax, 0x80(%rsp)
movq 0x10(%rsp), %rax
addq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsp)
addq $0x2, 0x68(%rsp)
addq $0x4, 0x60(%rsp)
addq $0x2, 0x58(%rsp)
addq $0x4, 0x50(%rsp)
addq $0x2, 0x48(%rsp)
addq $0x4, 0x40(%rsp)
movq 0x18(%rsp), %rax
addq 0xd0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xb8(%rsp), %rax
addq %rax, 0x78(%rsp)
movq %rcx, 0x8(%rsp)
cmpq 0x98(%rsp), %rcx
jne 0xa55e
movq (%rsp), %r14
testb $0x1, 0x1c(%r14)
je 0xa9e4
movslq 0x130(%rsp), %rax
testq %rax, %rax
jle 0xa9e4
leaq 0x13c(%rsp), %rcx
movslq -0x8(%rcx), %rdx
decq %rdx
movslq %edx, %rdi
movslq 0x18(%r14), %rsi
imulq %rdi, %rsi
movq (%r14), %r9
movq 0x8(%r14), %rdi
subq %r9, %rdi
sarq %rdi
addq $0x24, %r14
imulq %rax, %rdx
movq -0x24(%rcx), %r10
movq -0x1c(%rcx), %r8
subq %r10, %r8
sarq %r8
leaq (%r9,%rsi,4), %r9
addq %rsi, %rsi
leaq (%r10,%rdx,2), %r10
cmpq %rsi, %rdi
movq %r14, %r11
cmovaq %r9, %r11
cmpq %rdx, %r8
movq %rcx, %rbx
cmovaq %r10, %rbx
movzwl (%r11), %r11d
movw %r11w, (%rbx)
incq %rsi
addq $0x2, %r9
incq %rdx
addq $0x2, %r10
decq %rax
jne 0xa9b5
movq 0xb0(%rsp), %rbx
movq 0xa8(%rsp), %r14
addq (%rbx), %r14
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
callq 0xe65e
movq 0x150(%rsp), %rax
movq %rax, 0x38(%r14)
movups 0x130(%rsp), %xmm0
movups 0x140(%rsp), %xmm1
movups %xmm1, 0x28(%r14)
movups %xmm0, 0x18(%r14)
movslq 0x20(%rsp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
leaq 0x158(%rsp), %rdx
movq %rbx, %rdi
callq 0xdf1c
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
je 0xaa66
movq 0x168(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0xaa83
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaa97
movq %rax, %rbx
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
je 0xaabc
movq 0x168(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0xaabc
movq %rax, %rbx
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0xaad9
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x35a0