// File: /workspace/github_cpp_makefile_star2_O3/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 $0x148, %rsp            # imm = 0x148
movl %edx, %ecx
movslq %esi, %rdx
movq %rdi, 0x48(%rsp)
movq (%rdi), %r12
movq %rdx, %r14
shlq $0x6, %r14
leaq 0x1b9d3(%rip), %rsi     # 0x25ce1
movl $0x4, %edi
movl %ecx, 0x8(%rsp)
xorl %eax, %eax
callq 0x1cede
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 0xc8(%rsp), %r15
movq %r15, %rdi
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdb78
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 0x108(%rsp), %rdi
movl $0x1, %r9d
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdb78
addq $0x20, %rsp
addq %r14, %r12
movl 0x3c(%r12), %eax
movl %eax, 0x104(%rsp)
movl %eax, 0x144(%rsp)
movslq 0x124(%rsp), %rax
movq %rax, 0x28(%rsp)
testq %rax, %rax
jle 0xa800
leaq 0xec(%rsp), %rax
movl -0xc(%rax), %ecx
leaq 0x24(%r12), %r8
movq -0x24(%rax), %rdx
movq -0x1c(%rax), %rax
movq %rdx, 0x78(%rsp)
subq %rdx, %rax
sarq %rax
movq %rax, 0xa0(%rsp)
leaq 0x12c(%rsp), %rax
movslq -0xc(%rax), %rdx
movq -0x24(%rax), %rsi
movq -0x1c(%rax), %rax
movq %rsi, 0x68(%rsp)
subq %rsi, %rax
sarq %rax
movq %rax, 0x98(%rsp)
movq %rcx, 0x20(%rsp)
movslq %ecx, %rax
movq %rax, 0x60(%rsp)
addq %rax, %rax
movq %rax, 0x58(%rsp)
movq %rdx, 0x70(%rsp)
leaq (%rdx,%rdx), %rax
movq %rax, 0x50(%rsp)
movq $0x0, (%rsp)
movq %r8, 0x38(%rsp)
movq %r14, 0x80(%rsp)
movq %r12, 0x10(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0xa7ea
movq (%rsp), %rsi
leaq (%rsi,%rsi), %rax
movslq 0x18(%r12), %rcx
imulq %rcx, %rax
movq %rax, 0xc0(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %r10
subq %rax, %r10
sarq %r10
leaq 0x1(,%rsi,2), %rdx
imulq %rcx, %rdx
movq %rsi, %rdi
imulq 0x60(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
leaq 0x2(,%rsi,2), %rdi
imulq %rcx, %rdi
leaq 0x3(,%rsi,2), %r11
imulq %rcx, %r11
leaq -0x1(,%rsi,2), %rbx
imulq %rcx, %rbx
movq %rsi, %r9
imulq 0x70(%rsp), %r9
movq %r9, 0xa8(%rsp)
imulq %rsi, %rcx
leaq (%rax,%rcx,4), %r9
movq %rdx, 0xb8(%rsp)
leaq (%rax,%rdx,2), %r14
movq 0x58(%rsp), %r12
imulq %rsi, %r12
addq 0x78(%rsp), %r12
movq %rdi, 0x18(%rsp)
leaq (%rax,%rdi,2), %r13
movq %r11, 0x88(%rsp)
leaq (%rax,%r11,2), %r15
movq %rbx, 0x90(%rsp)
leaq (%rax,%rbx,2), %rax
movq 0x50(%rsp), %rdx
imulq %rsi, %rdx
addq 0x68(%rsp), %rdx
leaq 0x1(%rsi), %rcx
movq %rcx, 0x30(%rsp)
xorl %ebp, %ebp
movq %r10, 0x40(%rsp)
movq 0xc0(%rsp), %rcx
addq %rbp, %rcx
cmpq %rcx, %r10
movq %r8, %rcx
cmovaq %r9, %rcx
movq 0xb8(%rsp), %rsi
addq %rbp, %rsi
cmpq %rsi, %r10
movq %r8, %rsi
cmovaq %r14, %rsi
movswl (%rcx), %r11d
movswl (%rsi), %esi
movl %esi, %ecx
addl %r11d, %ecx
xorl %edi, %edi
movl %esi, 0xc(%rsp)
cmpw %si, %r11w
setg %dil
addl %ecx, %edi
shrl %edi
movq 0xb0(%rsp), %rcx
addq %rbp, %rcx
cmpq %rcx, 0xa0(%rsp)
leaq 0xec(%rsp), %rcx
cmovaq %r12, %rcx
movw %di, (%rcx)
movq 0x30(%rsp), %rcx
cmpq 0x28(%rsp), %rcx
jge 0xa638
movq 0x18(%rsp), %rcx
addq %rbp, %rcx
cmpq %rcx, %r10
movq %r8, %rcx
cmovaq %r13, %rcx
movswl (%rcx), %ecx
movq 0x88(%rsp), %rsi
addq %rbp, %rsi
cmpq %rsi, %r10
movq %r8, %rsi
cmovaq %r15, %rsi
movswl (%rsi), %r8d
movl %r8d, %r10d
addl %ecx, %r10d
xorl %esi, %esi
cmpw %r8w, %cx
movq 0x38(%rsp), %r8
setg %sil
addl %r10d, %esi
movq 0x40(%rsp), %r10
shrl %esi
jmp 0xa65a
movq 0x10(%rsp), %rcx
testb $0x1, 0x1c(%rcx)
movl %edi, %esi
je 0xa65a
movq 0x18(%rsp), %rcx
addq %rbp, %rcx
cmpq %rcx, %r10
movq %r8, %rcx
cmovaq %r13, %rcx
movzwl (%rcx), %esi
movl %edi, %ebx
cmpq $0x0, (%rsp)
je 0xa67b
movq 0x90(%rsp), %rcx
addq %rbp, %rcx
cmpq %rcx, %r10
movq %r8, %rcx
cmovaq %rax, %rcx
movzwl (%rcx), %ebx
movswl %bx, %r8d
movswl %di, %r10d
cmpw %di, %si
jg 0xa75d
cmpw %di, %bx
jl 0xa75d
movswl %si, %esi
leal (,%r8,4), %ecx
leal (%rsi,%rsi,2), %edi
addl %r10d, %edi
subl %edi, %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rdi # imm = 0x2AAAAAAB
movq %rdi, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rdi
addl %ecx, %edi
movswl %di, %ecx
movl %edi, %ebx
andl $0x1, %ebx
subl %ebx, %ecx
subl %r10d, %r8d
leal (%r8,%r8), %ebx
cmpl %ebx, %ecx
jle 0xa6df
leal 0x1(,%r8,2), %edi
movswl %di, %ecx
movl %ecx, %r8d
andl $0x1, %r8d
addl %ecx, %r8d
subl %esi, %r10d
addl %r10d, %r10d
cmpl %r10d, %r8d
jg 0xa6fa
movl %edi, %r10d
movl %r10d, %ecx
addl 0xc(%rsp), %ecx
subl %ecx, %r11d
movq 0xa8(%rsp), %rcx
addq %rbp, %rcx
cmpq %rcx, 0x98(%rsp)
leaq 0x12c(%rsp), %rcx
cmovaq %rdx, %rcx
movw %r11w, (%rcx)
incq %rbp
addq $0x2, %r9
addq $0x2, %r14
addq $0x2, %r12
addq $0x2, %r13
addq $0x2, %r15
addq $0x2, %rax
addq $0x2, %rdx
cmpq %rbp, 0x20(%rsp)
movq 0x38(%rsp), %r8
movq 0x40(%rsp), %r10
jne 0xa573
jmp 0xa7d2
xorl %ecx, %ecx
cmpw %di, %si
jl 0xa6fd
cmpw %di, %bx
jg 0xa6fd
movswl %si, %esi
leal (,%r8,4), %ecx
leal (%rsi,%rsi,2), %edi
addl %r10d, %edi
subl %edi, %ecx
addl $-0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rdi # imm = 0x2AAAAAAB
movq %rdi, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rdi
addl %ecx, %edi
movswl %di, %ecx
movl %edi, %ebx
andl $0x1, %ebx
addl %ecx, %ebx
subl %r10d, %r8d
leal (%r8,%r8), %ecx
cmpl %ecx, %ebx
jge 0xa7b3
leal -0x1(,%r8,2), %edi
movl %edi, %ecx
andl $0xfffe, %ecx           # imm = 0xFFFE
movswl %cx, %ecx
subl %esi, %r10d
addl %r10d, %r10d
cmpl %ecx, %r10d
jle 0xa6f7
jmp 0xa6fa
movq 0x30(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x80(%rsp), %r14
movq 0x10(%rsp), %r12
jmp 0xa7f5
movq (%rsp), %rcx
incq %rcx
movq %rcx, (%rsp)
cmpq 0x28(%rsp), %rcx
jne 0xa48d
testb $0x1, 0x1c(%r12)
je 0xa893
movslq 0xe0(%rsp), %rax
testq %rax, %rax
jle 0xa893
leaq 0xec(%rsp), %rcx
movslq -0x8(%rcx), %rdx
decq %rdx
movslq %edx, %rdi
movslq 0x18(%r12), %rsi
imulq %rdi, %rsi
movq (%r12), %r9
movq 0x8(%r12), %rdi
subq %r9, %rdi
sarq %rdi
addq $0x24, %r12
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 %r12, %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 0xa864
movq 0x48(%rsp), %rbx
addq (%rbx), %r14
leaq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0xe5dc
movq 0x100(%rsp), %rax
movq %rax, 0x38(%r14)
movups 0xe0(%rsp), %xmm0
movups 0xf0(%rsp), %xmm1
movups %xmm1, 0x28(%r14)
movups %xmm0, 0x18(%r14)
movslq 0x8(%rsp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
leaq 0x108(%rsp), %rdx
movq %rbx, %rdi
callq 0xde8a
movq 0x108(%rsp), %rdi
testq %rdi, %rdi
je 0xa90a
movq 0x118(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0xa927
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa93b
movq %rax, %rbx
movq 0x108(%rsp), %rdi
testq %rdi, %rdi
je 0xa960
movq 0x118(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0xa960
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0xa97d
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3590