// File: /workspace/github_cpp_makefile_star2_O2/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), %r11d
decl %r9d
movl 0x38b0(%rip), %eax      # 0x5130
movl %eax, %r14d
subl (%rsi), %r14d
xorl %r10d, %r10d
movl $0x0, %ebp
movl $0x0, %ebx
cmpl %ecx, %r14d
jge 0x18ec
xorl %r14d, %r14d
movl %r9d, %ebx
leal 0x1(%r14), %ebp
cmpl %ebp, %ebx
jle 0x18c9
leal (%r14,%rbx), %r15d
shrl %r15d
leal 0x1(%r15), %ebp
imull %eax, %ebp
subl (%rsi,%r15,4), %ebp
cmpl %ecx, %ebp
jl 0x18c4
decl %r15d
movl %r15d, %ebx
jmp 0x189e
movl %r15d, %r14d
jmp 0x189e
leal 0x1(%rbx), %ebp
imull %eax, %ebp
movslq %ebx, %r15
subl (%rsi,%r15,4), %ebp
cmpl %ecx, %ebp
cmovll %ebx, %r14d
leal 0x1(%r14), %ebp
movl %ebp, %ebx
imull %eax, %ebx
movslq %r14d, %r14
subl (%rsi,%r14,4), %ebx
movl 0x3a5d(%rip), %r8d      # 0x5350
movl %r8d, %r14d
imull %ebp, %r14d
cmpl %ebp, %r9d
cmovnel %r8d, %r11d
decl %r11d
movl 0x382a(%rip), %esi      # 0x5134
movl %ecx, %r9d
subl %ebx, %r9d
leal 0x1(%r10), %r12d
cmpl %r12d, %r11d
jle 0x1948
leal (%r10,%r11), %r12d
shrl %r12d
movl %esi, %r13d
imull %r12d, %r13d
leal (%r12,%r14), %r15d
movslq %r15d, %r15
movzwl (%rdx,%r15,2), %r15d
subl %r15d, %r13d
cmpl %r9d, %r13d
jl 0x1943
decl %r12d
movl %r12d, %r11d
jmp 0x1910
movl %r12d, %r10d
jmp 0x1910
movl %esi, %r15d
imull %r11d, %r15d
leal (%r11,%r14), %r12d
movslq %r12d, %r12
movzwl (%rdx,%r12,2), %r12d
subl %r12d, %r15d
cmpl %r9d, %r15d
cmovll %r11d, %r10d
leal -0x1(%r8), %r9d
cmpl %r8d, %r10d
cmovnel %r10d, %r9d
imull %r9d, %esi
addl %r14d, %r9d
movslq %r9d, %r8
movzwl (%rdx,%r8,2), %edx
subl %edx, %ebx
addl %esi, %ebx
imull %eax, %ebp
addl %esi, %ebp
movslq %ebp, %rdx
movslq -0x4(%rsp), %rsi
cmpl %edx, %esi
movl %edx, %r8d
cmovgl %esi, %r8d
cmpq %rsi, %rdx
jge 0x19b2
cmpb $0x0, (%rdi,%rdx)
jne 0x19aa
incl %ebx
cmpl %ecx, %ebx
je 0x19af
incq %rdx
jmp 0x1999
movl %edx, %r8d
leal 0x1(%rsi), %eax
cmpq %rsi, %rdx
cmovll %r8d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq