// File: /workspace/github_cpp_makefile_star2_O2/cloudinary[P]fuif/transform/subsample.h
// Function: inv_subsample(Image&, std::vector<int, std::allocator<int>>)
bool inv_subsample(Image &input, std::vector<int> parameters) {
    check_subsample_parameters(parameters);

    for (int i=0; i<parameters.size(); i+=4) {
        int c1 = parameters[i+0];
        int c2 = parameters[i+1];
        int srh = parameters[i+2];
        int srv = parameters[i+3];
        for (int c=c1; c<=c2; c++) {
         int ow = input.channel[c].w;
         int oh = input.channel[c].h;
         if (ow >= input.channel[input.nb_meta_channels].w && oh >= input.channel[input.nb_meta_channels].h) {
            // this can happen in case of LQIP and 1:16 scale decodes
            v_printf(5,"Skipping upscaling of channel %i because it is already as large as channel %i.\n",c,input.nb_meta_channels);
            continue;
         }
         Channel channel(ow*srh,oh*srv,input.channel[c].minval,input.channel[c].maxval);
         if (srv <= 2 && srh <= 2) {
          // 'fancy' horizontal upscale
          if (srh == 2) {
           for (int y=0; y<oh; y++) {
            for (int x=0; x<ow; x++) {
             channel.value(y*srv,x*srh) =   (3*input.channel[c].value(y,x) + input.channel[c].value(y,(x?x-1:0)) + 1)>>2;
             channel.value(y*srv,x*srh+1) = (3*input.channel[c].value(y,x) + input.channel[c].value(y,(x+1<ow?x+1:x)) + 2)>>2;
            }
           }
          } else {
           for (int y=0; y<oh; y++) {
            for (int x=0; x<ow; x++) {
             channel.value(y*srv,x) = input.channel[c].value(y,x);
            }
           }
          }
          if (srv == 2) {
           Channel orig = channel;
           for (int y=0; y<oh; y++) {
            for (int x=0; x<ow*srh; x++) {
             channel.value(y*srv,x) =   (3*orig.value(y*srv,x) + orig.value((y?(y-1)*srv:0),x) + 1)>>2;
             channel.value(y*srv+1,x) = (3*orig.value(y*srv,x) + orig.value((y+1<oh?(y+1)*srv:y*srv),x) + 2)>>2;
            }
           }
          }
         } else {
         // simple box filter upscaling. fancier upscaling could be done too...
          for (int y=0; y<oh*srv; y++) {
           for (int x=0; x<ow*srh; x++) {
             channel.value(y,x) = input.channel[c].value(y/srv,x/srh);
           }
          }
         }
         v_printf(5,"Upscaled channel %i from %ix%i to %ix%i\n",c,input.channel[c].w,input.channel[c].h,channel.w,channel.h);
         input.channel[c] = channel;
        }
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %r12
movq %rsi, 0x58(%rsp)
movq %rsi, %rdi
callq 0x589f
leaq 0x78(%rsp), %r13
xorl %r15d, %r15d
movq %r12, 0x48(%rsp)
movq 0x58(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
jbe 0x5eb3
movslq (%rax,%r15,4), %r14
movslq 0x4(%rax,%r15,4), %rcx
movq %rcx, 0x68(%rsp)
movl 0x8(%rax,%r15,4), %edi
movl 0xc(%rax,%r15,4), %eax
movl %eax, 0x10(%rsp)
cmpl $0x3, %eax
setl %al
cmpl $0x3, %edi
setl %cl
andb %al, %cl
movb %cl, 0xb(%rsp)
movq %r15, 0x60(%rsp)
movl %edi, 0x24(%rsp)
cmpq 0x68(%rsp), %r14
jg 0x5eaa
movq (%r12), %rax
movq %r14, %rcx
shlq $0x6, %rcx
movl 0x18(%rax,%rcx), %esi
movq %rcx, 0x28(%rsp)
movl 0x1c(%rax,%rcx), %ebp
movslq 0x6c(%r12), %rcx
movq %rcx, %rdx
shlq $0x6, %rdx
movl %esi, 0x1c(%rsp)
cmpl 0x18(%rax,%rdx), %esi
jl 0x5a87
addq %rax, %rdx
cmpl 0x1c(%rdx), %ebp
jge 0x5c9e
addq 0x28(%rsp), %rax
movl 0x1c(%rsp), %r15d
imull %edi, %r15d
movl %ebp, %ebx
imull 0x10(%rsp), %ebx
movswl 0x20(%rax), %ecx
movswl 0x22(%rax), %r8d
movq %r13, %rdi
movl %r15d, %esi
movl %ebx, %edx
pushq $0x1
popq %r9
pushq $0x0
pushq $0x0
pushq $0x0
pushq $0x0
callq 0xa470
addq $0x20, %rsp
cmpb $0x0, 0xb(%rsp)
movq %r14, 0x70(%rsp)
je 0x5c38
movl %r15d, 0x14(%rsp)
movl 0x1c(%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movl %eax, 0x18(%rsp)
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movl %eax, 0x38(%rsp)
cmpl $0x2, 0x24(%rsp)
movl %ebp, 0x34(%rsp)
jne 0x5cbb
xorl %eax, %eax
movl 0x14(%rsp), %ebp
cmpl 0x38(%rsp), %eax
je 0x5d09
movl %eax, 0x3c(%rsp)
imull 0x10(%rsp), %eax
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
pushq $0x1
popq %rax
movq %rax, 0x40(%rsp)
movl 0x18(%rsp), %ecx
movl %ebp, %r14d
subl $0x1, %r14d
movl $0x0, %eax
cmovbl %eax, %r14d
subl $0x1, %ecx
jb 0x5c23
movq 0x48(%rsp), %rbx
movq (%rbx), %rdi
movq 0x28(%rsp), %r15
addq %r15, %rdi
movl 0x3c(%rsp), %r12d
movl %r12d, %esi
movl %ebp, %edx
movl %ecx, 0x20(%rsp)
callq 0xa44a
movswl (%rax), %eax
leal (%rax,%rax,2), %r13d
movq (%rbx), %rdi
addq %r15, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0xa44a
movswl (%rax), %eax
leal (%rax,%r13), %r14d
incl %r14d
shrl $0x2, %r14d
movq 0x40(%rsp), %r13
leal -0x1(%r13), %edx
leaq 0x78(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0xa44a
movw %r14w, (%rax)
movq (%rbx), %rdi
addq %r15, %rdi
movl %r12d, %esi
movl %r12d, %r14d
movl %ebp, %edx
callq 0xa44a
movswl (%rax), %eax
leal (%rax,%rax,2), %eax
movq %rax, 0x50(%rsp)
movq (%rbx), %rdi
addq %r15, %rdi
leal 0x1(%rbp), %r12d
cmpl 0x1c(%rsp), %r12d
cmovll %r12d, %ebp
movl %r14d, %esi
movl %ebp, %edx
callq 0xa44a
movswl (%rax), %eax
movq 0x50(%rsp), %rcx
leal (%rax,%rcx), %ebp
addl $0x2, %ebp
shrl $0x2, %ebp
leaq 0x78(%rsp), %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
callq 0xa44a
movl 0x20(%rsp), %ecx
movw %bp, (%rax)
addl $0x2, %r13d
movq %r13, 0x40(%rsp)
movl %r12d, %ebp
jmp 0x5b31
movl 0x3c(%rsp), %eax
incl %eax
movq 0x48(%rsp), %r12
leaq 0x78(%rsp), %r13
jmp 0x5b08
xorl %ebp, %ebp
testl %r15d, %r15d
cmovlel %ebp, %r15d
testl %ebx, %ebx
cmovlel %ebp, %ebx
movl %ebx, 0xc(%rsp)
movl %r15d, %ebx
cmpl 0xc(%rsp), %ebp
je 0x5e3f
xorl %r15d, %r15d
cmpl %r15d, %ebx
je 0x5c9a
movq (%r12), %rdi
addq 0x28(%rsp), %rdi
movl %ebp, %eax
cltd
idivl 0x10(%rsp)
movl %eax, %esi
movl %r15d, %eax
cltd
idivl 0x24(%rsp)
movl %eax, %edx
callq 0xa44a
movzwl (%rax), %r14d
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0xa44a
movw %r14w, (%rax)
incl %r15d
jmp 0x5c5a
incl %ebp
jmp 0x5c4d
movl %edi, %ebx
pushq $0x5
popq %rdi
leaq 0x17b10(%rip), %rsi     # 0x1d7ba
movl %r14d, %edx
xorl %eax, %eax
callq 0x16c30
movl %ebx, %edi
jmp 0x5ea2
xorl %ebx, %ebx
movl 0x14(%rsp), %ebp
cmpl 0x38(%rsp), %ebx
je 0x5d09
movl %ebx, %ebp
imull 0x10(%rsp), %ebp
xorl %r15d, %r15d
cmpl %r15d, 0x18(%rsp)
je 0x5d05
movq (%r12), %rdi
addq 0x28(%rsp), %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0xa44a
movzwl (%rax), %r14d
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0xa44a
movw %r14w, (%rax)
incl %r15d
jmp 0x5cd1
incl %ebx
jmp 0x5cbd
cmpl $0x2, 0x10(%rsp)
jne 0x5e3f
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0xa4f4
xorl %edx, %edx
testl %ebp, %ebp
cmovlel %edx, %ebp
movl 0x34(%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movl %eax, 0x18(%rsp)
cmpl 0x18(%rsp), %edx
je 0x5e32
testl %edx, %edx
movl %edx, %eax
leal -0x2(%rax,%rax), %esi
cmovel %edx, %esi
movl %esi, 0xc(%rsp)
leal (%rdx,%rdx), %r15d
incl %edx
movq %rdx, 0x50(%rsp)
cmpl %ecx, %edx
leal 0x2(%rax,%rax), %ecx
cmovgel %r15d, %ecx
movl %ecx, 0x40(%rsp)
leal 0x1(,%rax,2), %eax
movl %eax, 0x20(%rsp)
xorl %ebx, %ebx
cmpl %ebx, %ebp
je 0x5e1a
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xa44a
movswl (%rax), %eax
leal (%rax,%rax,2), %r13d
movq %r12, %rdi
movl 0xc(%rsp), %esi
movl %ebx, %edx
callq 0xa44a
movswl (%rax), %eax
addl %eax, %r13d
incl %r13d
shrl $0x2, %r13d
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xa44a
movw %r13w, (%rax)
movq %r12, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xa44a
movswl (%rax), %eax
leal (%rax,%rax,2), %r13d
movq %r12, %rdi
movl 0x40(%rsp), %esi
movl %ebx, %edx
callq 0xa44a
movswl (%rax), %eax
addl %eax, %r13d
addl $0x2, %r13d
shrl $0x2, %r13d
movq %r14, %rdi
movl 0x20(%rsp), %esi
movl %ebx, %edx
callq 0xa44a
movw %r13w, (%rax)
incl %ebx
jmp 0x5d7c
movq 0x48(%rsp), %r12
leaq 0x78(%rsp), %r13
movl 0x34(%rsp), %ecx
movq 0x50(%rsp), %rdx
jmp 0x5d3d
leaq 0xb8(%rsp), %rdi
callq 0xabc2
movq (%r12), %rax
movq 0x28(%rsp), %rbx
movl 0x18(%rax,%rbx), %ecx
movl 0x1c(%rax,%rbx), %r8d
movl 0x90(%rsp), %r9d
movl 0x94(%rsp), %r10d
subq $0x8, %rsp
pushq $0x5
popq %rdi
leaq 0x1799b(%rip), %rsi     # 0x1d80a
movq 0x78(%rsp), %r14
movl %r14d, %edx
xorl %eax, %eax
pushq %r10
callq 0x16c30
popq %rax
popq %rcx
addq (%r12), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa526
movq %r13, %rdi
callq 0xabc2
movq 0x60(%rsp), %r15
movl 0x24(%rsp), %edi
incq %r14
jmp 0x5a42
addq $0x4, %r15
jmp 0x59ef
movb $0x1, %al
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5ec9
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xabc2
movq %rbx, %rdi
callq 0x35d0