// File: TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: selectnew0(unsigned char*, int*, unsigned short*, int, int, int, int)
int selectnew0(unsigned char *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;
    //if(gate>0){printf("(select_0 - %d,%d)",e,t2);}
    j=0; //2回目のloglog探索
    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;
    //if(gate>0){printf("(select_0 - %d/ %d,%d,%d,%d)",c,e,l,n,t3);}
    for(int p=i*lpurse+j*spurse;p<n;p++){
        //if(c==723466){printf("\n[%d-%d-%d]",u[p/8],(8-rankct[u[p/8]][7]),p);}
        if(e+(8-rankct[u[p/8]][7])<c){
            e+=8-rankct[u[p/8]][7];p+=7;
        }
        else{
            for(int ji=0;ji<8;ji++){
                //if(c==723466){
                //    printf("\n後%d:LAST[%d-%d-%d]",c-e,u[p/8],(1+ji-rankct[u[p/8]][ji]),p);
                //}
                if(e+(1+ji-rankct[u[p/8]][ji])==c){return p+ji;}
            }
        }
    }
    return n+1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl 0xb377(%rip), %eax      # 0xe1a0
movq -0x18(%rbp), %rcx
subl (%rcx), %eax
cmpl -0x24(%rbp), %eax
jge 0x2ee6
jmp 0x2e3a
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2e88
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
imull 0xb33b(%rip), %eax      # 0xe1a0
movq -0x18(%rbp), %rcx
movslq -0x30(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
cmpl -0x24(%rbp), %eax
jl 0x2e80
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2e86
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x2e3a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
imull 0xb30b(%rip), %eax      # 0xe1a0
movq -0x18(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
cmpl -0x24(%rbp), %eax
jl 0x2eb6
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2ec2
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
imull 0xb2d1(%rip), %eax      # 0xe1a0
movq -0x18(%rbp), %rcx
movslq -0x30(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x30(%rbp), %eax
imull 0xb537(%rip), %eax      # 0xe434
movl %eax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movl 0xb520(%rip), %eax      # 0xe434
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl $0x1, %eax
cmpl -0x30(%rbp), %eax
jne 0x2f2e
movl 0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f30
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2f88
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
imull 0xb24c(%rip), %eax      # 0xe1a4
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
addl -0x34(%rbp), %edx
movslq %edx, %rdx
movzwl (%rcx,%rdx,2), %ecx
subl %ecx, %eax
movl -0x24(%rbp), %ecx
subl -0x44(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2f80
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2f86
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x2f30
movl -0x3c(%rbp), %eax
imull 0xb212(%rip), %eax      # 0xe1a4
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
addl -0x3c(%rbp), %edx
movslq %edx, %rdx
movzwl (%rcx,%rdx,2), %ecx
subl %ecx, %eax
movl -0x24(%rbp), %ecx
subl -0x44(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2fb7
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x2fbd
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xb46e(%rip), %eax      # 0xe434
jne 0x2fd4
movl 0xb466(%rip), %eax      # 0xe434
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
imull 0xb1c6(%rip), %eax      # 0xe1a4
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
addl -0x34(%rbp), %edx
movslq %edx, %rdx
movzwl (%rcx,%rdx,2), %ecx
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x30(%rbp), %eax
imull 0xb199(%rip), %eax      # 0xe1a0
movl -0x34(%rbp), %ecx
imull 0xb193(%rip), %ecx      # 0xe1a4
addl %ecx, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x312b
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rcx
movl -0x4c(%rbp), %eax
movl $0x8, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x54(%rbp), %eax
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
leaq 0xc446(%rip), %rdx      # 0xf490
shlq $0x5, %rcx
addq %rcx, %rdx
movl $0x8, %ecx
subl 0x1c(%rdx), %ecx
addl %ecx, %eax
cmpl -0x24(%rbp), %eax
jge 0x30a7
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x4c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
leaq 0xc409(%rip), %rcx      # 0xf490
shlq $0x5, %rax
addq %rax, %rcx
movl $0x8, %eax
subl 0x1c(%rcx), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x4c(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x4c(%rbp)
jmp 0x311b
movl $0x0, -0x50(%rbp)
cmpl $0x8, -0x50(%rbp)
jge 0x3119
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x50(%rbp), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x4c(%rbp), %eax
movl $0x8, %esi
cltd
idivl %esi
movq -0x70(%rbp), %rdx
movl %eax, %esi
movl -0x64(%rbp), %eax
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
movl %edx, %esi
leaq 0xc3a4(%rip), %rdx      # 0xf490
shlq $0x5, %rsi
addq %rsi, %rdx
movslq -0x50(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
addl %ecx, %eax
cmpl -0x24(%rbp), %eax
jne 0x310c
movl -0x4c(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3134
jmp 0x310e
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x30ae
jmp 0x311b
jmp 0x311d
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3016
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)