// File: /workspace/github_cpp_makefile_star2_O3/cloudinary[P]fuif/transform/dct.h
// Function: default_DCT_scanscript(int, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&, std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>>&)
void default_DCT_scanscript(int nb_components, std::vector<std::vector<int>> & ordering, std::vector<int> & comp, std::vector<int> & coeff) {
   ordering.clear();
   for(int i=0; i<nb_components; i++)
       ordering.push_back(std::vector<int>(64));
   comp.clear();
   coeff.clear();
   std::vector<int> pc(nb_components,0);
   std::vector<int> cshifts(nb_components,3);
   int cc=0;
   int m=0;
   for (int p=0; p<nb_components*64; p++) {
     ordering[cc][pc[cc]] = p;
     comp.push_back(cc);
     coeff.push_back(pc[cc]);
//     v_printf(10,"Position %i: component %i, coefficient %i (cshift=%i)\n",p,cc,pc[cc],cshifts[cc]);
     pc[cc]++;

/*
     if (pc[cc] > 63) {cc++; m=0;}
     else if (dct_cshifts[pc[cc]] < cshifts[cc]) { cshifts[cc]--; cc++; m=0;}
     else if (cshifts[cc] == 2 && ++m == 1) {cc++; m=0;}
     else if (cshifts[cc] == 1 && ++m == 1) {cc++; m=0;}
     else if (cshifts[cc] == 0 && ++m == 2) {cc++; m=0;}
*/

// tried this one, but doesn't seem to be better than doing the simpler thing
//     if (pc[cc] > 63) cc++;
//     else if (dct_cshifts[pc[cc]] < cshifts[cc]) { cshifts[cc]--; cc++; }

// simple scan script: go one coefficient at a time, from low freq to high freq, alternating between the components
     cc++;
     if (cc == nb_components) { cc=0; }

   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movl %edi, %ebp
movq (%rsi), %rsi
movq %r15, %rdi
callq 0xf78e
movl %ebp, 0x8(%rsp)
testl %ebp, %ebp
jle 0x78fd
leaq 0x10(%rsp), %r12
movl 0x8(%rsp), %r13d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x100, %edi            # imm = 0x100
callq 0x32b0
movq %rax, 0x10(%rsp)
movq %rax, %rbp
addq $0x100, %rbp            # imm = 0x100
movq %rbp, 0x20(%rsp)
movl $0x100, %edx            # imm = 0x100
movq %rax, %rdi
xorl %esi, %esi
callq 0x3180
movq %rbp, 0x18(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xf7d8
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x78f8
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
decl %r13d
jne 0x7893
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x790a
movq %rax, 0x8(%r14)
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x7917
movq %rax, 0x8(%rbx)
movslq 0x8(%rsp), %r12
leaq 0x30(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rcx
movq %r12, %rsi
callq 0xdc1c
leaq 0x4(%rsp), %rdx
movl $0x3, (%rdx)
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movq %r12, %rsi
callq 0xdc1c
movl $0x0, 0x4(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x7a20
movl 0x8(%rsp), %eax
shll $0x6, %eax
cmpl $0x2, %eax
movl $0x1, %r13d
cmovgel %eax, %r13d
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
xorl %ecx, %ecx
xorl %r12d, %r12d
movslq %ecx, %rcx
movq (%r15), %rdx
leaq (%rcx,%rcx,2), %rsi
movslq (%rax,%rcx,4), %rcx
movq (%rdx,%rsi,8), %rdx
movl %r12d, (%rdx,%rcx,4)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x79b9
movl 0x4(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x79cf
movq %r14, %rdi
leaq 0x4(%rsp), %rdx
callq 0xf9d8
movl 0x4(%rsp), %ecx
movq 0x10(%rsp), %rax
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x79ee
movl (%rdx), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x79fb
movq %rbx, %rdi
callq 0xf9d8
movq 0x10(%rsp), %rax
movslq 0x4(%rsp), %rcx
incl (%rax,%rcx,4)
movl 0x4(%rsp), %ecx
incl %ecx
cmpl 0x8(%rsp), %ecx
cmovel %ebp, %ecx
movl %ecx, 0x4(%rsp)
incl %r12d
cmpl %r12d, %r13d
jne 0x7989
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7a37
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7a4e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7a82
jmp 0x7a7d
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x7a85
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
jmp 0x7a85
movq %rax, %rbx
jmp 0x7a9c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x7a9c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3590