// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movslq %esi, %rbp
movq %rbp, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movq (%rdi), %r13
shlq $0x6, %rbp
movslq %edx, %rbx
movq %rbx, %r14
shlq $0x6, %r14
movl 0x18(%r13,%r14), %esi
addl 0x18(%r13,%rbp), %esi
movswl 0x20(%r13,%rbp), %ecx
movswl 0x22(%r13,%rbp), %r8d
movl 0x1c(%r13,%rbp), %edx
movl 0x28(%r13,%rbp), %r9d
movl 0x2c(%r13,%rbp), %eax
decl %eax
movl 0x30(%r13,%rbp), %r10d
movl 0x34(%r13,%rbp), %r11d
decl %r11d
movl 0x38(%r13,%rbp), %r12d
leaq 0x28(%rsp), %r15
movq %r15, %rdi
pushq %r12
movq %rbp, %r12
pushq %r11
pushq %r10
pushq %rax
callq 0xa470
addq $0x20, %rsp
movl 0x3c(%r13,%rbp), %eax
movl %eax, 0x3c(%r15)
movl 0x18(%r13,%rbp), %r8d
movl 0x18(%r15), %r9d
leaq 0x19cff(%rip), %rsi     # 0x1db60
xorl %ebp, %ebp
pushq $0x4
popq %rdi
movq 0x8(%rsp), %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x16c30
leaq (%r12,%r13), %rax
addq %r13, %r14
leaq 0x28(%rsp), %r13
movq %r14, %r15
movq %rax, %r14
movq %r12, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %rax, 0x8(%rsp)
cmpl 0x1c(%r14), %ebp
jge 0x4042
movl 0x18(%r14), %edi
movl %edi, %ecx
imull %ebp, %ecx
movslq %ecx, %rax
movq (%r14), %rdx
movzwl (%rdx,%rax,2), %eax
movl %eax, %esi
cmpl $0x2, %edi
jl 0x3ec0
movl %ecx, %ecx
movzwl 0x2(%rdx,%rcx,2), %esi
movswl %ax, %ebx
movswl %si, %edx
movl %ebx, %edi
movl %ebx, %esi
callq 0xa8fe
movl %eax, %r14d
movq %r15, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xa79e
addl %r14d, %eax
movswl %ax, %ecx
leal (%rcx,%rbx,2), %edx
movl %ecx, %esi
andl $0x1, %esi
movl %esi, %edi
negl %edi
testw %cx, %cx
cmovlel %esi, %edi
addl %edx, %edi
sarl %edi
movl %edi, %r12d
subl %eax, %r12d
movslq 0x40(%rsp), %rax
movslq %ebp, %rcx
imulq %rax, %rcx
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rdx
subq %rax, %rdx
sarq %rdx
cmpq %rcx, %rdx
leaq (%rax,%rcx,2), %rax
leaq 0x4c(%rsp), %rcx
cmovbeq %rcx, %rax
movw %di, (%rax)
pushq $0x1
popq %r14
pushq $0x1
popq %rax
movl %eax, %ebx
movq %r13, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0xa44a
movw %r12w, (%rax)
cmpl 0x18(%r15), %r14d
jge 0x4005
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0xa79e
movl %eax, %r13d
movq 0x8(%rsp), %rdx
movl 0x18(%rdx), %edi
movl %ebp, %ecx
imull %edi, %ecx
movslq %ecx, %rax
addq %r14, %rax
movq (%rdx), %rsi
movzwl (%rsi,%rax,2), %eax
leal 0x1(%r14), %r8d
movl %eax, %edx
cmpl %edi, %r8d
jge 0x3f93
addl %r14d, %ecx
incl %ecx
movslq %ecx, %rcx
movzwl (%rsi,%rcx,2), %edx
movswl %ax, %r15d
movl 0x40(%rsp), %eax
imull %ebp, %eax
addl %ebx, %eax
cltq
movq 0x28(%rsp), %rcx
movswl (%rcx,%rax,2), %edi
movswl %dx, %edx
movl %r15d, %esi
callq 0xa8fe
addl %eax, %r13d
movswl %r13w, %eax
movl %eax, %ecx
andl $0x1, %ecx
movl %ecx, %r12d
negl %r12d
testw %ax, %ax
cmovlel %ecx, %r12d
leal (%rax,%r15,2), %eax
addl %eax, %r12d
sarl %r12d
leal 0x1(%rbx), %edx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
callq 0xa44a
movw %r12w, (%rax)
subl %r13d, %r12d
movq %r15, %r13
incq %r14
addl $0x2, %ebx
movq 0x20(%rsp), %r15
jmp 0x3f38
testb $0x1, 0x40(%rsp)
movq 0x18(%rsp), %r12
movq 0x8(%rsp), %r14
je 0x403b
movl 0x18(%r14), %edx
decl %edx
movq %r14, %rdi
movl %ebp, %esi
callq 0xa79e
movl %eax, %ebx
movl 0x40(%rsp), %edx
decl %edx
movq %r13, %rdi
movl %ebp, %esi
callq 0xa44a
movw %bx, (%rax)
incl %ebp
jmp 0x3e95
movq 0x10(%rsp), %rax
addq (%rax), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0xa526
leaq 0x28(%rsp), %rdi
callq 0xabc2
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xabc2
movq %rbx, %rdi
callq 0x35d0