// File: /workspace/github_cpp_makefile_star2_O1/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 0x27c7
xorl %edx, %edx
movl %eax, %r10d
cmpl $0x3, %r9d
jl 0x27b2
xorl %edx, %edx
movl %eax, %r10d
leal (%rdx,%r10), %r9d
shrl %r9d
cmpl %ecx, (%rsi,%r9,4)
jl 0x27a6
decl %r9d
movl %r9d, %r10d
jmp 0x27a9
movl %r9d, %edx
leal 0x1(%rdx), %r9d
cmpl %r9d, %r10d
jg 0x2791
movslq %r10d, %r9
cmpl %ecx, (%rsi,%r9,4)
cmovgel %edx, %r9d
movslq %r9d, %r11
movl (%rsi,%r11,4), %r10d
incl %r11d
movl 0x8c56(%rip), %r9d      # 0xb424
leal -0x1(%r9), %esi
movl %esi, %edx
cmpl %r11d, %eax
jne 0x27e3
movl 0x30(%rsp), %eax
decl %eax
cltd
idivl %r9d
movl %r9d, %eax
imull %r11d, %eax
xorl %r14d, %r14d
cmpl $0x2, %edx
jl 0x2826
movl %ecx, %ebp
subl %r10d, %ebp
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 0x281a
decl %r15d
movl %r15d, %edx
jmp 0x281d
movl %r15d, %r14d
leal 0x1(%r14), %r15d
cmpl %r15d, %edx
jg 0x27fa
leal (%rdx,%rax), %ebp
movslq %ebp, %r15
movzwl (%r8,%r15,2), %ebp
movl %ecx, %r15d
subl %r10d, %r15d
cmpl %ebp, %r15d
cmovgl %edx, %r14d
cmpl %r9d, %r14d
cmovel %esi, %r14d
imull 0x8943(%rip), %r11d     # 0xb190
movl 0x8941(%rip), %edx      # 0xb194
imull %r14d, %edx
addl %r11d, %edx
cmpl %ebx, %edx
setl %sil
jge 0x2919
addl %eax, %r14d
movslq %r14d, %rax
movzwl (%r8,%rax,2), %eax
addl %eax, %r10d
leaq 0x9c05(%rip), %r8       # 0xc480
leal 0x7(%rdx), %r9d
testl %edx, %edx
movl %edx, %r11d
cmovsl %r9d, %r11d
sarl $0x3, %r11d
movslq %r11d, %r11
movzbl (%rdi,%r11), %r11d
movl %r11d, %r14d
shll $0x5, %r14d
movl 0x1c(%r14,%r8), %ebp
addl %r10d, %ebp
cmpl %ecx, %ebp
jge 0x28af
movl %ebp, %r10d
movl %r9d, %edx
jmp 0x2909
movl %r11d, %r9d
shll $0x5, %r9d
movl (%r9,%r8), %r14d
addl %r10d, %r14d
xorl %r9d, %r9d
movl $0x0, %ebp
cmpl %ecx, %r14d
je 0x28f8
shll $0x5, %r11d
addq %r8, %r11
addq $0x4, %r11
xorl %r9d, %r9d
cmpq $0x7, %r9
je 0x2900
movl (%r11,%r9,4), %ebp
addl %r10d, %ebp
incq %r9
cmpl %ecx, %ebp
jne 0x28d8
leaq -0x1(%r9), %rax
cmpq $0x7, %rax
setae %bpl
addl %edx, %r9d
movl %r9d, %eax
jmp 0x2904
setae %bpl
testb %bpl, %bpl
je 0x2919
incl %edx
cmpl %ebx, %edx
setl %sil
jl 0x287b
jmp 0x2919
testb $0x1, %sil
jne 0x2931
leaq 0x579b(%rip), %rdi      # 0x80c1
xorl %eax, %eax
callq 0x2030
incl %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq