// File: /workspace/github_cpp_makefile_star2_O2/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 $0x378, %rsp            # imm = 0x378
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0xa67c
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x5326
movq %rbx, %rdi
movl 0x6c(%rbx), %r15d
leaq 0x68(%rsp), %rsi
movq (%rsi), %rax
movl (%rax), %r12d
movl 0x4(%rax), %ebx
movq 0x8(%rdi), %r14
subq (%rdi), %r14
movq %rdi, 0x10(%rsp)
callq 0x62fc
leal (%r12,%r15), %ebp
addl %ebx, %r15d
subl %r12d, %ebx
leal 0x1(%rbx), %r12d
shrq $0x6, %r14
imull $0x3f, %r12d, %r13d
leal (%r14,%r13), %r9d
decl %r9d
leaq 0x16ee1(%rip), %rsi     # 0x1d8db
pushq $0x3
popq %rdi
movl %ebp, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x16c30
leaq 0x50(%rsp), %rsi
andq $0x0, 0x10(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
leaq 0xa0(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x80(%rsp), %rcx
movaps %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
movl %r12d, %edi
callq 0x612f
movq 0x10(%rsp), %rax
cvtsi2sdl 0x60(%rax), %xmm0
addsd 0x16792(%rip), %xmm0    # 0x1d1e8
mulsd 0x16792(%rip), %xmm0    # 0x1d1f0
addl %r14d, %r13d
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18(%rsp)
movslq %ebp, %rbp
movslq %r13d, %r12
movq %rbp, %r13
shlq $0x6, %r13
movq %rbp, 0x28(%rsp)
cmpq %r12, %rbp
jge 0x6a9b
movq 0x10(%rsp), %rax
movq (%rax), %rdi
addq %r13, %rdi
callq 0xa72e
incq %rbp
addq $0x40, %r13
jmp 0x6a7d
cvtss2sd 0x18(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
notl %ebx
addl %ebx, %r14d
movslq %r15d, %rax
movq %rax, 0x30(%rsp)
movslq %r14d, %rax
movq %rax, 0x48(%rsp)
movq 0x28(%rsp), %rbx
cmpq 0x30(%rsp), %rbx
movq 0x10(%rsp), %rax
jg 0x6c5e
movq (%rax), %rax
movq %rbx, %rdx
shlq $0x6, %rdx
movl 0x18(%rax,%rdx), %r12d
movl 0x1c(%rax,%rdx), %ebp
movq 0xc0(%rsp), %rax
movl 0x18(%rax,%rdx), %ecx
movq %rdx, 0x18(%rsp)
movl 0x1c(%rax,%rdx), %r8d
movl %ebp, (%rsp)
pushq $0x3
popq %rdi
leaq 0x16e1a(%rip), %rsi     # 0x1d921
movl %ebx, %edx
movl %r12d, %r9d
xorl %eax, %eax
callq 0x16c30
movq %rbx, 0x38(%rsp)
subq 0x28(%rsp), %rbx
xorl %r14d, %r14d
testl %r12d, %r12d
cmovlel %r14d, %r12d
testl %ebp, %ebp
cmovlel %r14d, %ebp
imulq $0x18, %rbx, %r15
movl %r12d, 0x24(%rsp)
movl %ebp, 0x20(%rsp)
cmpl %ebp, %r14d
je 0x6c51
leal (,%r14,8), %ebx
xorl %ebp, %ebp
cmpl %r12d, %ebp
je 0x6c45
leal (,%rbp,8), %r12d
xorl %r13d, %r13d
cmpq $0x40, %r13
je 0x6b9e
movq 0xc0(%rsp), %rdi
addq 0x18(%rsp), %rdi
movl %r13d, %esi
shrl $0x3, %esi
orl %ebx, %esi
movl %r13d, %edx
andl $0x7, %edx
orl %r12d, %edx
callq 0xa744
cwtl
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x170(%rsp,%r13,8)
incq %r13
jmp 0x6b61
leaq 0x170(%rsp), %rdi
callq 0x6117
movsd 0x170(%rsp), %xmm0
callq 0x3150
subsd 0x40(%rsp), %xmm0
cvttsd2si %xmm0, %r12d
movq 0x10(%rsp), %rax
movq (%rax), %rdi
addq 0x18(%rsp), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r12w, (%rax)
pushq $0x1
popq %r12
cmpq $0x40, %r12
je 0x6c39
movsd 0x170(%rsp,%r12,8), %xmm0
callq 0x3150
cvttsd2si %xmm0, %r13d
movq 0x50(%rsp), %rax
leaq 0x16867(%rip), %rcx     # 0x1d470
movslq (%rcx,%r12,4), %rcx
movq (%rax,%r15), %rax
movslq (%rax,%rcx,4), %rdi
addq 0x48(%rsp), %rdi
shlq $0x6, %rdi
movq 0x10(%rsp), %rax
addq (%rax), %rdi
movl %r14d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r13w, (%rax)
incq %r12
jmp 0x6be3
incl %ebp
movl 0x24(%rsp), %r12d
jmp 0x6b4d
incl %r14d
movl 0x20(%rsp), %ebp
jmp 0x6b3a
movq 0x38(%rsp), %rbx
incq %rbx
jmp 0x6ac1
leaq 0x80(%rsp), %rdi
callq 0x5374
leaq 0xa0(%rsp), %rdi
callq 0x5374
leaq 0x50(%rsp), %rdi
callq 0xa654
leaq 0x68(%rsp), %rdi
callq 0x5374
leaq 0xc0(%rsp), %rdi
callq 0xa776
movb $0x1, %al
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6cbf
movq %rax, %rbx
jmp 0x6cf0
movq %rax, %rbx
jmp 0x6ce6
jmp 0x6cbf
jmp 0x6cbf
jmp 0x6cbf
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x5374
leaq 0xa0(%rsp), %rdi
callq 0x5374
leaq 0x50(%rsp), %rdi
callq 0xa654
leaq 0x68(%rsp), %rdi
callq 0x5374
leaq 0xc0(%rsp), %rdi
callq 0xa776
movq %rbx, %rdi
callq 0x35d0