// File: /workspace/github_cpp_makefile_star2_O3/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
leal -0x1(%r9), %eax
xorl %r11d, %r11d
movl $0x0, %r10d
cmpl %ecx, (%rsi)
jge 0x27b9
xorl %edx, %edx
movl %eax, %r10d
cmpl $0x3, %r9d
jl 0x27a4
xorl %edx, %edx
movl %eax, %r10d
leal (%rdx,%r10), %r9d
shrl %r9d
cmpl %ecx, (%rsi,%r9,4)
jl 0x2798
decl %r9d
movl %r9d, %r10d
jmp 0x279b
movl %r9d, %edx
leal 0x1(%rdx), %r9d
cmpl %r9d, %r10d
jg 0x2783
movslq %r10d, %r9
cmpl %ecx, (%rsi,%r9,4)
cmovgel %edx, %r9d
movslq %r9d, %r11
movl (%rsi,%r11,4), %r10d
incl %r11d
movl 0x8c64(%rip), %r9d      # 0xb424
leal -0x1(%r9), %esi
movl %esi, %edx
cmpl %r11d, %eax
jne 0x27d5
movl 0x30(%rsp), %eax
decl %eax
cltd
idivl %r9d
movl %r9d, %eax
imull %r11d, %eax
movl %ecx, %ebp
subl %r10d, %ebp
xorl %r14d, %r14d
cmpl $0x2, %edx
jl 0x2818
xorl %r14d, %r14d
leal (%r14,%rdx), %r15d
shrl %r15d
leal (%r15,%rax), %r12d
movslq %r12d, %r12
movzwl (%r8,%r12,2), %r12d
cmpl %r12d, %ebp
jg 0x280c
decl %r15d
movl %r15d, %edx
jmp 0x280f
movl %r15d, %r14d
leal 0x1(%r14), %r15d
cmpl %r15d, %edx
jg 0x27ec
leal (%rdx,%rax), %r15d
movslq %r15d, %r15
movzwl (%r8,%r15,2), %r15d
cmpl %r15d, %ebp
cmovgl %edx, %r14d
cmpl %r9d, %r14d
cmovel %esi, %r14d
imull 0x8956(%rip), %r11d     # 0xb190
movl 0x8954(%rip), %esi      # 0xb194
imull %r14d, %esi
addl %r11d, %esi
cmpl %ebx, %esi
jge 0x28bc
addl %eax, %r14d
movslq %r14d, %rax
movzwl (%r8,%rax,2), %eax
addl %eax, %r10d
leaq 0x9c20(%rip), %rax      # 0xc480
movl %esi, %edx
leal 0x7(%rsi), %r8d
testl %esi, %esi
cmovnsl %esi, %r8d
sarl $0x3, %r8d
movslq %r8d, %rsi
movzbl (%rdi,%rsi), %esi
movl %esi, %r8d
shll $0x5, %r8d
movl 0x1c(%r8,%rax), %r8d
addl %r10d, %r8d
cmpl %ecx, %r8d
jge 0x2895
addl $0x7, %edx
movl %edx, %esi
movl %r8d, %r10d
jmp 0x28b6
shll $0x5, %esi
xorl %r8d, %r8d
leaq (%rsi,%r8,4), %r9
movl (%rax,%r9), %r9d
addl %r10d, %r9d
cmpl %ecx, %r9d
je 0x28ce
incq %r8
cmpq $0x8, %r8
jne 0x289b
movl %edx, %esi
incl %esi
cmpl %ebx, %esi
jl 0x2860
leaq 0x582e(%rip), %rdi      # 0x80f1
xorl %eax, %eax
callq 0x2030
incl %ebx
jmp 0x28d3
addl %r8d, %edx
movl %edx, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq