// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movl %edi, %ebp
movq %rsi, %rdi
callq 0xa55a
xorl %r14d, %r14d
testl %ebp, %ebp
cmovgl %ebp, %r14d
leaq 0x18(%rsp), %r12
pushq $0x40
popq %r13
leaq 0x30(%rsp), %rbx
subl $0x1, %r14d
jb 0x6194
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xa562
movq %r15, %rdi
movq %r12, %rsi
callq 0xb464
movq %r12, %rdi
callq 0x5374
jmp 0x616b
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x61a6
movq %rax, 0x8(%rcx)
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x61b8
movq %rax, 0x8(%rcx)
movslq %ebp, %rbx
leaq 0x30(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
movq %rsp, %rcx
movq %rbx, %rsi
callq 0xa5b4
movq %rsp, %rdx
movl $0x3, (%rdx)
leaq 0x30(%rsp), %rdi
leaq 0x7(%rsp), %rcx
movq %rbx, %rsi
callq 0xa5b4
movq %rsp, %r14
andl $0x0, (%r14)
movl %ebp, %ebx
shll $0x6, %ebx
xorl %r13d, %r13d
testl %ebx, %ebx
cmovlel %r13d, %ebx
xorl %eax, %eax
xorl %r12d, %r12d
cmpl %r12d, %ebx
je 0x626a
cltq
movq (%r15), %rcx
imulq $0x18, %rax, %rdx
movq 0x18(%rsp), %rsi
movslq (%rsi,%rax,4), %rax
movq (%rcx,%rdx), %rcx
movl %r12d, (%rcx,%rax,4)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0xa60a
movslq (%rsp), %rsi
shlq $0x2, %rsi
addq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xa60a
movslq (%rsp), %rax
movq 0x18(%rsp), %rcx
incl (%rcx,%rax,4)
movl (%rsp), %eax
incl %eax
cmpl %ebp, %eax
cmovel %r13d, %eax
movl %eax, (%rsp)
incl %r12d
jmp 0x6208
leaq 0x30(%rsp), %rdi
callq 0x5374
leaq 0x18(%rsp), %rdi
callq 0x5374
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6296
jmp 0x6291
movq %rax, %rbx
jmp 0x62b2
movq %rax, %rbx
jmp 0x62a8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5374
leaq 0x18(%rsp), %rdi
callq 0x5374
movq %rbx, %rdi
callq 0x35d0