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

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

    Channel chout((chin.w+1)/2, chin.h, chin.minval, chin.maxval, chin.q, chin.hshift+1,chin.vshift,chin.hcshift+1,chin.vcshift);
    Channel chout_residual(chin.w-chout.w,chout.h,chout.minval-chout.maxval,chout.maxval-chout.minval,1, chin.hshift+1,chin.vshift,chin.hcshift,chin.vcshift);
    chout.component = chin.component;
    chout_residual.component = chin.component;

    for (int y=0; y<chout.h; y++) {
      for (int x=0; x<chout_residual.w; x++) {
        pixel_type A = chin.value(y,x*2);
        pixel_type B = chin.value(y,x*2+1);
        pixel_type avg = (A+B+(A>B))>>1;
        chout.value(y,x) = avg;
        pixel_type diff = A-B;
        pixel_type next_avg = avg;
        if (x+1<chout_residual.w) next_avg = (chin.value(y,x*2+2) + chin.value(y,x*2+3) + (chin.value(y,x*2+2) > chin.value(y,x*2+3))) >> 1;  // which will be chout.value(y,x+1)
        else if (chin.w & 1) next_avg = (chin.value(y,x*2+2));

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

        chout_residual.value(y,x) = diff-tendency;

      }
      if (chin.w & 1) {
        int x = chout.w-1;
        chout.value(y,x) = chin.value(y,x*2);
      }
    }
    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, 0xa8(%rsp)
