// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/transform/dct.h
// Function: fwd_DCT(Image&, std::vector<int, std::allocator<int>>&)
bool fwd_DCT(Image &input, std::vector<int> &parameters) {
    Image tmp=input; // TODO: implement without copy
    std::vector<int> adj_params = parameters; // use a copy so empty (default) parameters remain empty

    int beginc = input.nb_meta_channels + adj_params[0];
    int endc = input.nb_meta_channels + adj_params[1];
    int nb_channels = endc-beginc+1;
    int offset = input.channel.size();
    meta_DCT(input, adj_params);

    v_printf(3,"Doing 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);

    float DCoffset = (input.maxval + 1.0) * 4.0;

    for (int c=beginc; c<offset+63*nb_channels; c++) {
            input.channel[c].resize();
    }
    for (int c=beginc; c<=endc; c++) {
        int bw=input.channel[c].w;
        int bh=input.channel[c].h;
        v_printf(3,"  Channel %i : %ix%i image to %ix%i blocks\n",c,tmp.channel[c].w,tmp.channel[c].h,bw,bh);
        for (int by=0; by<bh; by++) {
          for (int bx=0; bx<bw; bx++) {
            double block[64];
            for (int i=0; i<64; i++) block[i] = tmp.channel[c].repeating_edge_value(by*8+(i>>3),bx*8+(i&7));
            ComputeBlockDCTDouble(block);
            input.channel[c].value(by,bx) = round(block[0]) - DCoffset;
            for (int i=1; i<64; i++) input.channel[offset-nb_channels+ ordering[c-beginc][jpeg_zigzag[i]]].value(by,bx) = round(block[i]);
          }
        }
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x120(%rsp), %rdi
movq %r15, %rsi
callq 0xe196
leaq 0x138(%rsp), %r14
leaq 0x18(%r15), %rsi
movq %r14, %rdi
callq 0xe732
movups 0x30(%r15), %xmm0
leaq 0x160(%rsp), %rdi
movups %xmm0, -0x10(%rdi)
leaq 0x40(%r15), %rsi
callq 0x641c
movups 0x58(%r15), %xmm0
movups 0x64(%r15), %xmm1
leaq 0x198(%rsp), %rdi
movups %xmm1, -0x14(%rdi)
movups %xmm0, -0x20(%rdi)
leaq 0x78(%r15), %rsi
callq 0xe7bc
movups 0x90(%r15), %xmm0
movups 0x99(%r15), %xmm1
movups %xmm1, 0x1b9(%rsp)
movups %xmm0, 0x1b0(%rsp)
leaq 0xa8(%rsp), %rdi
movq %rbx, %rsi
callq 0x641c
movl 0x6c(%r15), %ebp
leaq 0xa8(%rsp), %rsi
movq (%rsi), %rax
movl (%rax), %ecx
movq %rcx, 0x10(%rsp)
movl 0x4(%rax), %r13d
movq 0x8(%r15), %rbx
subq (%r15), %rbx
movq %r15, %rdi
callq 0x7b7e
movq 0x10(%rsp), %rcx
leal (%rcx,%rbp), %edx
addl %r13d, %ebp
movl %r13d, %eax
subl %ecx, %eax
movq %rax, 0x18(%rsp)
leal 0x1(%rax), %r12d
shrq $0x6, %rbx
movl %r12d, %r14d
shll $0x6, %r14d
subl %r12d, %r14d
leal (%r14,%rbx), %r9d
decl %r9d
leaq 0x1d3de(%rip), %rsi     # 0x2595b
movl $0x3, %edi
movl %edx, 0x8(%rsp)
movl %ebp, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x1d0d6
xorps %xmm0, %xmm0
leaq 0x100(%rsp), %rsi
movaps %xmm0, (%rsi)
xorl %eax, %eax
movq %rax, 0x10(%rsi)
leaq 0xe0(%rsp), %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
leaq 0xc0(%rsp), %rcx
movq %rax, 0x10(%rcx)
movaps %xmm0, (%rcx)
movl %r12d, %edi
callq 0x78bc
addl %ebx, %r14d
movq %r15, 0x20(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x60(%r15), %xmm0
movsd %xmm0, 0x28(%rsp)
cmpl %r14d, 0x8(%rsp)
jge 0x862d
movslq 0x8(%rsp), %r15
movslq %r14d, %r14
movq %r15, %r12
shlq $0x6, %r12
orq $0x24, %r12
movq 0x20(%rsp), %rax
movq (%rax), %rdx
leaq (%rdx,%r12), %rdi
addq $-0x24, %rdi
addq %r12, %rdx
movslq 0x18(%rdi), %rax
movslq 0x1c(%rdi), %rsi
imulq %rax, %rsi
callq 0xe944
incq %r15
addq $0x40, %r12
cmpq %r14, %r15
jl 0x85fd
cmpl 0x10(%rsp), %r13d
jl 0x8935
movsd 0x28(%rsp), %xmm0
addsd 0x1cb72(%rip), %xmm0    # 0x251b8
mulsd 0x1cb72(%rip), %xmm0    # 0x251c0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x68(%rsp)
movq 0x18(%rsp), %rax
notl %eax
addl %eax, %ebx
movl 0x8(%rsp), %ecx
movslq %ecx, %rax
cmpl %ebp, %ecx
cmovgl %ecx, %ebp
incl %ebp
movslq %ebx, %r12
movq %rax, 0x48(%rsp)
movq %rax, %rdx
movq %rbp, 0x50(%rsp)
movq %r12, 0x60(%rsp)
movq 0x60(%rsp), %r12
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rdx, %rsi
shlq $0x6, %rsi
movl 0x18(%rax,%rsi), %r9d
movl 0x1c(%rax,%rsi), %ebx
movq 0x120(%rsp), %rax
movl 0x18(%rax,%rsi), %ecx
movq %rsi, 0x40(%rsp)
movl 0x1c(%rax,%rsi), %r8d
movl %ebx, (%rsp)
movl $0x3, %edi
leaq 0x1d2d7(%rip), %rsi     # 0x259a1
movq %rdx, 0x38(%rsp)
movl %r9d, 0x10(%rsp)
xorl %eax, %eax
callq 0x1d0d6
testl %ebx, %ebx
jle 0x8920
movq 0x120(%rsp), %rcx
movq 0x40(%rsp), %rax
leaq (%rcx,%rax), %r11
addq $0x24, %r11
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
movq 0x38(%rsp), %rax
subq 0x48(%rsp), %rax
xorl %r8d, %r8d
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
movq %rax, 0x58(%rsp)
movl %ebx, 0x34(%rsp)
movq %r11, 0x70(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x8910
leal (,%r8,8), %ebx
movq 0x18(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r13
subq %r14, %r13
sarq %r13
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movq 0x40(%rsp), %rax
leaq (%rcx,%rax), %rdx
movq %rdx, 0x88(%rsp)
movq %rcx, 0x90(%rsp)
addq %rcx, %rax
addq $0x24, %rax
movq %rax, 0x80(%rsp)
movq 0x100(%rsp), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x78(%rsp)
xorl %ebp, %ebp
movl %ebx, 0x28(%rsp)
movq %r14, 0xa0(%rsp)
movq %r13, 0x98(%rsp)
movq %r8, 0x8(%rsp)
leal (,%rbp,8), %eax
movq 0x18(%rsp), %rdx
movl 0x18(%rdx), %ecx
movl 0x1c(%rdx), %edx
leal -0x1(%rdx), %esi
leal -0x1(%rcx), %edi
xorl %r8d, %r8d
movl %r8d, %r9d
shrl $0x3, %r9d
addl %ebx, %r9d
movl %r8d, %r10d
andl $0x7, %r10d
orl %eax, %r10d
cmpl %r9d, %edx
cmovlel %esi, %r9d
cmpl %r10d, %ecx
cmovlel %edi, %r10d
imull %ecx, %r9d
addl %r10d, %r9d
movslq %r9d, %r9
cmpq %r9, %r13
leaq (%r14,%r9,2), %r9
cmovbeq %r11, %r9
movswl (%r9), %r9d
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
movsd %xmm0, 0x1d0(%rsp,%r8,8)
incq %r8
cmpq $0x40, %r8
jne 0x87c0
leaq 0x1d0(%rsp), %rdi
callq 0x76fa
movsd 0x1d0(%rsp), %xmm0
callq 0x3150
subsd 0x68(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movq 0x88(%rsp), %rsi
movl 0x18(%rsi), %ecx
imull 0x8(%rsp), %ecx
addl %ebp, %ecx
movslq %ecx, %rcx
movq (%rsi), %rdx
movq 0x8(%rsi), %rsi
subq %rdx, %rsi
sarq %rsi
cmpq %rcx, %rsi
leaq (%rdx,%rcx,2), %rcx
cmovbeq 0x80(%rsp), %rcx
movw %ax, (%rcx)
movq 0x78(%rsp), %rax
movq (%rax), %r13
movl $0x1, %ebx
leaq 0x1ccac(%rip), %r14     # 0x25530
movq 0x90(%rsp), %r15
movsd 0x1d0(%rsp,%rbx,8), %xmm0
callq 0x3150
movq 0x8(%rsp), %r8
cvttsd2si %xmm0, %eax
movslq (%r14,%rbx,4), %rcx
movslq (%r13,%rcx,4), %rcx
addq %r12, %rcx
shlq $0x6, %rcx
addq %r15, %rcx
addq $0x24, %rcx
movl -0xc(%rcx), %edx
imull %r8d, %edx
addl %ebp, %edx
movslq %edx, %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
movw %ax, (%rdx)
incq %rbx
cmpq $0x40, %rbx
jne 0x888c
incl %ebp
cmpl 0x10(%rsp), %ebp
movq 0x70(%rsp), %r11
movl 0x28(%rsp), %ebx
movq 0xa0(%rsp), %r14
movq 0x98(%rsp), %r13
jne 0x87a5
incl %r8d
movl 0x34(%rsp), %ebx
cmpl %ebx, %r8d
jne 0x8723
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x50(%rsp), %rbp
cmpl %edx, %ebp
jne 0x868d
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x8952
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
leaq 0x138(%rsp), %rbx
je 0x8977
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x100(%rsp), %rdi
callq 0xde8a
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x89a1
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x89be
movq 0x1a8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x89db
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0xe808
leaq 0x120(%rsp), %rdi
callq 0xe220
movb $0x1, %al
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8a4a
movq %rax, %rbx
jmp 0x8ab1
movq %rax, %rbx
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x8a33
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x8a33
movq %rax, %rbx
movq %r14, %rdi
jmp 0x8af3
movq %rax, %rbx
jmp 0x8af8
movq %rax, %rbx
jmp 0x8a94
jmp 0x8a4a
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x8a6a
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x8a87
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x100(%rsp), %rdi
callq 0xde8a
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x8ab1
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x8ace
movq 0x1a8(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x8aeb
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0x138(%rsp), %rdi
callq 0xe808
leaq 0x120(%rsp), %rdi
callq 0xe220
movq %rbx, %rdi
callq 0x35a0