// File: /workspace/github_cpp_makefile_star2_O1/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 $0x178, %rsp            # imm = 0x178
movl %edx, %ecx
movslq %esi, %rdx
movq %rdi, 0xa0(%rsp)
movq (%rdi), %r12
movq %rdx, %r14
shlq $0x6, %r14
leaq 0x1c04e(%rip), %rsi     # 0x25c44
movl $0x4, %edi
movl %ecx, 0x38(%rsp)
xorl %eax, %eax
callq 0x1d0d6
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 0xf8(%rsp), %r15
movq %r15, %rdi
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdc18
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 0x138(%rsp), %rdi
movl $0x1, %r9d
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xdc18
addq $0x20, %rsp
movq %r14, 0x98(%rsp)
addq %r14, %r12
movl 0x3c(%r12), %eax
movl %eax, 0x134(%rsp)
movl 0x3c(%r12), %eax
movl %eax, 0x174(%rsp)
movslq 0x114(%rsp), %rax
movq %rax, 0xd8(%rsp)
testq %rax, %rax
jle 0xa226
leaq 0x15c(%rsp), %rax
movl -0xc(%rax), %ecx
leaq 0x24(%r12), %rdx
movq %rdx, 0x78(%rsp)
leaq 0x11c(%rsp), %rdx
movslq -0xc(%rdx), %rsi
movq -0x24(%rdx), %rdi
movq -0x1c(%rdx), %rdx
subq %rdi, %rdx
sarq %rdx
movq %rdx, 0x70(%rsp)
movq -0x24(%rax), %rdx
movq -0x1c(%rax), %rax
movq %rdx, 0x60(%rsp)
subq %rdx, %rax
sarq %rax
movq %rax, 0xf0(%rsp)
movslq 0x18(%r12), %rax
movq %rax, 0x48(%rsp)
leaq -0x1(%rsi), %rax
movq %rax, 0xb0(%rsp)
addl %eax, %eax
cltq
movq %rax, 0xa8(%rsp)
movq %rcx, %rax
negq %rax
movq %rax, 0xe8(%rsp)
movq %rcx, 0xd0(%rsp)
movslq %ecx, %rax
movq %rsi, 0x40(%rsp)
leaq (%rsi,%rsi), %rcx
movq %rcx, 0xc8(%rsp)
movq %rax, 0x80(%rsp)
addq %rax, %rax
movq %rax, 0xc0(%rsp)
movq $0x0, 0x28(%rsp)
movq %rdi, 0xb8(%rsp)
movq %rdi, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, 0x68(%rsp)
cmpl $0x0, 0xd0(%rsp)
jle 0xa144
movq 0x68(%rsp), %rax
movslq 0x18(%rax), %rbp
movq (%rax), %r11
movq 0x8(%rax), %rsi
subq %r11, %rsi
sarq %rsi
movq 0x50(%rsp), %r10
imulq %rbp, %r10
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %r10, %rax
movq %rax, 0x90(%rsp)
movabsq $0x300000000, %rax      # imm = 0x300000000
addq %r10, %rax
movq %rax, 0x88(%rsp)
movabsq $0x200000000, %rax      # imm = 0x200000000
leaq (%r10,%rax), %r9
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r10
movq 0x10(%rsp), %r13
imulq %rbp, %r13
movq %rbp, 0xe0(%rsp)
imulq 0x58(%rsp), %rbp
addq %r11, %rbp
movl $0x1, %r15d
movq 0x60(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %r11, 0x8(%rsp)
movq %rsi, 0x30(%rsp)
cmpq %r13, %rsi
movq 0x78(%rsp), %r12
movq %r12, %rax
cmovaq %rbp, %rax
movq %r10, %rcx
sarq $0x20, %rcx
movq %r10, %r8
sarq $0x1f, %r8
addq %r11, %r8
cmpq %rcx, %rsi
cmovbeq %r12, %r8
movswl (%rax), %r14d
movswl (%r8), %ecx
movl %ecx, %eax
addl %r14d, %eax
xorl %ebx, %ebx
movl %ecx, 0x3c(%rsp)
cmpw %cx, %r14w
setg %bl
addl %eax, %ebx
shrl %ebx
movq 0x20(%rsp), %rax
addq %r15, %rax
decq %rax
cmpq %rax, 0x70(%rsp)
leaq 0x11c(%rsp), %rax
cmovaq %rdx, %rax
movw %bx, (%rax)
cmpq 0x80(%rsp), %r15
jge 0x9f4a
movq %r9, %rax
sarq $0x20, %rax
movq %r9, %rcx
sarq $0x1f, %rcx
addq %r11, %rcx
cmpq %rax, %rsi
cmovbeq %r12, %rcx
movswl (%rcx), %ecx
movq 0x88(%rsp), %r8
movq %r8, %rax
sarq $0x20, %rax
sarq $0x1f, %r8
addq %r11, %r8
cmpq %rax, %rsi
cmovbeq %r12, %r8
movswl (%r8), %r8d
movl %r8d, %r11d
addl %ecx, %r11d
xorl %eax, %eax
cmpw %r8w, %cx
setg %al
addl %r11d, %eax
shrl %eax
jmp 0x9f75
movl %ebx, %eax
testb $0x1, 0xe0(%rsp)
je 0x9f75
movq %r9, %rax
sarq $0x20, %rax
movq %r9, %rcx
sarq $0x1f, %rcx
addq 0x8(%rsp), %rcx
cmpq %rax, 0x30(%rsp)
cmovbeq %r12, %rcx
movzwl (%rcx), %eax
movl %ebx, %r11d
cmpq $0x1, %r15
je 0x9fa3
movq 0x90(%rsp), %r8
movq %r8, %rcx
sarq $0x20, %rcx
sarq $0x1f, %r8
addq 0x8(%rsp), %r8
cmpq %rcx, 0x30(%rsp)
cmovbeq %r12, %r8
movzwl (%r8), %r11d
movswl %r11w, %r8d
movswl %bx, %r12d
cmpw %bx, %ax
jg 0xa0ae
cmpw %bx, %r11w
jl 0xa0ae
cwtl
leal (,%r8,4), %ecx
leal (%rax,%rax,2), %r11d
addl %r12d, %r11d
subl %r11d, %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rbx # imm = 0x2AAAAAAB
movq %rbx, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rbx
addl %ecx, %ebx
movswl %bx, %ecx
movl %ebx, %r11d
andl $0x1, %r11d
subl %r11d, %ecx
subl %r12d, %r8d
leal (%r8,%r8), %r11d
cmpl %r11d, %ecx
jle 0xa00c
leal 0x1(,%r8,2), %ebx
movq 0x8(%rsp), %r11
movswl %bx, %ecx
movl %ecx, %r8d
andl $0x1, %r8d
addl %ecx, %r8d
subl %eax, %r12d
addl %r12d, %r12d
cmpl %r12d, %r8d
jg 0xa02c
movl %ebx, %r12d
movl %r12d, %ecx
addl 0x3c(%rsp), %ecx
subl %ecx, %r14d
movq 0x28(%rsp), %rax
addq %r15, %rax
decq %rax
cmpq %rax, 0xf0(%rsp)
leaq 0x15c(%rsp), %rax
cmovaq %rdi, %rax
movw %r14w, (%rax)
movabsq $0x200000000, %rax      # imm = 0x200000000
addq %rax, 0x90(%rsp)
addq %rax, 0x88(%rsp)
addq %rax, %r9
addq %rax, %r10
addq $0x2, %r13
addq $0x4, %rbp
addq $0x2, %rdx
addq $0x2, %rdi
movq 0xe8(%rsp), %rax
addq %r15, %rax
incq %rax
incq %r15
cmpq $0x1, %rax
movq 0x30(%rsp), %rsi
jne 0x9e8a
jmp 0xa144
xorl %ecx, %ecx
cmpw %bx, %ax
jl 0xa13a
cmpw %bx, %r11w
movq 0x8(%rsp), %r11
jg 0xa02f
cwtl
leal (,%r8,4), %ecx
leal (%rax,%rax,2), %r11d
addl %r12d, %r11d
subl %r11d, %ecx
addl $-0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rbx # imm = 0x2AAAAAAB
movq %rbx, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rbx
addl %ecx, %ebx
movswl %bx, %ecx
movl %ebx, %r11d
andl $0x1, %r11d
addl %ecx, %r11d
subl %r12d, %r8d
leal (%r8,%r8), %ecx
cmpl %ecx, %r11d
jge 0xa116
leal -0x1(,%r8,2), %ebx
movl %ebx, %ecx
andl $0xfffe, %ecx           # imm = 0xFFFE
movswl %cx, %ecx
subl %eax, %r12d
addl %r12d, %r12d
cmpl %ecx, %r12d
movq 0x8(%rsp), %r11
jle 0xa029
jmp 0xa02c
movq 0x8(%rsp), %r11
jmp 0xa02f
testb $0x1, 0x48(%rsp)
movq 0x68(%rsp), %r12
je 0xa1b6
movq 0x10(%rsp), %rsi
movq %rsi, %rax
imulq 0x48(%rsp), %rax
addq 0xa8(%rsp), %rax
movq (%r12), %rcx
movq 0x8(%r12), %rdx
subq %rcx, %rdx
sarq %rdx
cmpq %rax, %rdx
leaq (%rcx,%rax,2), %rax
cmovbeq 0x78(%rsp), %rax
movzwl (%rax), %eax
movq %rsi, %rcx
imulq 0x40(%rsp), %rcx
addq 0xb0(%rsp), %rcx
cmpq %rcx, 0x70(%rsp)
movq 0xb8(%rsp), %rdx
leaq (%rdx,%rcx,2), %rcx
leaq 0x11c(%rsp), %rdx
cmovbeq %rdx, %rcx
movw %ax, (%rcx)
movq 0x10(%rsp), %rcx
incq %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, 0x50(%rsp)
addq $0x2, 0x58(%rsp)
movq 0x20(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
addq 0xc8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xc0(%rsp), %rax
addq %rax, 0x60(%rsp)
movq 0x28(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rcx, 0x10(%rsp)
cmpq 0xd8(%rsp), %rcx
jne 0x9de4
movq 0xa0(%rsp), %rbx
movq 0x98(%rsp), %r14
addq (%rbx), %r14
leaq 0xf8(%rsp), %rsi
movq %r14, %rdi
callq 0xe65e
leaq 0x110(%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 0x38(%rsp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
leaq 0x138(%rsp), %rdx
movq %rbx, %rdi
callq 0xdf1c
movq 0x138(%rsp), %rdi
testq %rdi, %rdi
je 0xa2a3
movq 0x148(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0xa2c0
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa2d4
movq %rax, %rbx
movq 0x138(%rsp), %rdi
testq %rdi, %rdi
je 0xa2f9
movq 0x148(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0xa2f9
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
testq %rdi, %rdi
je 0xa316
movq 0x108(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x35a0