// File: /workspace/github_cpp_makefile_star2_O3/cloudinary[P]fuif/transform/squeeze.h
// Function: inv_hsqueeze(Image&, int, int)
void inv_hsqueeze(Image &input, int c, int rc) {
    const Channel &chin = input.channel[c];
    const Channel &chin_residual = input.channel[rc];
    Channel chout(chin.w + chin_residual.w, chin.h,chin.minval,chin.maxval,chin.q,chin.hshift-1,chin.vshift,chin.hcshift-1,chin.vcshift);
    chout.component = chin.component;
    v_printf(4,"Undoing horizontal squeeze of channel %i using residuals in channel %i (going from width %i to %i)\n",c,rc,chin.w,chout.w);

    for (int y=0; y<chin.h; y++) {
      pixel_type avg = chin.value_nocheck(y,0);
      pixel_type next_avg = (1<chin.w ? next_avg = chin.value_nocheck(y,1) : avg);
      pixel_type tendency=smooth_tendency(avg,avg,next_avg);
      pixel_type diff = chin_residual.value(y,0) + tendency;
      pixel_type A = ((avg<<1)+diff+(diff>0?-(diff&1):(diff&1)))>>1;
      pixel_type B = A-diff;
      chout.value(y,0) = A;
      chout.value(y,1) = B;
      for (int x=1; x<chin_residual.w; x++) {
        pixel_type diff_minus_tendency = chin_residual.value(y,x);
        pixel_type avg = chin.value_nocheck(y,x);
        pixel_type next_avg = (x+1<chin.w ? next_avg = chin.value_nocheck(y,x+1) : avg);
        pixel_type left = chout.value_nocheck(y,(x<<1)-1);
        pixel_type tendency=smooth_tendency(left,avg,next_avg);
        pixel_type diff = diff_minus_tendency + tendency;
//        pixel_type A = ((avg<<1)+diff+(diff&1))>>1;
        pixel_type A = ((avg<<1)+diff+(diff>0?-(diff&1):(diff&1)))>>1;
        chout.value(y,x<<1) = A;
        pixel_type B = A-diff;
        chout.value(y,(x<<1)+1) = B;
//        if (c==2 && chin.w == 1352 && x > 180 && x < 185 && y > 118 && y < 121) printf("Cg = avg=%i, diff=%i=%i+%i, A=%i,B=%i\n",avg,diff,diff_minus_tendency,tendency,A,B);
      }
/*
      for (int x=1; x<chin_residual.w; x++) {
        pixel_type diff_minus_tendency = chin_residual.value(y,x);
        pixel_type avg = chin.value(y,x);

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

        pixel_type diff = diff_minus_tendency + tendency;

        pixel_type A = ((avg<<1)+diff+(diff&1))>>1;
        pixel_type B = A-diff;
        chout.value(y,x*2) = A;
        chout.value(y,x*2+1) = B;
      }
*/
      if (chout.w & 1) chout.value(y,chout.w-1) = chin.value(y,chin.w-1);
    }
    input.channel[c] = chout;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movslq %esi, %rbp
movq %rbp, (%rsp)
movq %rdi, 0x40(%rsp)
movq (%rdi), %r14
shlq $0x6, %rbp
movslq %edx, %r15
movq %r15, %rbx
shlq $0x6, %rbx
movl 0x18(%r14,%rbx), %esi
addl 0x18(%r14,%rbp), %esi
movswl 0x20(%r14,%rbp), %ecx
movswl 0x22(%r14,%rbp), %r8d
movl 0x1c(%r14,%rbp), %edx
movl 0x28(%r14,%rbp), %r9d
movl 0x2c(%r14,%rbp), %eax
decl %eax
movl 0x30(%r14,%rbp), %r10d
movl 0x34(%r14,%rbp), %r11d
decl %r11d
movl 0x38(%r14,%rbp), %r12d
leaq 0xa8(%rsp), %r13
movq %r13, %rdi
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0xdb78
addq $0x20, %rsp
movl 0x3c(%r14,%rbp), %eax
movl %eax, 0x3c(%r13)
movl 0x18(%r14,%rbp), %r8d
movl 0x18(%r13), %r9d
leaq 0x21701(%rip), %rsi     # 0x25be0
movl $0x4, %edi
movq (%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x1cede
movq %rbp, 0x38(%rsp)
leaq (%r14,%rbp), %rax
movq %rax, 0x8(%rsp)
movslq 0x1c(%rax), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
jle 0x495d
addq %rbx, %r14
movq 0x8(%rsp), %rcx
movslq 0x18(%rcx), %rdx
movq (%rcx), %rsi
movl 0x18(%r14), %eax
movq (%r14), %rdi
movq 0x8(%r14), %r8
subq %rdi, %r8
sarq %r8
movq %r8, 0x28(%rsp)
addq $0x24, %r14
leaq 0xcc(%rsp), %r8
movl -0xc(%r8), %r9d
movq -0x24(%r8), %r11
movq -0x1c(%r8), %r15
subq %r11, %r15
sarq %r15
leaq -0x1(%rdx), %r8
movq %r8, 0x50(%rsp)
addq $0x24, %rcx
movq %rcx, 0x48(%rsp)
movq %r9, 0x18(%rsp)
movslq %r9d, %rbx
movslq %eax, %r12
leaq 0x4(%rsi), %rcx
movq %rcx, (%rsp)
movq %rdx, 0x30(%rsp)
leaq (%rdx,%rdx), %rcx
movq %rcx, 0x60(%rsp)
leaq -0x2(%rax,%rax), %rax
movq %rax, 0xa0(%rsp)
movq %rdi, 0x78(%rsp)
leaq 0x2(%rdi), %rax
movq %rax, 0x20(%rsp)
leaq (%r12,%r12), %rax
movq %rax, 0x58(%rsp)
movl $0x1, %eax
movq %rax, 0x10(%rsp)
xorl %edi, %edi
xorl %r10d, %r10d
movq %rsi, 0x80(%rsp)
movq %rbx, 0x70(%rsp)
movq %r12, 0x68(%rsp)
movq %r10, %rdx
movq 0x30(%rsp), %rcx
imulq %rcx, %rdx
movswl (%rsi,%rdx,2), %eax
cmpl $0x1, %ecx
movq %rdx, 0x90(%rsp)
jle 0x4645
movswl 0x2(%rsi,%rdx,2), %esi
cmpw %si, %ax
jge 0x4647
leal (%rsi,%rsi,2), %ecx
leal (%rax,%rax,2), %edx
subl %ecx, %edx
addl $-0x6, %edx
movslq %edx, %rcx
imulq $0x2aaaaaab, %rcx, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
movl %ecx, %edx
andl $0x1, %edx
addl %ecx, %edx
movl $0xffff, %edx           # imm = 0xFFFF
cmovsl %edx, %ecx
movl %ecx, %edx
andl $0xfffe, %edx           # imm = 0xFFFE
movswl %dx, %edx
movl %eax, %r8d
subl %esi, %r8d
addl %r8d, %r8d
cmpl %edx, %r8d
cmovlel %ecx, %r8d
jmp 0x4692
movl %eax, %esi
leal (%rsi,%rsi,2), %ecx
leal (%rax,%rax,2), %edx
subl %ecx, %edx
addl $0x6, %edx
movslq %edx, %rcx
imulq $0x2aaaaaab, %rcx, %rdx # imm = 0x2AAAAAAB
movq %rdx, %r8
shrq $0x3f, %r8
shrq $0x21, %rdx
addl %r8d, %edx
cmpl $0x18, %ecx
movl $0x1, %ecx
cmovgel %ecx, %edx
movswl %dx, %ecx
movl %ecx, %r9d
andl $0x1, %r9d
addl %ecx, %r9d
movl %eax, %r8d
subl %esi, %r8d
addl %r8d, %r8d
cmpl %r8d, %r9d
cmovlel %edx, %r8d
movq %r10, %rcx
imulq %r12, %rcx
cmpq %rcx, 0x28(%rsp)
movq 0x78(%rsp), %rdx
leaq (%rdx,%rcx,2), %rcx
cmovbeq %r14, %rcx
addw (%rcx), %r8w
movswl %r8w, %ecx
movl %ecx, %edx
andl $0x1, %edx
movl %edx, %esi
negl %esi
testw %cx, %cx
cmovlel %edx, %esi
leal (%rcx,%rax,2), %eax
addl %eax, %esi
sarl %esi
movl %esi, %eax
subl %r8d, %eax
movq %r10, 0x98(%rsp)
imulq %rbx, %r10
cmpq %r10, %r15
leaq (%r11,%r10,2), %rcx
leaq 0xcc(%rsp), %r8
cmovbeq %r8, %rcx
leaq 0x1(%r10), %rdx
cmpq %rdx, %r15
leaq 0x2(%r11,%r10,2), %rdx
cmovbeq %r8, %rdx
movw %si, (%rcx)
movw %ax, (%rdx)
cmpl $0x2, %r12d
jl 0x48c1
movl $0x2, %r12d
movq 0x10(%rsp), %rax
xorl %esi, %esi
movq 0x20(%rsp), %rcx
leaq (%rcx,%rsi), %rbp
cmpq %rax, 0x28(%rsp)
movq %r14, %r13
cmovbeq %r14, %rbp
movq (%rsp), %rcx
movzwl -0x2(%rcx,%rsi), %r9d
movl %r9d, %edx
cmpq 0x30(%rsp), %r12
jge 0x474b
movq (%rsp), %rcx
movzwl (%rcx,%rsi), %edx
movswl %r9w, %r14d
leal (%rdi,%rsi), %ecx
incl %ecx
movslq %ecx, %rcx
movzwl (%r11,%rcx,2), %ecx
movswl %cx, %r8d
cmpw %dx, %r14w
jl 0x47d4
cmpw %r9w, %cx
jl 0x47d4
movswl %dx, %r9d
leal (,%r8,4), %ecx
leal (%r9,%r9,2), %edx
addl %r14d, %edx
subl %edx, %ecx
addl $0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rdx # imm = 0x2AAAAAAB
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rdx
addl %ecx, %edx
movswl %dx, %ecx
movl %edx, %ebx
andl $0x1, %ebx
subl %ebx, %ecx
subl %r14d, %r8d
leal (%r8,%r8), %ebx
cmpl %ebx, %ecx
jle 0x47b8
leal 0x1(,%r8,2), %edx
movswl %dx, %ecx
movl %ecx, %r8d
andl $0x1, %r8d
addl %ecx, %r8d
movl %r14d, %ebx
subl %r9d, %ebx
addl %ebx, %ebx
cmpl %ebx, %r8d
jle 0x4845
jmp 0x4847
xorl %ebx, %ebx
cmpw %dx, %r9w
jg 0x4847
cmpw %r9w, %cx
jg 0x4847
movswl %dx, %r9d
leal (,%r8,4), %ecx
leal (%r9,%r9,2), %edx
addl %r14d, %edx
subl %edx, %ecx
addl $-0x6, %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rdx # imm = 0x2AAAAAAB
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rdx
addl %ecx, %edx
movswl %dx, %ecx
movl %edx, %ebx
andl $0x1, %ebx
addl %ecx, %ebx
subl %r14d, %r8d
leal (%r8,%r8), %ecx
cmpl %ecx, %ebx
jge 0x482e
leal -0x1(,%r8,2), %edx
movl %edx, %ecx
andl $0xfffe, %ecx           # imm = 0xFFFE
movswl %cx, %ecx
movl %r14d, %ebx
subl %r9d, %ebx
addl %ebx, %ebx
cmpl %ecx, %ebx
jg 0x4847
movl %edx, %ebx
movzwl (%rbp), %r8d
leal (%rdi,%rsi), %ecx
addl $0x3, %ecx
leaq 0x2(%rsi), %rdx
addl %r8d, %ebx
movswl %bx, %esi
leal (%rsi,%r14,2), %r8d
movl %esi, %r9d
andl $0x1, %r9d
movl %r9d, %ebp
negl %ebp
testw %si, %si
cmovlel %r9d, %ebp
addl %r8d, %ebp
sarl %ebp
movslq %edx, %rsi
addq %r10, %rsi
cmpq %rsi, %r15
leaq (%r11,%rsi,2), %rsi
leaq 0xcc(%rsp), %r8
cmovbeq %r8, %rsi
movw %bp, (%rsi)
subl %ebx, %ebp
movslq %ecx, %rcx
cmpq %rcx, %r15
leaq (%r11,%rcx,2), %rcx
cmovbeq %r8, %rcx
movw %bp, (%rcx)
incq %rax
incq %r12
movq %rdx, %rsi
cmpq %rdx, 0xa0(%rsp)
movq %r13, %r14
jne 0x471a
movq 0x70(%rsp), %rbx
testb $0x1, %bl
movq 0x80(%rsp), %rsi
je 0x4922
movq 0x90(%rsp), %rcx
addq 0x50(%rsp), %rcx
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq %rax
cmpq %rcx, %rax
leaq (%rsi,%rcx,2), %rax
cmovbeq 0x48(%rsp), %rax
movzwl (%rax), %eax
movq 0x18(%rsp), %rcx
addl %r10d, %ecx
decl %ecx
movslq %ecx, %rcx
cmpq %rcx, %r15
leaq (%r11,%rcx,2), %rcx
leaq 0xcc(%rsp), %rdx
cmovbeq %rdx, %rcx
movw %ax, (%rcx)
movq 0x98(%rsp), %r10
incq %r10
movq 0x60(%rsp), %rax
addq %rax, (%rsp)
addq 0x18(%rsp), %rdi
movq 0x58(%rsp), %rax
addq %rax, 0x20(%rsp)
movq 0x68(%rsp), %r12
addq %r12, 0x10(%rsp)
cmpq 0x88(%rsp), %r10
jne 0x45d0
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %rax
addq (%rax), %rbx
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0xe5dc
leaq 0xc0(%rsp), %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x38(%rbx)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x28(%rbx)
movups %xmm0, 0x18(%rbx)
movq -0x18(%rax), %rdi
testq %rdi, %rdi
je 0x49b2
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x49e4
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3590