// File: 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:
subq $0x228, %rsp            # imm = 0x228
movq %rsi, 0x138(%rsp)
movq %rdi, %rax
movq 0x138(%rsp), %rdi
movq %rdi, 0x140(%rsp)
movq %rax, 0x220(%rsp)
movq %rdi, 0x218(%rsp)
callq 0x6e80
movl $0x0, 0x214(%rsp)
movq 0x140(%rsp), %rdi
movslq 0x214(%rsp), %rax
movq %rax, 0x130(%rsp)
callq 0x4d50
movq %rax, %rcx
movq 0x130(%rsp), %rax
cmpq %rcx, %rax
jae 0x7bdf
movq 0x140(%rsp), %rdi
movl 0x214(%rsp), %eax
addl $0x0, %eax
movslq %eax, %rsi
callq 0x12190
movq 0x140(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x210(%rsp)
movl 0x214(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x12190
movq 0x140(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x20c(%rsp)
movl 0x214(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x12190
movq 0x140(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x208(%rsp)
movl 0x214(%rsp), %eax
addl $0x3, %eax
movslq %eax, %rsi
callq 0x12190
movl (%rax), %eax
movl %eax, 0x204(%rsp)
movl 0x210(%rsp), %eax
movl %eax, 0x200(%rsp)
movl 0x200(%rsp), %eax
cmpl 0x20c(%rsp), %eax
jg 0x7bc7
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
movl %eax, 0x1fc(%rsp)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movl 0x1c(%rax), %eax
movl %eax, 0x1f8(%rsp)
movl 0x1fc(%rsp), %eax
movl %eax, 0x12c(%rsp)
movq 0x220(%rsp), %rdi
movq 0x220(%rsp), %rax
movslq 0x6c(%rax), %rsi
callq 0x4ba0
movq %rax, %rcx
movl 0x12c(%rsp), %eax
cmpl 0x18(%rcx), %eax
jl 0x7275
movl 0x1f8(%rsp), %eax
movl %eax, 0x128(%rsp)
movq 0x220(%rsp), %rdi
movq 0x220(%rsp), %rax
movslq 0x6c(%rax), %rsi
callq 0x4ba0
movq %rax, %rcx
movl 0x128(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jl 0x7275
movl 0x200(%rsp), %edx
movq 0x220(%rsp), %rax
movl 0x6c(%rax), %ecx
movl $0x5, %edi
leaq 0x3f501(%rip), %rsi     # 0x4676a
movb $0x0, %al
callq 0x3a770
jmp 0x7ba2
movl 0x1fc(%rsp), %eax
imull 0x208(%rsp), %eax
movl %eax, 0x11c(%rsp)
movl 0x1f8(%rsp), %eax
imull 0x204(%rsp), %eax
movl %eax, 0x120(%rsp)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movw 0x20(%rax), %ax
movw %ax, 0x126(%rsp)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movl 0x11c(%rsp), %esi
movl 0x120(%rsp), %edx
movw 0x126(%rsp), %cx
leaq 0x1b8(%rsp), %rdi
movl $0x1, %r9d
xorl %r8d, %r8d
movswl %cx, %ecx
movswl 0x22(%rax), %r8d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
callq 0x12200
cmpl $0x2, 0x204(%rsp)
jg 0x79fa
cmpl $0x2, 0x208(%rsp)
jg 0x79fa
cmpl $0x2, 0x208(%rsp)
jne 0x7652
movl $0x0, 0x1b4(%rsp)
movl 0x1b4(%rsp), %eax
cmpl 0x1f8(%rsp), %eax
jge 0x764d
movl $0x0, 0x1b0(%rsp)
movl 0x1b0(%rsp), %eax
cmpl 0x1fc(%rsp), %eax
jge 0x7635
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x1b4(%rsp), %esi
movl 0x1b0(%rsp), %edx
callq 0x12110
movq %rax, 0x110(%rsp)
jmp 0x73c7
movq 0x110(%rsp), %rax
movswl (%rax), %eax
imull $0x3, %eax, %eax
movl %eax, 0xfc(%rsp)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, 0x100(%rsp)
movl 0x1b4(%rsp), %eax
movl %eax, 0x10c(%rsp)
cmpl $0x0, 0x1b0(%rsp)
je 0x7424
movl 0x1b0(%rsp), %eax
subl $0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x742f
xorl %eax, %eax
movl %eax, 0xf8(%rsp)
jmp 0x742f
movl 0x10c(%rsp), %esi
movq 0x100(%rsp), %rdi
movl 0xf8(%rsp), %edx
callq 0x12110
movq %rax, 0xf0(%rsp)
jmp 0x7454
movl 0xfc(%rsp), %ecx
movq 0xf0(%rsp), %rax
movswl (%rax), %edx
movl %ecx, %eax
movl %edx, %ecx
leal 0x1(%rax,%rcx), %eax
shrl $0x2, %eax
movw %ax, 0xe6(%rsp)
movl 0x1b4(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
movl 0x1b0(%rsp), %edx
movl 0x208(%rsp), %eax
imull %eax, %edx
leaq 0x1b8(%rsp), %rdi
callq 0x12110
movq %rax, 0xe8(%rsp)
jmp 0x74b2
movq 0xe8(%rsp), %rax
movw 0xe6(%rsp), %cx
movw %cx, (%rax)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x1b4(%rsp), %esi
movl 0x1b0(%rsp), %edx
callq 0x12110
movq %rax, 0xd8(%rsp)
jmp 0x74fa
movq 0xd8(%rsp), %rax
movswl (%rax), %eax
imull $0x3, %eax, %eax
movl %eax, 0xc4(%rsp)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, 0xc8(%rsp)
movl 0x1b4(%rsp), %eax
movl %eax, 0xd4(%rsp)
movl 0x1b0(%rsp), %eax
addl $0x1, %eax
cmpl 0x1fc(%rsp), %eax
jge 0x7560
movl 0x1b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x756e
movl 0x1b0(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0xd4(%rsp), %esi
movq 0xc8(%rsp), %rdi
movl 0xc0(%rsp), %edx
callq 0x12110
movq %rax, 0xb8(%rsp)
jmp 0x7593
movl 0xc4(%rsp), %ecx
movq 0xb8(%rsp), %rax
movswl (%rax), %edx
movl %ecx, %eax
movl %edx, %ecx
leal 0x2(%rax,%rcx), %eax
shrl $0x2, %eax
movw %ax, 0xae(%rsp)
movl 0x1b4(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
movl 0x1b0(%rsp), %edx
movl 0x208(%rsp), %eax
imull %eax, %edx
incl %edx
leaq 0x1b8(%rsp), %rdi
callq 0x12110
movq %rax, 0xb0(%rsp)
jmp 0x75f3
movq 0xb0(%rsp), %rax
movw 0xae(%rsp), %cx
movw %cx, (%rax)
movl 0x1b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1b0(%rsp)
jmp 0x737e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
jmp 0x7bb8
jmp 0x7637
movl 0x1b4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1b4(%rsp)
jmp 0x735f
jmp 0x774a
movl $0x0, 0x1a0(%rsp)
movl 0x1a0(%rsp), %eax
cmpl 0x1f8(%rsp), %eax
jge 0x7748
movl $0x0, 0x19c(%rsp)
movl 0x19c(%rsp), %eax
cmpl 0x1fc(%rsp), %eax
jge 0x7730
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x1a0(%rsp), %esi
movl 0x19c(%rsp), %edx
callq 0x12110
movq %rax, 0xa0(%rsp)
jmp 0x76c5
movq 0xa0(%rsp), %rax
movw (%rax), %ax
movw %ax, 0x96(%rsp)
movl 0x1a0(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
movl 0x19c(%rsp), %edx
leaq 0x1b8(%rsp), %rdi
callq 0x12110
movq %rax, 0x98(%rsp)
jmp 0x7707
movq 0x98(%rsp), %rax
movw 0x96(%rsp), %cx
movw %cx, (%rax)
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x767c
jmp 0x7732
movl 0x1a0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a0(%rsp)
jmp 0x765d
jmp 0x774a
cmpl $0x2, 0x204(%rsp)
jne 0x79f5
leaq 0x158(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x12330
jmp 0x776f
movl $0x0, 0x154(%rsp)
movl 0x154(%rsp), %eax
cmpl 0x1f8(%rsp), %eax
jge 0x79e8
movl $0x0, 0x150(%rsp)
movl 0x150(%rsp), %eax
movl 0x1fc(%rsp), %ecx
imull 0x208(%rsp), %ecx
cmpl %ecx, %eax
jge 0x79d0
movl 0x154(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
movl 0x150(%rsp), %edx
leaq 0x158(%rsp), %rdi
callq 0x12110
movq %rax, 0x88(%rsp)
jmp 0x77e6
movq 0x88(%rsp), %rax
movswl (%rax), %eax
imull $0x3, %eax, %eax
movl %eax, 0x84(%rsp)
cmpl $0x0, 0x154(%rsp)
je 0x7820
movl 0x154(%rsp), %eax
subl $0x1, %eax
imull 0x204(%rsp), %eax
movl %eax, 0x80(%rsp)
jmp 0x782b
xorl %eax, %eax
movl %eax, 0x80(%rsp)
jmp 0x782b
movl 0x80(%rsp), %esi
movl 0x150(%rsp), %edx
leaq 0x158(%rsp), %rdi
callq 0x12110
movq %rax, 0x78(%rsp)
jmp 0x784d
movl 0x84(%rsp), %ecx
movq 0x78(%rsp), %rax
movswl (%rax), %edx
movl %ecx, %eax
movl %edx, %ecx
leal 0x1(%rax,%rcx), %eax
shrl $0x2, %eax
movw %ax, 0x6e(%rsp)
movl 0x154(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
movl 0x150(%rsp), %edx
leaq 0x1b8(%rsp), %rdi
callq 0x12110
movq %rax, 0x70(%rsp)
jmp 0x7898
movq 0x70(%rsp), %rax
movw 0x6e(%rsp), %cx
movw %cx, (%rax)
movl 0x154(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
movl 0x150(%rsp), %edx
leaq 0x158(%rsp), %rdi
callq 0x12110
movq %rax, 0x60(%rsp)
jmp 0x78d1
movq 0x60(%rsp), %rax
movswl (%rax), %eax
imull $0x3, %eax, %eax
movl %eax, 0x5c(%rsp)
movl 0x154(%rsp), %eax
addl $0x1, %eax
cmpl 0x1f8(%rsp), %eax
jge 0x790b
movl 0x154(%rsp), %eax
addl $0x1, %eax
imull 0x204(%rsp), %eax
movl %eax, 0x58(%rsp)
jmp 0x791e
movl 0x154(%rsp), %eax
imull 0x204(%rsp), %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %esi
movl 0x150(%rsp), %edx
leaq 0x158(%rsp), %rdi
callq 0x12110
movq %rax, 0x50(%rsp)
jmp 0x793d
movl 0x5c(%rsp), %ecx
movq 0x50(%rsp), %rax
movswl (%rax), %edx
movl %ecx, %eax
movl %edx, %ecx
leal 0x2(%rax,%rcx), %eax
shrl $0x2, %eax
movw %ax, 0x46(%rsp)
movl 0x154(%rsp), %esi
movl 0x204(%rsp), %eax
imull %eax, %esi
incl %esi
movl 0x150(%rsp), %edx
leaq 0x1b8(%rsp), %rdi
callq 0x12110
movq %rax, 0x48(%rsp)
jmp 0x7987
movq 0x48(%rsp), %rax
movw 0x46(%rsp), %cx
movw %cx, (%rax)
movl 0x150(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x150(%rsp)
jmp 0x7799
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1a8(%rsp)
movl %eax, 0x1a4(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x12380
jmp 0x7bb8
jmp 0x79d2
movl 0x154(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x154(%rsp)
jmp 0x777a
leaq 0x158(%rsp), %rdi
callq 0x12380
jmp 0x7b02
movl $0x0, 0x14c(%rsp)
movl 0x14c(%rsp), %eax
movl 0x1f8(%rsp), %ecx
imull 0x204(%rsp), %ecx
cmpl %ecx, %eax
jge 0x7b00
movl $0x0, 0x148(%rsp)
movl 0x148(%rsp), %eax
movl 0x1fc(%rsp), %ecx
imull 0x208(%rsp), %ecx
cmpl %ecx, %eax
jge 0x7ae8
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
movl 0x14c(%rsp), %eax
movl 0x204(%rsp), %ecx
cltd
idivl %ecx
movl %eax, %esi
movl 0x148(%rsp), %eax
movl 0x208(%rsp), %ecx
cltd
idivl %ecx
movl %eax, %edx
callq 0x12110
movq %rax, 0x38(%rsp)
jmp 0x7a96
movq 0x38(%rsp), %rax
movw (%rax), %ax
movw %ax, 0x2e(%rsp)
movl 0x14c(%rsp), %esi
movl 0x148(%rsp), %edx
leaq 0x1b8(%rsp), %rdi
callq 0x12110
movq %rax, 0x30(%rsp)
jmp 0x7ac5
movq 0x30(%rsp), %rax
movw 0x2e(%rsp), %cx
movw %cx, (%rax)
movl 0x148(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x148(%rsp)
jmp 0x7a2e
jmp 0x7aea
movl 0x14c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14c(%rsp)
jmp 0x7a05
jmp 0x7b02
movl 0x200(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x220(%rsp), %rdi
movslq %eax, %rsi
callq 0x4ba0
movl 0x18(%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movl 0x24(%rsp), %edx
movl 0x28(%rsp), %ecx
movl 0x1c(%rax), %r8d
movl 0x1d0(%rsp), %r9d
movl 0x1d4(%rsp), %esi
movq %rsp, %rax
movl %esi, (%rax)
leaq 0x3ec5a(%rip), %rsi     # 0x467ba
xorl %eax, %eax
movl $0x5, %edi
callq 0x3a770
jmp 0x7b6e
movq 0x220(%rsp), %rdi
movslq 0x200(%rsp), %rsi
callq 0x4ba0
movq %rax, %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x12390
jmp 0x7b95
leaq 0x1b8(%rsp), %rdi
callq 0x12380
movl 0x200(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x200(%rsp)
jmp 0x718d
leaq 0x1b8(%rsp), %rdi
callq 0x12380
jmp 0x7beb
jmp 0x7bc9
movl 0x214(%rsp), %eax
addl $0x4, %eax
movl %eax, 0x214(%rsp)
jmp 0x70c2
movb $0x1, %al
andb $0x1, %al
addq $0x228, %rsp            # imm = 0x228
retq
movq 0x1a8(%rsp), %rdi
callq 0x36a0
nopl (%rax,%rax)