movq (%rdi), %r12
movq %rdx, %r14
shlq $0x6, %r14
leaq 0x1c0e4(%rip), %rsi     # 0x25c44
movl $0x4, %edi
movl %ecx, 0x30(%rsp)
xorl %eax, %eax
callq 0x1cede
movl 0x18(%r12,%r14), %eax
movl 0x1c(%r12,%r14), %edx
movl %eax, %ecx
incl %ecx
shrl $0x1f, %ecx
leal (%rax,%rcx), %esi
incl %esi
sarl %esi
movswl 0x20(%r12,%r14), %ecx
movswl 0x22(%r12,%r14), %r8d
movl 0x28(%r12,%r14), %r9d
movl 0x2c(%r12,%r14), %eax
incl %eax
movl 0x30(%r12,%r14), %r10d
movl 0x34(%r12,%r14), %r11d
incl %r11d
movl 0x38(%r12,%r14), %ebx
leaq 0x118(%rsp), %r15
movq %r15, %rdi
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdb78
addq $0x20, %rsp
movl 0x18(%r12,%r14), %esi
movl 0x2c(%r12,%r14), %eax
subl 0x18(%r15), %esi
movl 0x1c(%r15), %edx
movl 0x20(%r15), %ecx
movzwl 0x22(%r15), %edi
movl %ecx, %r8d
subl %edi, %r8d
subl %ecx, %edi
incl %eax
movl 0x30(%r12,%r14), %r10d
movl 0x34(%r12,%r14), %r11d
movl 0x38(%r12,%r14), %ebx
movswl %r8w, %ecx
movswl %di, %r8d
leaq 0x158(%rsp), %rdi
movl $0x1, %r9d
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdb78
addq $0x20, %rsp
movq %r14, 0xa0(%rsp)
addq %r14, %r12
movl 0x3c(%r12), %eax
movl %eax, 0x154(%rsp)
movl %eax, 0x194(%rsp)
movslq 0x134(%rsp), %rax
movq %rax, 0xf0(%rsp)
testq %rax, %rax
jle 0xa1ea
movabsq $0x200000000, %rcx      # imm = 0x200000000
leaq 0x17c(%rsp), %rax
movl -0xc(%rax), %edx
leaq 0x24(%r12), %rbx
leaq 0x13c(%rsp), %rsi
movslq -0xc(%rsi), %rdi
movq -0x24(%rsi), %r8
movq -0x1c(%rsi), %rsi
subq %r8, %rsi
sarq %rsi
movq %rsi, 0x80(%rsp)
movq -0x24(%rax), %rsi
movq -0x1c(%rax), %rax
movq %rsi, 0x68(%rsp)
subq %rsi, %rax
sarq %rax
movq %rax, 0x108(%rsp)
movslq 0x18(%r12), %rsi
leaq -0x1(%rdi), %rax
movq %rax, 0xb8(%rsp)
addl %eax, %eax
cltq
movq %rax, 0xb0(%rsp)
movq %rsi, %rax
shlq $0x20, %rax
movq %rax, 0xe0(%rsp)
movq %rdx, %rax
negq %rax
movq %rax, 0x100(%rsp)
movq %rdx, 0xe8(%rsp)
movslq %edx, %rax
leaq (%rsi,%rsi), %rdx
movq %rdx, 0xd8(%rsp)
movq %rdi, 0x38(%rsp)
leaq (%rdi,%rdi), %rdx
movq %rdx, 0xd0(%rsp)
movq %rax, 0x88(%rsp)
addq %rax, %rax
movq %rax, 0xc8(%rsp)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x60(%rsp)
movabsq $0x300000000, %rax      # imm = 0x300000000
movq %rax, 0x58(%rsp)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x50(%rsp)
movq $0x0, 0x20(%rsp)
movq %r8, 0xc0(%rsp)
movq %r8, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
xorl %edi, %edi
movq %rbx, 0x90(%rsp)
movq %r12, 0x70(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdi, 0xf8(%rsp)
cmpl $0x0, 0xe8(%rsp)
jle 0xa0ee
movq 0x70(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %r10
subq %rcx, %r10
sarq %r10
movq 0x8(%rsp), %rax
movq %rcx, 0x98(%rsp)
leaq (%rcx,%rax), %rdx
movl $0x1, %eax
movq 0x68(%rsp), %r8
movq 0x10(%rsp), %r15
movq 0x48(%rsp), %rbp
movq 0x50(%rsp), %r13
movq 0x40(%rsp), %r11
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %r14
movq %r10, 0x28(%rsp)
movq %rbp, 0x110(%rsp)
cmpq %rbp, %r10
movq %rbx, %rcx
cmovaq %rdx, %rcx
movq %r13, %rdi
sarq $0x20, %rdi
movq %r13, %r9
sarq $0x1f, %r9
movq 0x98(%rsp), %rbp
addq %rbp, %r9
cmpq %rdi, %r10
cmovbeq %rbx, %r9
movswl (%rcx), %r12d
movswl (%r9), %r9d
movl %r9d, %ecx
addl %r12d, %ecx
xorl %edi, %edi
movl %r9d, 0x34(%rsp)
cmpw %r9w, %r12w
setg %dil
addl %ecx, %edi
shrl %edi
movq 0x18(%rsp), %rcx
addq %rax, %rcx
decq %rcx
cmpq %rcx, 0x80(%rsp)
leaq 0x13c(%rsp), %rcx
cmovaq %r15, %rcx
movw %di, (%rcx)
cmpq 0x88(%rsp), %rax
movq %r15, (%rsp)
jge 0x9eef
movq %r11, %rcx
sarq $0x20, %rcx
movq %r11, %r9
sarq $0x1f, %r9
addq %rbp, %r9
cmpq %rcx, %r10
cmovbeq %rbx, %r9
movswl (%r9), %ecx
movq %rsi, %r9
sarq $0x20, %r9
movq %r8, %r15
movq %rdx, %r8
movq %r10, %rdx
movq %rsi, %r10
sarq $0x1f, %r10
addq %rbp, %r10
cmpq %r9, %rdx
movq %r8, %rdx
movq %r15, %r8
cmovbeq %rbx, %r10
movswl (%r10), %r9d
movl %r9d, %ebx
addl %ecx, %ebx
xorl %r10d, %r10d
cmpw %r9w, %cx
setg %r10b
addl %ebx, %r10d
movq 0x90(%rsp), %rbx
shrl %r10d
jmp 0x9f17
movl %edi, %r10d
testb $0x1, 0x78(%rsp)
je 0x9f17
movq %r11, %rcx
sarq $0x20, %rcx
movq %r11, %r9
sarq $0x1f, %r9
addq %rbp, %r9
cmpq %rcx, 0x28(%rsp)
cmovbeq %rbx, %r9
movzwl (%r9), %r10d
movl %edi, %r15d
cmpq $0x1, %rax
je 0x9f43
movq %r14, %rcx
sarq $0x20, %rcx
movq %r14, %r9
sarq $0x1f, %r9
addq 0x98(%rsp), %r9
cmpq %rcx, 0x28(%rsp)
cmovbeq %rbx, %r9
movzwl (%r9), %r15d
movswl %r15w, %ebx
movswl %di, %r9d
cmpw %di, %r10w
jg 0xa056
cmpw %di, %r15w
jl 0xa056
movswl %r10w, %edi
leal (,%rbx,4), %ecx
leal (%rdi,%rdi,2), %r10d
addl %r9d, %r10d
subl %r10d, %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %r10 # imm = 0x2AAAAAAB
movq %r10, %rcx
shrq $0x3f, %rcx
sarq $0x21, %r10
addl %ecx, %r10d
movswl %r10w, %ecx
movl %r10d, %r15d
andl $0x1, %r15d
subl %r15d, %ecx
subl %r9d, %ebx
leal (%rbx,%rbx), %r15d
cmpl %r15d, %ecx
jle 0x9fb1
leal 0x1(,%rbx,2), %r10d
movq (%rsp), %r15
movswl %r10w, %ecx
movl %ecx, %ebx
andl $0x1, %ebx
addl %ecx, %ebx
subl %edi, %r9d
addl %r9d, %r9d
cmpl %r9d, %ebx
jg 0x9fce
movl %r10d, %r9d
movl %r9d, %ecx
addl 0x34(%rsp), %ecx
subl %ecx, %r12d
movq 0x20(%rsp), %rcx
addq %rax, %rcx
decq %rcx
cmpq %rcx, 0x108(%rsp)
leaq 0x17c(%rsp), %rcx
cmovaq %r8, %rcx
movw %r12w, (%rcx)
movabsq $0x200000000, %rcx      # imm = 0x200000000
addq %rcx, %r14
addq %rcx, %rsi
addq %rcx, %r11
addq %rcx, %r13
movq 0x110(%rsp), %rbp
addq $0x2, %rbp
addq $0x4, %rdx
addq $0x2, %r15
addq $0x2, %r8
movq 0x100(%rsp), %rcx
addq %rax, %rcx
incq %rcx
incq %rax
cmpq $0x1, %rcx
movq 0x90(%rsp), %rbx
movq 0x28(%rsp), %r10
jne 0x9e05
jmp 0xa0ee
xorl %ecx, %ecx
cmpw %di, %r10w
jl 0xa0e5
cmpw %di, %r15w
movq (%rsp), %r15
jg 0x9fd1
movswl %r10w, %edi
leal (,%rbx,4), %ecx
leal (%rdi,%rdi,2), %r10d
addl %r9d, %r10d
subl %r10d, %ecx
addl $-0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %r10 # imm = 0x2AAAAAAB
movq %r10, %rcx
shrq $0x3f, %rcx
sarq $0x21, %r10
addl %ecx, %r10d
movswl %r10w, %ecx
movl %r10d, %r15d
andl $0x1, %r15d
addl %ecx, %r15d
subl %r9d, %ebx
leal (%rbx,%rbx), %ecx
cmpl %ecx, %r15d
jge 0xa0c1
leal -0x1(,%rbx,2), %r10d
movl %r10d, %ecx
andl $0xfffe, %ecx           # imm = 0xFFFE
movswl %cx, %ecx
subl %edi, %r9d
addl %r9d, %r9d
cmpl %ecx, %r9d
movq (%rsp), %r15
jle 0x9fcb
jmp 0x9fce
movq (%rsp), %r15
jmp 0x9fd1
movq 0x78(%rsp), %rsi
testb $0x1, %sil
movq 0x70(%rsp), %r12
movq 0xf8(%rsp), %rdi
je 0xa166
movq %rdi, %rax
imulq %rsi, %rax
addq 0xb0(%rsp), %rax
movq (%r12), %rcx
movq 0x8(%r12), %rdx
subq %rcx, %rdx
sarq %rdx
cmpq %rax, %rdx
leaq (%rcx,%rax,2), %rax
cmovbeq %rbx, %rax
movzwl (%rax), %eax
movq %rdi, %rcx
imulq 0x38(%rsp), %rcx
addq 0xb8(%rsp), %rcx
cmpq %rcx, 0x80(%rsp)
movq 0xc0(%rsp), %rdx
leaq (%rdx,%rcx,2), %rcx
leaq 0x13c(%rsp), %rdx
cmovbeq %rdx, %rcx
movw %ax, (%rcx)
incq %rdi
movq 0xe0(%rsp), %rax
addq %rax, 0x60(%rsp)
addq %rax, 0x58(%rsp)
addq %rax, 0x40(%rsp)
addq %rax, 0x50(%rsp)
addq %rsi, 0x48(%rsp)
movq 0x8(%rsp), %rax
addq 0xd8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
addq 0x38(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
addq 0xd0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xc8(%rsp), %rax
addq %rax, 0x68(%rsp)
movq 0x20(%rsp), %rax
addq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq 0xf0(%rsp), %rdi
jne 0x9d9f
movq 0xa8(%rsp), %rbx
movq 0xa0(%rsp), %r14
addq (%rbx), %r14
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
callq 0xe5dc
leaq 0x130(%rsp), %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x38(%r14)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x28(%r14)
movups %xmm0, 0x18(%r14)
movslq 0x30(%rsp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
leaq 0x158(%rsp), %rdx
movq %rbx, %rdi
callq 0xde8a
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
je 0xa267
movq 0x168(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0xa284
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 0xa298
movq %rax, %rbx
movq 0x158(%rsp), %rdi
testq %rdi, %rdi
je 0xa2bd
movq 0x168(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0xa2bd
movq %rax, %rbx
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0xa2da
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3590