// File: /workspace/github_cpp_makefile_star2_O1/TooruAkagi[P]GCIS_Index/gcis_uni_build.cpp
// Function: select0(bool*, int*, unsigned short*, int, int, int, int)
int select0(bool *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;
    j=0; //2
    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;
    for(int p=i*lpurse+j*spurse;p<n;p++){
        if(u[p]==0){
            e++;
            if(e==c){return p;}
        }
    }
    return n+1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %r8d, -0x4(%rsp)
movl 0x38(%rsp), %r14d
leal -0x1(%r9), %ebp
movl 0x37f7(%rip), %r8d      # 0x5130
movl %r8d, %r15d
subl (%rsi), %r15d
xorl %r10d, %r10d
movl $0x0, %ebx
movl $0x0, %r11d
cmpl %ecx, %r15d
jge 0x19b6
xorl %r11d, %r11d
movl %ebp, %ebx
cmpl $0x3, %r9d
jl 0x198e
xorl %r11d, %r11d
movl %ebp, %ebx
leal (%r11,%rbx), %r9d
shrl %r9d
leal 0x1(%r9), %r15d
imull %r8d, %r15d
subl (%rsi,%r9,4), %r15d
cmpl %ecx, %r15d
jl 0x1982
decl %r9d
movl %r9d, %ebx
jmp 0x1985
movl %r9d, %r11d
leal 0x1(%r11), %r9d
cmpl %r9d, %ebx
jg 0x1962
leal 0x1(%rbx), %r9d
imull %r8d, %r9d
movslq %ebx, %r15
subl (%rsi,%r15,4), %r9d
cmpl %ecx, %r9d
cmovgel %r11d, %r15d
leal 0x1(%r15), %ebx
movl %ebx, %r11d
imull %r8d, %r11d
movslq %r15d, %r9
subl (%rsi,%r9,4), %r11d
movl 0x3994(%rip), %eax      # 0x5350
movl %eax, %esi
imull %ebx, %esi
cmpl %ebx, %ebp
cmovnel %eax, %r14d
leal -0x1(%r14), %r15d
cmpl $0x3, %r14d
jl 0x1a16
movl 0x375d(%rip), %ebp      # 0x5134
movl %ecx, %r14d
subl %r11d, %r14d
xorl %r10d, %r10d
leal (%r10,%r15), %r12d
shrl %r12d
movl %ebp, %r13d
imull %r12d, %r13d
leal (%r12,%rsi), %r9d
movslq %r9d, %r9
movzwl (%rdx,%r9,2), %r9d
subl %r9d, %r13d
cmpl %r14d, %r13d
jl 0x1a0a
decl %r12d
movl %r12d, %r15d
jmp 0x1a0d
movl %r12d, %r10d
leal 0x1(%r10), %r9d
cmpl %r9d, %r15d
jg 0x19e0
movl 0x3717(%rip), %r14d     # 0x5134
movl %r14d, %r9d
imull %r15d, %r9d
leal (%r15,%rsi), %ebp
movslq %ebp, %r12
movzwl (%rdx,%r12,2), %ebp
subl %ebp, %r9d
movl %ecx, %ebp
subl %r11d, %ebp
cmpl %ebp, %r9d
cmovll %r15d, %r10d
leal -0x1(%rax), %ebp
cmpl %eax, %r10d
cmovnel %r10d, %ebp
imull %ebp, %r14d
imull %r8d, %ebx
leal (%r14,%rbx), %r8d
movl -0x4(%rsp), %eax
cmpl %eax, %r8d
setl %r9b
jge 0x1a9b
addl %esi, %ebp
movslq %ebp, %rsi
movzwl (%rdx,%rsi,2), %edx
subl %edx, %r11d
addl %r14d, %r11d
movslq %r14d, %rdx
movslq %ebx, %r8
addq %rdx, %r8
movslq %eax, %rdx
cmpb $0x0, (%rdi,%r8)
jne 0x1a8c
incl %r11d
cmpl %ecx, %r11d
je 0x1a9b
incq %r8
cmpq %rdx, %r8
setl %r9b
jl 0x1a7d
movl %eax, %r8d
incl %eax
testb $0x1, %r9b
cmovnel %r8d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq