// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rsi), %rax
cmpq (%rsi), %rax
jne 0x7e36
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7b06
movl 0x6c(%r14), %edx
movq (%rbx), %rax
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, 0x48(%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, 0x18(%rsp)
jle 0x83d8
movl %eax, 0x38(%rsp)
addl %ebp, %edx
decl %r9d
leaq 0x1da52(%rip), %rsi     # 0x258e5
xorl %r12d, %r12d
movl $0x3, %edi
movq %rdx, 0x20(%rsp)
movl %r8d, %r13d
xorl %eax, %eax
callq 0x1d0d6
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 0x78bc
movslq %r13d, %rax
movq %rax, 0x40(%rsp)
cmpl %ebp, %r14d
movq 0x48(%rsp), %r14
jl 0x836f
notl %r15d
addl 0x18(%rsp), %r15d
movq 0x20(%rsp), %rcx
movslq %ecx, %rdx
movl 0x1c(%rsp), %eax
cmpl %eax, %ecx
cmovlel %eax, %ecx
incl %ecx
movq %rcx, 0x20(%rsp)
movq 0x40(%rsp), %rax
shlq $0x6, %rax
movq %rax, 0x98(%rsp)
movslq %r15d, %r15
movq %rdx, 0xa0(%rsp)
movq %rdx, %r13
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 0x1d983(%rip), %rsi     # 0x2592d
movq %rdx, 0xa8(%rsp)
movl %ecx, %r14d
movl %ebx, %r8d
movq %r9, 0x50(%rsp)
xorl %eax, %eax
callq 0x1d0d6
movl %ebx, %eax
imull %r14d, %eax
movslq %eax, %rsi
movw $0x0, 0x190(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x190(%rsp), %rdx
leaq 0x17(%rsp), %rcx
callq 0xe312
movl %r14d, 0x70(%rsp)
movl %ebx, 0x74(%rsp)
movl $0x0, 0x78(%rsp)
movl $0x1, 0x80(%rsp)
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rax
movups %xmm0, 0x14(%rax)
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
movw $0x0, 0x7c(%rsp)
movq (%rbp), %r10
movl 0x3c(%r10,%r13), %eax
movl %eax, 0x94(%rsp)
movq 0x2c(%r10,%r13), %xmm0
paddd 0x1d249(%rip), %xmm0    # 0x25290
movq %xmm0, 0x84(%rsp)
movl 0x34(%r10,%r13), %eax
addl $-0x3, %eax
movl %eax, 0x8c(%rsp)
movl 0x34(%r10,%r13), %eax
addl $-0x3, %eax
movl %eax, 0x90(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x60(%rbp), %xmm0
leaq (%r10,%r13), %rax
movq %rax, 0x28(%rsp)
addsd 0x1d131(%rip), %xmm0    # 0x251b8
mulsd 0x1d131(%rip), %xmm0    # 0x251c0
testl %r12d, %r12d
jle 0x830b
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x3c(%rsp)
leaq (%r15,%r15,2), %rax
shlq $0x3, %rax
addq 0x170(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x28(%rsp), %rax
addq $0x24, %rax
movq %rax, 0xd8(%rsp)
movl %r12d, %eax
movq %rax, 0xc0(%rsp)
movq 0x50(%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, 0x30(%rsp)
xorl %r11d, %r11d
movq %r10, 0xe0(%rsp)
cmpl $0x0, 0x50(%rsp)
jle 0x82e8
movq 0x28(%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 0x58(%rsp), %r15
movq 0x60(%rsp), %rbp
subq %r15, %rbp
sarq %rbp
movq 0x30(%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 0x3c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x190(%rsp)
movl $0x1, %eax
leaq 0x1d360(%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 0x81d8
movq %r14, 0x110(%rsp)
leaq 0x190(%rsp), %r13
movq %r13, %rdi
callq 0x77d9
movq %r12, 0x118(%rsp)
xorl %eax, %eax
movq %rax, 0x128(%rsp)
xorl %r14d, %r14d
leaq 0x7c(%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 0x8260
movq 0x128(%rsp), %rax
incq %rax
addq $0x40, %r13
addq 0x120(%rsp), %r12
cmpq $0x8, %rax
jne 0x8250
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 0x817f
incq %r11
movq 0x30(%rsp), %rax
addq 0xb8(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq 0xc0(%rsp), %r11
jne 0x810f
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0xe65e
leaq 0x70(%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 0x58(%rsp), %rdi
testq %rdi, %rdi
movq 0x48(%rsp), %r14
movq 0x20(%rsp), %rbx
movq 0xa8(%rsp), %r13
je 0x8363
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
incq %r13
cmpl %r13d, %ebx
jne 0x7f3e
movslq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rsi
shlq $0x6, %rsi
addq (%r14), %rsi
shlq $0x6, %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xfd3a
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x83ac
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x83c9
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x170(%rsp), %rdi
callq 0xde8a
jmp 0x83e6
leaq 0x1d4d4(%rip), %rdi     # 0x258b3
xorl %eax, %eax
callq 0x3796
movl 0x18(%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 0x8425
jmp 0x8425
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x8428
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x8428
jmp 0x8425
movq %rax, %rbx
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x8445
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x8462
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x170(%rsp), %rdi
callq 0xde8a
movq %rbx, %rdi
callq 0x35a0