// File: /workspace/github_cpp_makefile_star2_O3/cloudinary[P]fuif/transform/dct.h
// Function: inv_DCT(Image&, std::vector<int, std::allocator<int>>&)
bool inv_DCT(Image &input, std::vector<int> &parameters) {
    if (!parameters.size()) default_DCT_parameters(parameters,input);
    int beginc = input.nb_meta_channels + parameters[0];
    int endc = input.nb_meta_channels + parameters[1];
    int nb_channels = endc-beginc+1;
    int offset = input.channel.size() - 63*nb_channels;

    if (offset <= endc) {
        e_printf("Invalid number of channels to apply inverse DCT.\n");
        return false;
    }
    v_printf(3,"Undoing DCT on channels %i..%i with AC coefficients in channels %i..%i\n",beginc,endc,offset,offset+63*nb_channels-1);


    std::vector<std::vector<int>> ordering;
    std::vector<int> comp;
    std::vector<int> coeff;
    default_DCT_scanscript(nb_channels,ordering,comp,coeff);

    for (int c=beginc; c<=endc; c++) {
        int bw = input.channel[c-beginc+offset].w; // consider first AC, in case we did repeated DCT (TODO: try repeated DCT to see if it even makes sense)
        int bh = input.channel[c-beginc+offset].h;
        if (input.channel[c].w < bw) bw = input.channel[c].w;
        if (input.channel[c].h < bh) bh = input.channel[c].h;

        v_printf(3,"  Channel %i : %ix%i image from %ix%i blocks\n",c,bw*8,bh*8,bw,bh);
        Channel outch(bw*8,bh*8,0,0);
        outch.component = input.channel[c].component;
        outch.hshift = input.channel[c].hshift - 3;
        outch.vshift = input.channel[c].vshift - 3;
        outch.hcshift = input.channel[c].hcshift - 3;
        outch.vcshift = input.channel[c].hcshift - 3;
        float DCoffset = (input.maxval + 1.0) * 4.0;
        for (int by=0; by<bh; by++) {
          for (int bx=0; bx<bw; bx++) {
            double block[64];
            block[0] = input.channel[c].value(by,bx) + DCoffset;
            for (int i=1; i<64; i++) block[i] = input.channel[offset-nb_channels+ ordering[c-beginc][jpeg_zigzag[i]]].value(by,bx);
            ComputeBlockIDCTDouble(block);
            for (int y=0; y<8; y++)
            for (int x=0; x<8; x++) outch.value(by*8+y, bx*8+x) = round(block[y*8+x]);
          }
        }
        input.channel[c] = outch;
    }
    input.channel.erase(input.channel.begin()+offset,input.channel.begin()+offset+nb_channels*63);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x398, %rsp            # imm = 0x398
movq %rdi, %r14
movq (%rsi), %rax
cmpq %rax, 0x8(%rsi)
jne 0x7ddf
movq %rsi, %rbx
movq %rsi, %rdi
movq %r14, %rsi
callq 0x7aa4
movq (%rbx), %rax
movl 0x6c(%r14), %edx
movl (%rax), %ebp
movq %r14, %rsi
movl 0x4(%rax), %r14d
leal (%r14,%rdx), %ecx
movl %r14d, %r15d
subl %ebp, %r15d
movq 0x8(%rsi), %r9
movq %rsi, 0x28(%rsp)
subq (%rsi), %r9
leal 0x1(%r15), %ebx
shrq $0x6, %r9
movl %ebx, %eax
shll $0x6, %eax
subl %ebx, %eax
movl %r9d, %r8d
subl %eax, %r8d
cmpl %ecx, %r8d
movl %ecx, 0x1c(%rsp)
movl %r8d, 0x40(%rsp)
jle 0x7e99
movl %eax, 0x18(%rsp)
addl %ebp, %edx
decl %r9d
leaq 0x1dab0(%rip), %rsi     # 0x258e5
xorl %r12d, %r12d
movl $0x3, %edi
movq %rdx, 0x20(%rsp)
movl %r8d, %r13d
xorl %eax, %eax
callq 0x1cede
leaq 0x170(%rsp), %rsi
movq %r12, 0x10(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
leaq 0x150(%rsp), %rdx
movq %r12, 0x10(%rdx)
movaps %xmm0, (%rdx)
leaq 0x130(%rsp), %rcx
movq %r12, 0x10(%rcx)
movaps %xmm0, (%rcx)
movl %ebx, %edi
callq 0x785d
movslq %r13d, %rsi
cmpl %ebp, %r14d
jge 0x7eac
movq 0x28(%rsp), %r14
movl 0x18(%rsp), %eax
jmp 0x8330
leaq 0x1da13(%rip), %rdi     # 0x258b3
xorl %eax, %eax
callq 0x379e
jmp 0x8390
notl %r15d
addl %r13d, %r15d
movq 0x20(%rsp), %rbx
movslq %ebx, %rcx
movl 0x1c(%rsp), %eax
cmpl %eax, %ebx
cmovlel %eax, %ebx
incl %ebx
movq %rsi, 0x90(%rsp)
shlq $0x6, %rsi
movq %rsi, 0x98(%rsp)
movslq %r15d, %r15
movq %rcx, 0xa0(%rsp)
movq %rcx, %r13
movq 0x28(%rsp), %r14
movq %rbx, 0x20(%rsp)
movq %r15, 0xc8(%rsp)
movq %r13, %r15
subq 0xa0(%rsp), %r15
movq %r14, %rbp
movq (%r14), %rax
movq %r15, %rcx
shlq $0x6, %rcx
addq %rax, %rcx
movq 0x98(%rsp), %rdx
movl 0x18(%rdx,%rcx), %r9d
movl 0x1c(%rdx,%rcx), %r12d
movq %r13, %rdx
shlq $0x6, %r13
movl 0x18(%rax,%r13), %ecx
movl 0x1c(%rax,%r13), %eax
cmpl %r9d, %ecx
cmovll %ecx, %r9d
cmpl %r12d, %eax
cmovll %eax, %r12d
leal (,%r9,8), %ecx
leal (,%r12,8), %ebx
movl %r12d, (%rsp)
movl $0x3, %edi
leaq 0x1d9c8(%rip), %rsi     # 0x2592d
movq %rdx, 0xa8(%rsp)
movl %ecx, %r14d
movl %ebx, %r8d
movq %r9, 0x48(%rsp)
xorl %eax, %eax
callq 0x1cede
movl %ebx, %eax
imull %r14d, %eax
movslq %eax, %rsi
movw $0x0, 0x190(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x190(%rsp), %rdx
leaq 0x17(%rsp), %rcx
callq 0xe282
movl %r14d, 0x68(%rsp)
movl %ebx, 0x6c(%rsp)
movl $0x0, 0x70(%rsp)
movl $0x1, 0x78(%rsp)
xorps %xmm0, %xmm0
leaq 0x68(%rsp), %rax
movups %xmm0, 0x14(%rax)
movl $0xffffffff, 0x8c(%rsp) # imm = 0xFFFFFFFF
movw $0x0, 0x74(%rsp)
movq (%rbp), %r10
movl 0x3c(%r10,%r13), %eax
movl %eax, 0x8c(%rsp)
movq 0x2c(%r10,%r13), %xmm0
paddd 0x1d291(%rip), %xmm0    # 0x25290
movq %xmm0, 0x7c(%rsp)
movl 0x34(%r10,%r13), %eax
addl $-0x3, %eax
movl %eax, 0x84(%rsp)
movl 0x34(%r10,%r13), %eax
addl $-0x3, %eax
movl %eax, 0x88(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x60(%rbp), %xmm0
leaq (%r10,%r13), %rax
movq %rax, 0x30(%rsp)
addsd 0x1d17c(%rip), %xmm0    # 0x251b8
mulsd 0x1d17c(%rip), %xmm0    # 0x251c0
testl %r12d, %r12d
jle 0x82c0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x44(%rsp)
leaq (%r15,%r15,2), %rax
shlq $0x3, %rax
addq 0x170(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x30(%rsp), %rax
addq $0x24, %rax
movq %rax, 0xd8(%rsp)
movl %r12d, %eax
movq %rax, 0xc0(%rsp)
movq 0x48(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0xd0(%rsp)
shll $0x6, %eax
movq %rax, 0xb8(%rsp)
movl %r14d, %eax
movq %rax, 0x120(%rsp)
movq $0x0, 0x38(%rsp)
xorl %r11d, %r11d
movq %r10, 0xe0(%rsp)
cmpl $0x0, 0x48(%rsp)
jle 0x829d
movq 0x30(%rsp), %rax
movslq 0x18(%rax), %rcx
imulq %r11, %rcx
movq %rcx, 0x100(%rsp)
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rcx, 0xf8(%rsp)
subq %rcx, %rax
sarq %rax
movq %rax, 0xf0(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax), %rbx
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %rbp
subq %r15, %rbp
sarq %rbp
movq 0x38(%rsp), %r12
xorl %r14d, %r14d
movq %r11, 0x108(%rsp)
movq %rbx, 0xe8(%rsp)
movq 0x100(%rsp), %rax
addq %r14, %rax
cmpq %rax, 0xf0(%rsp)
movq 0xf8(%rsp), %rcx
leaq (%rcx,%rax,2), %rax
cmovbeq 0xd8(%rsp), %rax
movswl (%rax), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
addss 0x44(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x190(%rsp)
movl $0x1, %eax
leaq 0x1d3ab(%rip), %r8      # 0x25530
movq 0xc8(%rsp), %r9
movslq (%r8,%rax,4), %rcx
movslq (%rbx,%rcx,4), %rcx
addq %r9, %rcx
shlq $0x6, %rcx
addq %r10, %rcx
addq $0x24, %rcx
movslq -0xc(%rcx), %rdx
imulq %r11, %rdx
addq %r14, %rdx
movq -0x24(%rcx), %rsi
movq -0x1c(%rcx), %rdi
subq %rsi, %rdi
sarq %rdi
cmpq %rdx, %rdi
leaq (%rsi,%rdx,2), %rdx
cmovbeq %rcx, %rdx
movswl (%rdx), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x190(%rsp,%rax,8)
incq %rax
cmpq $0x40, %rax
jne 0x818d
movq %r14, 0x110(%rsp)
leaq 0x190(%rsp), %r13
movq %r13, %rdi
callq 0x778a
movq %r12, 0x118(%rsp)
xorl %eax, %eax
movq %rax, 0x128(%rsp)
xorl %r14d, %r14d
leaq 0x74(%rsp), %rbx
movsd (%r13,%r14,8), %xmm0
callq 0x3150
cvttsd2si %xmm0, %eax
leal (%r12,%r14), %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbp
leaq (%r15,%rcx,2), %rcx
cmovbeq %rbx, %rcx
movw %ax, (%rcx)
incq %r14
cmpq $0x8, %r14
jne 0x8215
movq 0x128(%rsp), %rax
incq %rax
addq $0x40, %r13
addq 0x120(%rsp), %r12
cmpq $0x8, %rax
jne 0x8205
movq 0x110(%rsp), %r14
incq %r14
movq 0x118(%rsp), %r12
addq $0x8, %r12
cmpq 0xd0(%rsp), %r14
movq 0xe0(%rsp), %r10
movq 0x108(%rsp), %r11
movq 0xe8(%rsp), %rbx
jne 0x8134
incq %r11
movq 0x38(%rsp), %rax
addq 0xb8(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq 0xc0(%rsp), %r11
jne 0x80c4
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
callq 0xe5dc
leaq 0x68(%rsp), %rbp
movq 0x20(%rbp), %rax
movq %rax, 0x38(%rbx)
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups %xmm1, 0x28(%rbx)
movups %xmm0, 0x18(%rbx)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %rbx
movq 0xa8(%rsp), %r13
je 0x8318
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
incq %r13
cmpl %r13d, %ebx
jne 0x7ef9
movl 0x18(%rsp), %eax
movq 0x90(%rsp), %rsi
movslq %eax, %rdx
shlq $0x6, %rsi
addq (%r14), %rsi
shlq $0x6, %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xfcc2
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x8366
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x8383
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x170(%rsp), %rdi
callq 0xddf2
movl 0x40(%rsp), %eax
cmpl 0x1c(%rsp), %eax
setg %al
addq $0x398, %rsp            # imm = 0x398
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x83cf
jmp 0x83cf
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x83d2
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x83d2
jmp 0x83cf
movq %rax, %rbx
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x83ef
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x840c
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x170(%rsp), %rdi
callq 0xddf2
movq %rbx, %rdi
callq 0x3590