// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
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)
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0x24(%rbp), %eax
jge 0x2bad
jmp 0x2b28
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2b69
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
jl 0x2b61
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2b67
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x2b28
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
jl 0x2b8a
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2b96
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,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 0xb870(%rip), %eax      # 0xe434
movl %eax, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movl 0xb859(%rip), %eax      # 0xe434
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl $0x1, %eax
cmpl -0x30(%rbp), %eax
jne 0x2bfc
movl 0x10(%rbp), %eax
subl $0x1, %eax
cltd
idivl 0xb83b(%rip)            # 0xe434
movl %edx, -0x3c(%rbp)
jmp 0x2bfe
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2c4a
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
movl -0x24(%rbp), %ecx
subl -0x44(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2c42
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2c48
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x2bfe
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
movl -0x24(%rbp), %ecx
subl -0x44(%rbp), %ecx
cmpl %ecx, %eax
jl 0x2c6d
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x2c73
movl -0x3c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0xb7b8(%rip), %eax      # 0xe434
jne 0x2c8a
movl 0xb7b0(%rip), %eax      # 0xe434
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x30(%rbp), %eax
imull 0xb4ef(%rip), %eax      # 0xe1a0
movl -0x34(%rbp), %ecx
imull 0xb4e9(%rip), %ecx      # 0xe1a4
addl %ecx, %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x2dbd
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
movl %ecx, %edx
leaq 0xc79a(%rip), %rcx      # 0xf490
shlq $0x5, %rdx
addq %rdx, %rcx
addl 0x1c(%rcx), %eax
cmpl -0x24(%rbp), %eax
jge 0x2d49
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
movl %eax, %ecx
leaq 0xc762(%rip), %rax      # 0xf490
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x4c(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2dad
movl $0x0, -0x50(%rbp)
cmpl $0x8, -0x50(%rbp)
jge 0x2dab
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rcx
movl -0x4c(%rbp), %eax
movl $0x8, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x64(%rbp), %eax
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
movl %ecx, %edx
leaq 0xc710(%rip), %rcx      # 0xf490
shlq $0x5, %rdx
addq %rdx, %rcx
movslq -0x50(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
cmpl -0x24(%rbp), %eax
jne 0x2d9e
movl -0x4c(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2dd4
jmp 0x2da0
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2d50
jmp 0x2dad
jmp 0x2daf
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2cc0
leaq 0x833e(%rip), %rdi      # 0xb102
movb $0x0, %al
callq 0x2030
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)