// File: 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:
subq $0xf8, %rsp
movl %edi, 0xf4(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movq %rcx, 0xd8(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x123e0
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0xf4(%rsp), %eax
jge 0x8297
movq 0xe8(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x12430
movq 0x48(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
movl $0x40, %esi
callq 0x12440
jmp 0x820a
movq 0x40(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x12400
jmp 0x821e
leaq 0xb8(%rsp), %rdi
callq 0x54f0
leaq 0xb7(%rsp), %rdi
callq 0x4e10
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x81be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
jmp 0x8285
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x54f0
leaq 0xb7(%rsp), %rdi
callq 0x4e10
jmp 0x84e2
movq 0xe0(%rsp), %rdi
callq 0x121e0
movq 0xd8(%rsp), %rdi
callq 0x121e0
movslq 0xf4(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x84(%rsp)
leaq 0x83(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x12430
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rcx
leaq 0x88(%rsp), %rdi
leaq 0x84(%rsp), %rdx
callq 0x124c0
jmp 0x82fc
leaq 0x83(%rsp), %rdi
callq 0x4e10
movslq 0xf4(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x3, 0x64(%rsp)
leaq 0x63(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x12430
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rcx
leaq 0x68(%rsp), %rdi
leaq 0x64(%rsp), %rdx
callq 0x124c0
jmp 0x8348
leaq 0x63(%rsp), %rdi
callq 0x4e10
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
movl 0xf4(%rsp), %ecx
shll $0x6, %ecx
cmpl %ecx, %eax
jge 0x84b6
movl 0x54(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0xe8(%rsp), %rdi
movslq 0x5c(%rsp), %rsi
callq 0x12540
movq %rax, 0x10(%rsp)
movslq 0x5c(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x12190
movq 0x10(%rsp), %rdi
movslq (%rax), %rsi
callq 0x12190
movl 0x1c(%rsp), %ecx
movl %ecx, (%rax)
movq 0xe0(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
callq 0x12560
jmp 0x83d8
movq 0xd8(%rsp), %rax
movq %rax, 0x8(%rsp)
movslq 0x5c(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x12190
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x12560
jmp 0x8406
movslq 0x5c(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0x12190
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0xf4(%rsp), %eax
jne 0x84a4
movl $0x0, 0x5c(%rsp)
jmp 0x84a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0x83(%rsp), %rdi
callq 0x4e10
jmp 0x84e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0x63(%rsp), %rdi
callq 0x4e10
jmp 0x84d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x54f0
jmp 0x84d5
jmp 0x84a6
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x836a
leaq 0x68(%rsp), %rdi
callq 0x54f0
leaq 0x88(%rsp), %rdi
callq 0x54f0
addq $0xf8, %rsp
retq
leaq 0x88(%rsp), %rdi
callq 0x54f0
movq 0xa8(%rsp), %rdi
callq 0x36a0
nop