// File: /workspace/github_cpp_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movslq %esi, %rbp
movq %rbp, 0x8(%rsp)
movq %rdi, 0x58(%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 0xc8(%rsp), %r13
movq %r13, %rdi
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0xdc18
addq $0x20, %rsp
movl 0x3c(%r14,%rbp), %eax
movl %eax, 0x3c(%r13)
movl 0x18(%r14,%rbp), %r8d
movl 0x18(%r13), %r9d
leaq 0x216ff(%rip), %rsi     # 0x25be0
movl $0x4, %edi
movq 0x8(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x1d0d6
movq %rbp, 0x50(%rsp)
leaq (%r14,%rbp), %rax
movq %rax, 0x18(%rsp)
movslq 0x1c(%rax), %rax
movq %rax, 0xa8(%rsp)
testq %rax, %rax
jle 0x49c7
addq %rbx, %r14
movq 0x18(%rsp), %rax
movslq 0x18(%rax), %rcx
movq (%rax), %rsi
movl 0x18(%r14), %edx
movq (%r14), %rdi
movq 0x8(%r14), %r8
subq %rdi, %r8
sarq %r8
movq %r8, 0x40(%rsp)
addq $0x24, %r14
leaq 0xec(%rsp), %r8
movslq -0xc(%r8), %r9
movq -0x24(%r8), %r12
movq -0x1c(%r8), %r8
subq %r12, %r8
sarq %r8
movq %r8, 0x10(%rsp)
leaq -0x1(%rcx), %r8
movq %r8, 0x68(%rsp)
addq $0x24, %rax
movq %rax, 0x60(%rsp)
movq %rdx, 0xc0(%rsp)
movslq %edx, %r10
leaq 0x2(%rsi), %rax
movq %rax, 0x8(%rsp)
movq %r9, %rax
shlq $0x20, %rax
movq %rax, 0x80(%rsp)
movq %rcx, 0x48(%rsp)
leaq (%rcx,%rcx), %rax
movq %rax, 0x78(%rsp)
movq %rdi, 0x98(%rsp)
leaq 0x2(%rdi), %rax
movq %rax, 0x30(%rsp)
leaq (%r10,%r10), %rax
movq %rax, 0x70(%rsp)
movabsq $0x300000000, %rax      # imm = 0x300000000
movq %rax, 0x28(%rsp)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x20(%rsp)
movq $0x0, 0x38(%rsp)
xorl %r15d, %r15d
movq %rsi, 0xa0(%rsp)
movq %r9, 0x90(%rsp)
movq %r10, 0x88(%rsp)
movq %r15, %rdi
movq 0x48(%rsp), %rcx
imulq %rcx, %rdi
movzwl (%rsi,%rdi,2), %eax
movl %eax, %edx
cmpl $0x2, %ecx
jl 0x461b
movzwl 0x2(%rsi,%rdi,2), %edx
movq %rdi, 0xb0(%rsp)
movswl %ax, %ecx
movswl %dx, %edx
leal (%rdx,%rdx,2), %esi
negl %esi
leal (%rcx,%rcx,2), %eax
cmpw %dx, %cx
jge 0x4678
addl %esi, %eax
addl $-0x6, %eax
cltq
imulq $0x2aaaaaab, %rax, %rax # imm = 0x2AAAAAAB
movq %rax, %rsi
shrq $0x3f, %rsi
sarq $0x21, %rax
addl %esi, %eax
movl %eax, %esi
andl $0x1, %esi
addl %eax, %esi
movl $0xffff, %esi           # imm = 0xFFFF
cmovsl %esi, %eax
movl %eax, %esi
andl $0xfffe, %esi           # imm = 0xFFFE
movswl %si, %edi
movl %ecx, %esi
subl %edx, %esi
addl %esi, %esi
cmpl %edi, %esi
cmovlel %eax, %esi
jmp 0x46b7
addl %esi, %eax
addl $0x6, %eax
cltq
imulq $0x2aaaaaab, %rax, %rdi # imm = 0x2AAAAAAB
movq %rdi, %rsi
shrq $0x3f, %rsi
shrq $0x21, %rdi
addl %esi, %edi
cmpl $0x18, %eax
movl $0x1, %eax
cmovgel %eax, %edi
movswl %di, %eax
movl %eax, %r8d
andl $0x1, %r8d
addl %eax, %r8d
movl %ecx, %esi
subl %edx, %esi
addl %esi, %esi
cmpl %esi, %r8d
cmovlel %edi, %esi
movq %r15, %rax
imulq %r10, %rax
cmpq %rax, 0x40(%rsp)
movq 0x98(%rsp), %rdx
leaq (%rdx,%rax,2), %rax
cmovbeq %r14, %rax
addw (%rax), %si
movswl %si, %eax
movl %eax, %edx
andl $0x1, %edx
movl %edx, %edi
negl %edi
testw %ax, %ax
cmovlel %edx, %edi
leal (%rax,%rcx,2), %eax
addl %eax, %edi
sarl %edi
movl %edi, %eax
subl %esi, %eax
movq %r15, 0xb8(%rsp)
imulq %r9, %r15
movq 0x10(%rsp), %r8
cmpq %r15, %r8
leaq (%r12,%r15,2), %rcx
leaq 0xec(%rsp), %rsi
cmovbeq %rsi, %rcx
leaq 0x1(%r15), %rdx
cmpq %rdx, %r8
leaq 0x2(%r12,%r15,2), %rdx
cmovbeq %rsi, %rdx
movw %di, (%rcx)
movw %ax, (%rdx)
cmpl $0x2, %r10d
jl 0x4918
movl $0x1, %ebp
movq 0x30(%rsp), %r9
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %rcx
movabsq $0x200000000, %rdx      # imm = 0x200000000
movq %rbp, %rsi
movq 0x38(%rsp), %rax
addq %rbp, %rax
cmpq %rax, 0x40(%rsp)
movq %r14, %r13
movq %r14, %r8
cmovaq %r9, %r8
movq 0x8(%rsp), %rax
movzwl -0x2(%rax,%rbp,2), %r14d
incq %rbp
movl %r14d, %edi
cmpq 0x48(%rsp), %rbp
jge 0x4790
movq 0x8(%rsp), %rax
movzwl (%rax,%rsi,2), %edi
movswl %r14w, %r10d
movq %rbx, %rax
sarq $0x1f, %rax
movzwl (%r12,%rax), %eax
movswl %ax, %r11d
cmpw %di, %r10w
jl 0x4818
cmpw %r14w, %ax
jl 0x4818
movswl %di, %edi
leal (,%r11,4), %eax
leal (%rdi,%rdi,2), %esi
addl %r10d, %esi
subl %esi, %eax
addl $0x6, %eax
cltq
imulq $0x2aaaaaab, %rax, %r14 # imm = 0x2AAAAAAB
movq %r14, %rax
shrq $0x3f, %rax
sarq $0x21, %r14
addl %eax, %r14d
movswl %r14w, %eax
movl %r14d, %esi
andl $0x1, %esi
subl %esi, %eax
subl %r10d, %r11d
leal (%r11,%r11), %esi
cmpl %esi, %eax
jle 0x47fc
leal 0x1(,%r11,2), %r14d
movswl %r14w, %eax
movl %eax, %r11d
andl $0x1, %r11d
addl %eax, %r11d
movl %r10d, %esi
subl %edi, %esi
addl %esi, %esi
cmpl %esi, %r11d
jle 0x4886
jmp 0x4889
xorl %esi, %esi
cmpw %di, %r14w
jg 0x4889
cmpw %r14w, %ax
jg 0x4889
movswl %di, %edi
leal (,%r11,4), %eax
leal (%rdi,%rdi,2), %esi
addl %r10d, %esi
subl %esi, %eax
addl $-0x6, %eax
cltq
imulq $0x2aaaaaab, %rax, %r14 # imm = 0x2AAAAAAB
movq %r14, %rax
shrq $0x3f, %rax
sarq $0x21, %r14
addl %eax, %r14d
movswl %r14w, %eax
movl %r14d, %esi
andl $0x1, %esi
addl %eax, %esi
subl %r10d, %r11d
leal (%r11,%r11), %eax
cmpl %eax, %esi
jge 0x4872
leal -0x1(,%r11,2), %r14d
movl %r14d, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
cwtl
movl %r10d, %esi
subl %edi, %esi
addl %esi, %esi
cmpl %eax, %esi
jg 0x4889
movl %r14d, %esi
movzwl (%r8), %eax
addl %eax, %esi
movswl %si, %eax
leal (%rax,%r10,2), %r8d
movl %eax, %r10d
andl $0x1, %r10d
movl %r10d, %edi
negl %edi
testw %ax, %ax
cmovlel %r10d, %edi
addl %r8d, %edi
sarl %edi
movq %rdx, %rax
sarq $0x20, %rax
addq %r15, %rax
movq 0x10(%rsp), %r10
cmpq %rax, %r10
leaq (%r12,%rax,2), %rax
leaq 0xec(%rsp), %r8
cmovbeq %r8, %rax
movw %di, (%rax)
subl %esi, %edi
movq %rcx, %rax
sarq $0x20, %rax
movq %rcx, %rsi
sarq $0x1f, %rsi
addq %r12, %rsi
cmpq %rax, %r10
cmovbeq %r8, %rsi
movw %di, (%rsi)
movabsq $0x200000000, %rax      # imm = 0x200000000
addq %rax, %rdx
addq %rax, %rcx
addq %rax, %rbx
addq $0x2, %r9
cmpq %rbp, 0xc0(%rsp)
movq %r13, %r14
jne 0x4755
movq 0x90(%rsp), %r9
testb $0x1, %r9b
movq 0xa0(%rsp), %rsi
je 0x497b
movq 0xb0(%rsp), %rcx
addq 0x68(%rsp), %rcx
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
subq %rsi, %rax
sarq %rax
cmpq %rcx, %rax
leaq (%rsi,%rcx,2), %rax
cmovbeq 0x60(%rsp), %rax
movzwl (%rax), %eax
leal (%r15,%r9), %ecx
decl %ecx
movslq %ecx, %rcx
cmpq %rcx, 0x10(%rsp)
leaq (%r12,%rcx,2), %rcx
leaq 0xec(%rsp), %rdx
cmovbeq %rdx, %rcx
movw %ax, (%rcx)
movq 0xb8(%rsp), %r15
incq %r15
movq 0x78(%rsp), %rax
addq %rax, 0x8(%rsp)
movq 0x80(%rsp), %rax
addq %rax, 0x28(%rsp)
addq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
addq %rax, 0x30(%rsp)
movq 0x88(%rsp), %r10
addq %r10, 0x38(%rsp)
cmpq 0xa8(%rsp), %r15
jne 0x45ff
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %rax
addq (%rax), %rbx
leaq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0xe65e
leaq 0xe0(%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 0x4a1c
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x4a4e
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x35a0