// File: /workspace/github_cpp_makefile_star2_O2/TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: selectnew0(unsigned char*, int*, unsigned short*, int, int, int, int)
int selectnew0(unsigned char *u,int *u2,unsigned short int *u3,int c,int n,int t2,int t3){ //k番目の0を探す．
    int i = 0;
    int j = 0;
    int l = 0;
    int hmax = t2-1;int hmin = 0;
    if(lpurse-u2[0]<c){
        while(hmax>hmin+1){
            i = (hmax+hmin)/2;
            if((i+1)*lpurse-u2[i]>=c){hmax = i-1;}
            else{hmin = i;}
        }
        if((hmax+1)*lpurse-u2[hmax]>=c){i = hmin;hmax = hmin-1;}
        else{i=hmax;hmin = hmax;}
        l = (i+1)*lpurse-u2[i];
        i++;
    }
    int e = l;l=0;
    int ofi = i*spursesuu;
    //if(gate>0){printf("(select_0 - %d,%d)",e,t2);}
    j=0; //2回目のloglog探索
    hmin = 0;hmax = spursesuu-1;
    if(t2-1 == i){hmax = t3-1;}
    while(hmax>hmin+1){
        j = (hmax+hmin)/2;
        if(j*spurse-u3[ofi+j]>=c-e){hmax = j-1;}
        else{hmin = j;}
    }
    if(hmax*spurse-u3[ofi+hmax]>=c-e){j = hmin;}else{j = hmax;}
    if(j==spursesuu){j=spursesuu-1;}
    l = j*spurse-u3[ofi+j];
    e += l;
    //if(gate>0){printf("(select_0 - %d/ %d,%d,%d,%d)",c,e,l,n,t3);}
    for(int p=i*lpurse+j*spurse;p<n;p++){
        //if(c==723466){printf("\n[%d-%d-%d]",u[p/8],(8-rankct[u[p/8]][7]),p);}
        if(e+(8-rankct[u[p/8]][7])<c){
            e+=8-rankct[u[p/8]][7];p+=7;
        }
        else{
            for(int ji=0;ji<8;ji++){
                //if(c==723466){
                //    printf("\n後%d:LAST[%d-%d-%d]",c-e,u[p/8],(1+ji-rankct[u[p/8]][ji]),p);
                //}
                if(e+(1+ji-rankct[u[p/8]][ji])==c){return p+ji;}
            }
        }
    }
    return n+1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, -0x8(%rsp)
movl 0x38(%rsp), %r14d
decl %r9d
movl 0x7903(%rip), %eax      # 0xa1a0
movl %eax, %ebp
subl (%rsi), %ebp
xorl %ebx, %ebx
movl $0x0, %r10d
movl $0x0, %r11d
cmpl %ecx, %ebp
jge 0x290d
xorl %r15d, %r15d
movl %r9d, %r10d
leal 0x1(%r15), %r11d
cmpl %r11d, %r10d
jle 0x28e5
leal (%r15,%r10), %r11d
shrl %r11d
leal 0x1(%r11), %ebp
imull %eax, %ebp
subl (%rsi,%r11,4), %ebp
cmpl %ecx, %ebp
jl 0x28e0
decl %r11d
movl %r11d, %r10d
jmp 0x28b9
movl %r11d, %r15d
jmp 0x28b9
leal 0x1(%r10), %r11d
imull %eax, %r11d
movslq %r10d, %r12
subl (%rsi,%r12,4), %r11d
cmpl %ecx, %r11d
cmovll %r10d, %r15d
leal 0x1(%r15), %r10d
movl %r10d, %r11d
imull %eax, %r11d
movslq %r15d, %r15
subl (%rsi,%r15,4), %r11d
movl 0x7b21(%rip), %edi      # 0xa434
movl %edi, %r15d
imull %r10d, %r15d
cmpl %r10d, %r9d
cmovnel %edi, %r14d
decl %r14d
movl 0x787a(%rip), %esi      # 0xa1a4
movl %ecx, %r9d
subl %r11d, %r9d
leal 0x1(%rbx), %ebp
cmpl %ebp, %r14d
jle 0x2966
leal (%rbx,%r14), %r13d
shrl %r13d
movl %esi, %ebp
imull %r13d, %ebp
leal (%r15,%r13), %r12d
movslq %r12d, %r12
movzwl (%rdx,%r12,2), %r12d
subl %r12d, %ebp
cmpl %r9d, %ebp
jl 0x2961
decl %r13d
movl %r13d, %r14d
jmp 0x2930
movl %r13d, %ebx
jmp 0x2930
movl %esi, %ebp
imull %r14d, %ebp
leal (%r14,%r15), %r12d
movslq %r12d, %r12
movzwl (%rdx,%r12,2), %r12d
subl %r12d, %ebp
cmpl %r9d, %ebp
cmovll %r14d, %ebx
leal -0x1(%rdi), %r9d
cmpl %edi, %ebx
cmovnel %ebx, %r9d
imull %r9d, %esi
addl %r15d, %r9d
movslq %r9d, %rdi
movzwl (%rdx,%rdi,2), %edx
subl %edx, %r11d
addl %esi, %r11d
imull %eax, %r10d
addl %esi, %r10d
movl $0x8, %esi
leaq 0x8add(%rip), %r9       # 0xb490
movq -0x8(%rsp), %r14
cmpl %r8d, %r10d
jge 0x2a11
movl %r10d, %eax
cltd
idivl %esi
cltq
movzbl (%r14,%rax), %eax
movl %eax, %edi
shll $0x5, %edi
movl %r11d, %edx
subl 0x1c(%rdi,%r9), %edx
addl $0x8, %edx
cmpl %ecx, %edx
jge 0x29ea
addl $0x7, %r10d
movl %edx, %r11d
incl %r10d
jmp 0x29b8
shll $0x5, %eax
movl %ecx, %edx
subl %r11d, %edx
xorl %ebx, %ebx
cmpq $0x8, %rbx
je 0x29e5
leaq (%rax,%rbx,4), %rdi
incq %rbx
movl (%r9,%rdi), %edi
addl %edx, %edi
cmpl %ebx, %edi
jne 0x29f4
leal (%r10,%rbx), %edx
decl %edx
leal 0x1(%r8), %eax
cmpl %r8d, %r10d
cmovll %edx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq