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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %r8d, %ebx
movq %rdx, %r8
decl %r9d
xorl %r11d, %r11d
movl $0x0, %r10d
cmpl %ecx, (%rsi)
jge 0x2778
xorl %eax, %eax
movl %r9d, %edx
leal 0x1(%rax), %r10d
cmpl %r10d, %edx
jle 0x2764
leal (%rax,%rdx), %r10d
shrl %r10d
cmpl %ecx, (%rsi,%r10,4)
jl 0x275f
decl %r10d
movl %r10d, %edx
jmp 0x2741
movl %r10d, %eax
jmp 0x2741
movslq %edx, %r10
cmpl %ecx, (%rsi,%r10,4)
cmovll %edx, %eax
movslq %eax, %r11
movl (%rsi,%r11,4), %r10d
incl %r11d
movl 0x7cb5(%rip), %r14d     # 0xa434
leal -0x1(%r14), %ebp
movl %ebp, %edx
cmpl %r11d, %r9d
jne 0x2794
movl 0x30(%rsp), %eax
decl %eax
cltd
idivl %r14d
movl %r14d, %eax
imull %r11d, %eax
movl %ecx, %r9d
subl %r10d, %r9d
xorl %esi, %esi
leal 0x1(%rsi), %r15d
cmpl %r15d, %edx
jle 0x27d1
leal (%rsi,%rdx), %r15d
shrl %r15d
leal (%r15,%rax), %r12d
movslq %r12d, %r12
movzwl (%r8,%r12,2), %r12d
cmpl %r12d, %r9d
jg 0x27cc
decl %r15d
movl %r15d, %edx
jmp 0x27a3
movl %r15d, %esi
jmp 0x27a3
leal (%rdx,%rax), %r15d
movslq %r15d, %r15
movzwl (%r8,%r15,2), %r15d
cmpl %r15d, %r9d
cmovgl %edx, %esi
cmpl %r14d, %esi
cmovel %ebp, %esi
addl %esi, %eax
cltq
movzwl (%r8,%rax,2), %eax
imull 0x79a6(%rip), %r11d     # 0xa1a0
imull 0x79a3(%rip), %esi      # 0xa1a4
addl %eax, %r10d
addl %r11d, %esi
pushq $0x8
popq %r8
leaq 0x8c7e(%rip), %r9       # 0xb490
cmpl %ebx, %esi
jge 0x286c
movl %esi, %esi
movl %esi, %eax
cltd
idivl %r8d
cltq
movzbl (%rdi,%rax), %eax
movl %eax, %edx
shll $0x5, %edx
movl 0x1c(%rdx,%r9), %edx
addl %r10d, %edx
cmpl %ecx, %edx
jge 0x283f
addl $0x7, %esi
movl %edx, %r10d
incl %esi
jmp 0x2812
shll $0x5, %eax
xorl %edx, %edx
cmpq $0x8, %rdx
je 0x283b
leaq (%rax,%rdx,4), %r11
movl (%r9,%r11), %r11d
addl %r10d, %r11d
cmpl %ecx, %r11d
je 0x285f
incq %rdx
jmp 0x2844
addl %edx, %esi
movl %esi, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x487e(%rip), %rdi      # 0x70f1
xorl %eax, %eax
callq 0x2030
incl %ebx
movl %ebx, %esi
jmp 0x2861