// File: TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: pscheck(int*, int, int, int)
int pscheck(int *m,int start,int plen, int round){ //完全一致を探す
    bool *bitlet;
    bitlet = (bool*)malloc(10000);
    //round 0 .. 0からccs[round]
    //round1 ccs[round](118)を足す
    //round2 dc2s[1](57466)を引いた値(0〜dc2s[1]〜[2]にccs[2](56461)を足す)
    //round3 dc2s[2]をひいてccs[3]を足す
    int rofs = ccs[round];
    if(round>=2){rofs-=dc2s[round-1];}
    int y = cmlen(m,start,plen,bitlet);
    int a,b,c,d;
    int posup = selectnew1(k3x,k3sub,k3sub2,m[start]+rofs,Sizelist[8],Sizelist[3],Sizelist[4]);
    int posbt = selectnew1(k3x,k3sub,k3sub2,m[start]+1+rofs,Sizelist[8],Sizelist[3],Sizelist[4]);
    int ry = posup;
    posup = sranknew0(posup,k3x,k3sub,k3sub2,Sizelist[3],Sizelist[4])-1;
    posbt = sranknew0(posbt,k3x,k3sub,k3sub2,Sizelist[3],Sizelist[4]);
    //if(posup>=661175){printf("[%d]のエラー:%d[%d]\n",m[start],ry,rofs);}
    //printf("%d > %d >> (%d 〜 %d)%d - %d[%d]\n",m[start]+rofs,ry,posup,posbt,plen,start,round);
    if(posup < dc2s[round]-1){posup = dc2s[round]-1;}
    if(posbt > dc2s[round+1]){posbt = dc2s[round+1];}
    int pos = 0;
    //printf("%d:(%d 〜 %d)%d - %d\n",rofs,posup,posbt,plen,start);
    //for(int y6=0;y6<plen;y6++){printf("[%d]",m[start+y6]);}
    //posup = 既に絶対違うと考えられるところ(round0だと-1)
    //posbt = 既に絶対違うと考えられるところ(round0だと分割数そのもの)
    while(1){
        pos = posup + (posbt-posup)/2;
        b = selectnew0(d2topx,d2topsub,d2topsub2,pos+1,Sizelist[9],Sizelist[5],Sizelist[6]);
        b = sranknew1(b,d2topx,d2topsub,d2topsub2,Sizelist[5],Sizelist[6]); //その位置までの1の数 = 開始文字.
        c = bread(d2under,pos*6,6);
        d = b*64+c;
        c = gread(d,k);d+=loga(c)*2-1;
            //if(round==9){gate++;}
            a = selectnew0(d2topx,d2topsub,d2topsub2,pos+2,Sizelist[9],Sizelist[5],Sizelist[6]);
            a = sranknew1(a,d2topx,d2topsub,d2topsub2,Sizelist[5],Sizelist[6]);
            a*=64;a+=bread(d2under,(pos+1)*6,6);a-=d;
        b = pscmpr(k,bitlet,d,0,kad,c-1,plen-1,y-1,a);
        //if(round==9){printf("\n[pscmpr(%d,%d,%d,%d / %d,%d,%d)\n]",a,c-1,y-1,b,posup,pos,posbt);}
        if(b==2){
            a = selectnew0(d2topx,d2topsub,d2topsub2,pos+2,Sizelist[9],Sizelist[5],Sizelist[6]);
            a = sranknew1(a,d2topx,d2topsub,d2topsub2,Sizelist[5],Sizelist[6]);
            a*=64;a+=bread(d2under,(pos+1)*6,6);
            if(a>d+kad){b=1;}
            if(a<=d+kad){b=pos;break;}
        }
        if(b==0){posup=pos;}
        if(b==1){posbt=pos;}
        if(posbt-posup<2){
            printf("\n分割にないため存在しない");pos=-1;
            break;
        }
    }
    if(pos==-1){
        //for(int yj=0;yj<plen;yj++){printf(" %d",m[start+yj]);}
        //for(int yj=0;yj<=loops;yj++){printf("\ndc2s[%d]=%d,%d",yj,dc2s[yj],ccs[yj]);}
        //for(int yj=1;yj<=loops;yj++){uhdisp(dc2s[yj]-1);}
        exit(6);
        }
   //printf(" -> %d\n",pos);
    return pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl $0x2710, %edi           # imm = 0x2710
callq 0x21f0
movq %rax, -0x20(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0xa412(%rip), %rax      # 0xe340
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
cmpl $0x2, -0x14(%rbp)
jl 0x3f55
movl -0x14(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0xa3a6(%rip), %rax      # 0xe2f0
movl (%rax,%rcx,4), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x20(%rbp), %rcx
callq 0x27a0
movl %eax, -0x28(%rbp)
movq 0xa546(%rip), %rdi      # 0xe4b8
movq 0xa4e7(%rip), %rsi      # 0xe460
movq 0xa4c8(%rip), %rdx      # 0xe448
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
addl -0x24(%rbp), %ecx
movl 0xa23b(%rip), %r8d      # 0xe1d0
movl 0xa220(%rip), %r9d      # 0xe1bc
movl 0xa21e(%rip), %eax      # 0xe1c0
movl %eax, (%rsp)
callq 0x2ad0
movl %eax, -0x3c(%rbp)
movq 0xa504(%rip), %rdi      # 0xe4b8
movq 0xa4a5(%rip), %rsi      # 0xe460
movq 0xa486(%rip), %rdx      # 0xe448
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
addl $0x1, %ecx
addl -0x24(%rbp), %ecx
movl 0xa1f6(%rip), %r8d      # 0xe1d0
movl 0xa1db(%rip), %r9d      # 0xe1bc
movl 0xa1d9(%rip), %eax      # 0xe1c0
movl %eax, (%rsp)
callq 0x2ad0
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %edi
movq 0xa4b6(%rip), %rsi      # 0xe4b8
movq 0xa457(%rip), %rdx      # 0xe460
movq 0xa438(%rip), %rcx      # 0xe448
movl 0xa1a5(%rip), %r8d      # 0xe1bc
movl 0xa1a2(%rip), %r9d      # 0xe1c0
callq 0x2a80
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %edi
movq 0xa485(%rip), %rsi      # 0xe4b8
movq 0xa426(%rip), %rdx      # 0xe460
movq 0xa407(%rip), %rcx      # 0xe448
movl 0xa174(%rip), %r8d      # 0xe1bc
movl 0xa171(%rip), %r9d      # 0xe1c0
callq 0x2a80
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movslq -0x14(%rbp), %rdx
leaq 0xa28b(%rip), %rcx      # 0xe2f0
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4083
movslq -0x14(%rbp), %rcx
leaq 0xa276(%rip), %rax      # 0xe2f0
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
leaq 0xa25a(%rip), %rcx      # 0xe2f0
cmpl (%rcx,%rdx,4), %eax
jle 0x40b1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0xa245(%rip), %rax      # 0xe2f0
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movq 0xa3e3(%rip), %rdi      # 0xe4c0
movq 0xa374(%rip), %rsi      # 0xe458
movq 0xa355(%rip), %rdx      # 0xe440
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
movl 0xa0dc(%rip), %r8d      # 0xe1d4
movl 0xa0c5(%rip), %r9d      # 0xe1c4
movl 0xa0c3(%rip), %eax      # 0xe1c8
movl %eax, (%rsp)
callq 0x2de0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %edi
movq 0xa3a6(%rip), %rsi      # 0xe4c0
movq 0xa337(%rip), %rdx      # 0xe458
movq 0xa318(%rip), %rcx      # 0xe440
movl 0xa095(%rip), %r8d      # 0xe1c4
movl 0xa092(%rip), %r9d      # 0xe1c8
callq 0x28e0
movl %eax, -0x30(%rbp)
movq 0xa363(%rip), %rdi      # 0xe4a8
imull $0x6, -0x48(%rbp), %esi
movl $0x6, %edx
callq 0x25d0
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
shll $0x6, %eax
addl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %edi
movq 0xa32c(%rip), %rsi      # 0xe498
callq 0x2850
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edi
callq 0x2570
shll %eax
subl $0x1, %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq 0xa332(%rip), %rdi      # 0xe4c0
movq 0xa2c3(%rip), %rsi      # 0xe458
movq 0xa2a4(%rip), %rdx      # 0xe440
movl -0x48(%rbp), %ecx
addl $0x2, %ecx
movl 0xa02b(%rip), %r8d      # 0xe1d4
movl 0xa014(%rip), %r9d      # 0xe1c4
movl 0xa012(%rip), %eax      # 0xe1c8
movl %eax, (%rsp)
callq 0x2de0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
movq 0xa2f5(%rip), %rsi      # 0xe4c0
movq 0xa286(%rip), %rdx      # 0xe458
movq 0xa267(%rip), %rcx      # 0xe440
movl 0x9fe4(%rip), %r8d      # 0xe1c4
movl 0x9fe1(%rip), %r9d      # 0xe1c8
callq 0x28e0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x6, %eax
movl %eax, -0x2c(%rbp)
movq 0xa2a9(%rip), %rdi      # 0xe4a8
movl -0x48(%rbp), %eax
addl $0x1, %eax
imull $0x6, %eax, %esi
movl $0x6, %edx
callq 0x25d0
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x38(%rbp), %ecx
movl -0x2c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq 0xa26e(%rip), %rdi      # 0xe498
movq -0x20(%rbp), %rsi
movl -0x38(%rbp), %edx
movl 0xa058(%rip), %r8d      # 0xe290
movl -0x34(%rbp), %r9d
subl $0x1, %r9d
movl -0x10(%rbp), %r11d
subl $0x1, %r11d
movl -0x28(%rbp), %r10d
subl $0x1, %r10d
movl -0x2c(%rbp), %eax
xorl %ecx, %ecx
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x3c60
movl %eax, -0x30(%rbp)
cmpl $0x2, -0x30(%rbp)
jne 0x4336
movq 0xa245(%rip), %rdi      # 0xe4c0
movq 0xa1d6(%rip), %rsi      # 0xe458
movq 0xa1b7(%rip), %rdx      # 0xe440
movl -0x48(%rbp), %ecx
addl $0x2, %ecx
movl 0x9f3e(%rip), %r8d      # 0xe1d4
movl 0x9f27(%rip), %r9d      # 0xe1c4
movl 0x9f25(%rip), %eax      # 0xe1c8
movl %eax, (%rsp)
callq 0x2de0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
movq 0xa208(%rip), %rsi      # 0xe4c0
movq 0xa199(%rip), %rdx      # 0xe458
movq 0xa17a(%rip), %rcx      # 0xe440
movl 0x9ef7(%rip), %r8d      # 0xe1c4
movl 0x9ef4(%rip), %r9d      # 0xe1c8
callq 0x28e0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shll $0x6, %eax
movl %eax, -0x2c(%rbp)
movq 0xa1bc(%rip), %rdi      # 0xe4a8
movl -0x48(%rbp), %eax
addl $0x1, %eax
imull $0x6, %eax, %esi
movl $0x6, %edx
callq 0x25d0
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x38(%rbp), %ecx
addl 0x9f7f(%rip), %ecx      # 0xe290
cmpl %ecx, %eax
jle 0x431c
movl $0x1, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl -0x38(%rbp), %ecx
addl 0x9f68(%rip), %ecx      # 0xe290
cmpl %ecx, %eax
jg 0x4334
movl -0x48(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x4375
jmp 0x4336
cmpl $0x0, -0x30(%rbp)
jne 0x4342
movl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0x434e
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
subl -0x3c(%rbp), %eax
cmpl $0x2, %eax
jge 0x4370
leaq 0x6dae(%rip), %rdi      # 0xb10e
movb $0x0, %al
callq 0x2030
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
jmp 0x4375
jmp 0x40b8
cmpl $-0x1, -0x48(%rbp)
jne 0x4385
movl $0x6, %edi
callq 0x21e0
movl -0x48(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop