// File: TooruAkagi[P]GCIS_Index/gcis_nep_locate.cpp
// Function: pscheck(unsigned int*, int*, int, int, int)
int pscheck(unsigned int *D,int *D_2,int start,int plen, int round){ 
    //配列mのstartからplen文字の完全一致を探す
    //if(DEBUGFLAG==1){
    //    printf("\npscheck[");
    //    for(int j = 0;j<plen;j++){printf("%d ",m[start+j]);}
    //    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;
        //printf("\nテスト %d %d %d",pos,posbt,posup);
        int k = 0; // : the length of same prefix. if k == plen == the length of the purse, it's exactly the answer.
        int r = 0; // : for debuging
        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){
                if(D_2[pos+1]-D_2[pos]==plen){break;} //発見
                else{posbt=pos;} //パターンが短すぎる = もっと前に出てくるはず
        }
        //if(DEBUGFLAG==1){printf("\n >>  %d %d %d",pos,posbt,posup);}
        if(posbt-posup<2){pos=-1;break;} //もう探すところがない
    }
    //printf("位置%d ",pos);
    return pos;
}

// 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 0x2619
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xb09d(%rip), %rax      # 0xd6b0
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0xb085(%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 0xb06c(%rip), %rax      # 0xd6b0
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x3c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x2770
movl -0x38(%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 0x26b7
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x2770
movq 0xb062(%rip), %rax      # 0xd720
movl -0x14(%rbp), %ecx
addl -0x38(%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 -0x38(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x26ee
movl $0x0, -0x30(%rbp)
movq 0xb02b(%rip), %rax      # 0xd720
movl -0x14(%rbp), %ecx
addl -0x38(%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 -0x38(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jbe 0x2727
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x2770
movq 0xaff2(%rip), %rax      # 0xd720
movl -0x14(%rbp), %ecx
addl -0x38(%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 -0x38(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x2760
movl $0x1, -0x30(%rbp)
jmp 0x2770
jmp 0x2762
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x267d
cmpl $-0x1, -0x30(%rbp)
jne 0x277c
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0x2788
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x27b8
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
cmpl -0x18(%rbp), %eax
jne 0x27b0
jmp 0x27d1
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x27b8
movl -0x2c(%rbp), %eax
subl -0x28(%rbp), %eax
cmpl $0x2, %eax
jge 0x27cc
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
jmp 0x27d1
jmp 0x264a
movl -0x24(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)