// File: TooruAkagi[P]GCIS_Index/gcis_nep_build.cpp
// Function: bbsort(unsigned int*, int*, int*, int*, int, int, int)
void bbsort(unsigned int *T,int *P,int *P_2,int *I,int a,int b,int c){
    //to sort [c] purse(s) with [a]-th character from position [b] in I.
    //[c is really small] 
    sortstack--;
    if(DEBUGFLAG==1){printf("\nbbsort(%d,%d,%d)",a,b,c);}
    for(int i = 0;i<c;i++){
        int k = i;
        //int bc = T[P[I[b+i]]+a]; //a-th character in I[b+i]
        if(a+1 > P_2[I[b+i]]){continue;} //
        for(int j = i; j<c; j++){
            if(a+1 > P_2[I[b+j]]){k = j;break;}  //if the purse [i] doesn't have a-th character,exactly it's smaller;
            else{ //check next cheracter until one of each purse reaches the end
                int d = a;
                while(1){
                    //printf("\n[%d]",d);
                    if(T[P[I[b+k]]+d] > T[P[I[b+j]]+d]){k = j;break;}
                    if(T[P[I[b+k]]+d] < T[P[I[b+j]]+d]){break;}
                    d++;
                    if(d+1 > P_2[I[b+k]]){break;}
                    if(d+1 > P_2[I[b+j]]){k=j;break;}
                }
            }
        }
        if(k!=i){
            //printf("swap!");
            int tem = I[b+i];
            I[b+i] = I[b+k];
            I[b+k] = tem;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl 0x4d5b(%rip), %eax      # 0x7180
addl $-0x1, %eax
movl %eax, 0x4d52(%rip)      # 0x7180
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x261c
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %esi
addl -0x2c(%rbp), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x246c
jmp 0x260e
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x25be
movl -0x24(%rbp), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %esi
addl -0x34(%rbp), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x24a9
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x25be
movl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %esi
addl -0x30(%rbp), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x38(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rsi
movl -0x28(%rbp), %edi
addl -0x34(%rbp), %edi
movslq %edi, %rdi
movslq (%rsi,%rdi,4), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x38(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jbe 0x2506
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x25ac
movq -0x8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %esi
addl -0x30(%rbp), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
movl (%rcx,%rdx,4), %ecx
addl -0x38(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rsi
movl -0x28(%rbp), %edi
addl -0x34(%rbp), %edi
movslq %edi, %rdi
movslq (%rsi,%rdi,4), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x38(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x2554
jmp 0x25ac
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %esi
addl -0x30(%rbp), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x257f
jmp 0x25ac
movl -0x38(%rbp), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
movl -0x28(%rbp), %esi
addl -0x34(%rbp), %esi
movslq %esi, %rsi
movslq (%rdx,%rsi,4), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x25a7
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x25ac
jmp 0x24af
jmp 0x25ae
jmp 0x25b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2472
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x260c
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x30(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x260e
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2435
popq %rbp
retq
nop