// File: TooruAkagi[P]GCIS_Index/gcis_nep_locate.cpp
// Function: pschecks(unsigned int*, int*, int, int, int)
int pschecks(unsigned int *D,int *D_2,int start,int plen,int round){
    //mのstartmからmlenを，分割の最初から始まるものだけ探す
    //配列mのstartからplen文字一致する最も番号の小さいものを探す
    //printf("\n[");for(int y8=0;y8<plen;y8++){printf(" %d",m[start+y8]);}printf("]を探す");
    int rofs = 0;if(round>1){rofs=dc2s[round-1];}
    int pos = 0;int posup = dc2s[round]-1;int posbt = dc2s[round+1]; //round内のみで計算する
    while(1){
        pos = posup + (posbt-posup)/2;int k = 0;
        for(int i = 0;i<plen;i++){
            if(i == D_2[pos+1]-D_2[pos]){k=-1;break;} //分割が短すぎる = この分割より後に出てくるはず
            if(m[start+i]-rofs==D[D_2[pos]+i]){k=0;}
            if(m[start+i]-rofs>D[D_2[pos]+i]){k=-1;break;} //pos should be larger than now
            if(m[start+i]-rofs<D[D_2[pos]+i]){k=1;break;} //pos should be smaller than now
        }
        if(k==-1){posup=pos;}
        if(k==1){posbt=pos;}
        if(k==0){ //パターンと完全に一致するprefixを持っている
                posbt=pos;
        }
        if(posbt-posup<2){pos=-1;break;} //もう探すところがない
    }
    //printf("\n[最小:%d]",posbt);
    return posbt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x1, -0x1c(%rbp)
jle 0x3279
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xa43d(%rip), %rax      # 0xd6b0
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0xa425(%rip), %rax      # 0xd6b0
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0xa40c(%rip), %rax      # 0xd6b0
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x38(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x33c9
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movl -0x24(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movq -0x10(%rbp), %rdx
movslq -0x24(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
cmpl %ecx, %eax
jne 0x3310
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x33c9
movq 0xa409(%rip), %rax      # 0xd720
movl -0x14(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
subl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rdx
movslq -0x24(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x34(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x3347
movl $0x0, -0x30(%rbp)
movq 0xa3d2(%rip), %rax      # 0xd720
movl -0x14(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
subl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rdx
movslq -0x24(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x34(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jbe 0x3380
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x33c9
movq 0xa399(%rip), %rax      # 0xd720
movl -0x14(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
subl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movq -0x10(%rbp), %rdx
movslq -0x24(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x34(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x33b9
movl $0x1, -0x30(%rbp)
jmp 0x33c9
jmp 0x33bb
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x32d6
cmpl $-0x1, -0x30(%rbp)
jne 0x33d5
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0x33e1
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x33ed
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
cmpl $0x2, %eax
jge 0x3401
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
jmp 0x3406
jmp 0x32aa
movl -0x2c(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)