// File: /workspace/github_cpp_makefile_star2_O2/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 $0xb8, %rsp
movl %edx, %ecx
movslq %esi, %rdx
movq %rdi, 0x28(%rsp)
movq (%rdi), %rbp
movq %rdx, %r13
shlq $0x6, %r13
leaq 0x162de(%rip), %rsi     # 0x1dbc4
pushq $0x4
popq %rdi
movl %ecx, 0xc(%rsp)
xorl %eax, %eax
callq 0x16c30
movl 0x18(%rbp,%r13), %eax
movl 0x1c(%rbp,%r13), %r10d
incl %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movswl 0x20(%rbp,%r13), %ecx
movswl 0x22(%rbp,%r13), %r8d
movl 0x28(%rbp,%r13), %r9d
movl 0x2c(%rbp,%r13), %r11d
incl %r11d
movl 0x30(%rbp,%r13), %r14d
movl 0x34(%rbp,%r13), %r15d
incl %r15d
movl 0x38(%rbp,%r13), %r12d
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
movl %eax, %esi
movl %r10d, %edx
pushq %r12
movq %rbp, %r12
pushq %r15
pushq %r14
pushq %r11
callq 0xa470
addq $0x20, %rsp
movl 0x18(%rbp,%r13), %esi
movl 0x2c(%rbp,%r13), %eax
subl 0x18(%rbx), %esi
movl 0x1c(%rbx), %edx
movl 0x20(%rbx), %ecx
movzwl 0x22(%rbx), %edi
movl %ecx, %r8d
subl %edi, %r8d
subl %ecx, %edi
incl %eax
movl 0x30(%rbp,%r13), %r10d
movl 0x34(%rbp,%r13), %r11d
movq %r13, 0x20(%rsp)
movl 0x38(%rbp,%r13), %ebx
movswl %r8w, %ecx
movswl %di, %r8d
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %r9
pushq %rbx
pushq %r11
pushq %r10
pushq %rax
callq 0xa470
addq $0x20, %rsp
addq 0x20(%rsp), %r12
movl 0x3c(%r12), %eax
leaq 0x78(%rsp), %r15
movl %eax, 0x3c(%r15)
leaq 0x38(%rsp), %rcx
movl %eax, 0x3c(%rcx)
movq 0x28(%rsp), %rbx
xorl %r14d, %r14d
cmpl 0x94(%rsp), %r14d
jge 0x7b7a
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movl %eax, %ebp
movl %r14d, 0x8(%rsp)
cmpl 0x50(%rsp), %ebx
jge 0x7b36
leal 0x1(%rbp), %edx
movq %r12, %rdi
movl %r14d, %esi
callq 0xa79e
movq %rbp, %r13
movl %eax, %ebp
leal 0x2(%r13), %edx
movq %r12, %rdi
movl %r14d, %esi
movl %edx, 0x1c(%rsp)
callq 0xa79e
movl %ebp, 0x18(%rsp)
movswl %bp, %esi
movl %eax, 0x14(%rsp)
movswl %ax, %ecx
xorl %ebp, %ebp
cmpw %cx, %si
setg %bpl
addl %ecx, %ebp
addl %esi, %ebp
shrl %ebp
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0xa44a
movw %bp, (%rax)
incl %ebx
cmpl 0x50(%rsp), %ebx
movq %r13, 0x30(%rsp)
jge 0x7abc
leal 0x3(%r13), %edx
movl %edx, 0x4(%rsp)
movq %r12, %rdi
movl %r14d, %esi
callq 0xa79e
cwtl
movl %eax, 0x10(%rsp)
leal 0x4(%r13), %r15d
movq %r12, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0xa79e
movswl %ax, %r13d
addl 0x10(%rsp), %r13d
movq %r12, %rdi
movl %r14d, %esi
movl 0x4(%rsp), %edx
callq 0xa79e
movw %ax, 0x4(%rsp)
movq %r12, %rdi
movl %r14d, %esi
movl %r15d, %edx
leaq 0x78(%rsp), %r15
callq 0xa79e
xorl %r14d, %r14d
cmpw %ax, 0x4(%rsp)
setg %r14b
addl %r13d, %r14d
shrl %r14d
jmp 0x7ade
testb $0x1, 0x18(%r12)
movl %ebp, %r14d
je 0x7ade
movq 0x30(%rsp), %rax
leal 0x3(%rax), %edx
movq %r12, %rdi
movl 0x8(%rsp), %esi
callq 0xa79e
movl %eax, %r14d
movl %ebp, %eax
decl %ebx
movl 0x8(%rsp), %r13d
je 0x7af9
movq %r12, %rdi
movl %r13d, %esi
movq 0x30(%rsp), %rdx
callq 0xa79e
movswl %ax, %edi
movswl %bp, %esi
movswl %r14w, %edx
callq 0xa8fe
movl 0x14(%rsp), %ecx
addl %eax, %ecx
movl 0x18(%rsp), %ebp
subl %ecx, %ebp
leaq 0x38(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0xa44a
movw %bp, (%rax)
incl %ebx
movl 0x1c(%rsp), %eax
movl %eax, %ebp
movl %r13d, %r14d
jmp 0x79e4
testb $0x1, 0x18(%r12)
je 0x7b6d
movl 0x90(%rsp), %eax
leal -0x2(,%rax,2), %edx
movl %eax, %ebx
decl %ebx
movq %r12, %rdi
movl %r14d, %esi
callq 0xa79e
movl %eax, %ebp
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0xa44a
movw %bp, (%rax)
incl %r14d
movq 0x28(%rsp), %rbx
jmp 0x79ca
movq 0x20(%rsp), %rdi
addq (%rbx), %rdi
leaq 0x78(%rsp), %rsi
callq 0xa526
movslq 0xc(%rsp), %rsi
shlq $0x6, %rsi
addq (%rbx), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0xa7c8
leaq 0x38(%rsp), %rdi
callq 0xabc2
leaq 0x78(%rsp), %rdi
callq 0xabc2
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7bcd
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xabc2
jmp 0x7bdf
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xabc2
movq %rbx, %rdi
callq 0x35d0