// File: TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: findB(int*, int, int, int, int*, int*, int*, int*, int*, int*)
int findB(int *m,int startm,int mrlen,int round,int *kmpc,int *B1,int *B2,int *B3,int *Ls,int *Rs){ //列からtgを探す
    //Bコアを探す
    if(DEBUGFLAG==1){
        printf("\nAコアがない場合の[");
        for(int i2 = 0;i2<coredata[5];i2++){printf("%d ",m[startm+coredata[4]+i2]);}
        printf("](%d 文字)Bを探す(round %d)\nkmpc = ",mrlen,round);
        for(int i2 = 0;i2<mrlen;i2++){printf("%d ",kmpc[i2]);}
    }
    int len = 0;
    int rofs=0;
    if(round>1){rofs=dc2s[round-1];}
    int bsp[3] = {0,0,0}; //コアが完全一致した時，どこまで戻るか
    int i = 0;
    int tg = 0;
    int ofs = 0;
    int kpofs = 0;
    int y9;
    for(int y8=dc2s[round];y8<dc2s[round+1];y8++){
        //if(DEBUGFLAG==1){printf("\n[%d(%d)]",y8,D_2[y8+1]-D_2[y8]);}
        ofs=0;tg = 0;
        std::vector<int> x;
        xdisp(x,y8);
        for(y9=0;y9<x.size();y9++){
            if(rofs+x[y9]==m[startm+tg]){
                tg++;if(tg==1){kpofs = ofs;} //1文字一致を確認したらオフセットくらいは覚えておく
                if(tg==coredata[5]){
                     if(DEBUGFLAG==1){printf("(Bコア発見[%d文字目(%d)] / %dの(+%d))",y9,tg,y8,ofs);}
                }
                if(tg==mrlen){ //CコアがなければB = Cの発見と同じ.コアはどうせ1つしかないのでそのままbreak
                    //printf("\n(コア発見[%d文字目(%d)] / %d(+%d))",y9-D_2[y8],tg,y8,ofs);
                    bsp[0] = y9; //コアの最後尾の位置
                    bsp[1] = y9+1 - mrlen; //手前に残ってる文字数
                    bsp[2] = x.size()-y9-1; //この先に残ってる文字数
                    break;
                }
            }else{ //不一致
                if(tg!=0){
                    if(y8==279){printf("[kmpc%d->%d]",tg,kmpc[tg]);}
                    if(round==0){kpofs+= (tg - kmpc[tg]);}
                    else{kpofs+=D3access(m[startm])*(tg - kmpc[tg]);}
                    tg = kmpc[tg];y9--;continue;}
                tg=0;
            }
            //printf(" %d",rofs+D[y9]);
            if(round>0){ofs+=D3access(rofs+x[y9]);}else{ofs++;}
        }
        //if(fis>0){printf("(左に右出現[%d文字])",fis);} //先頭から出現
        if(tg==mrlen){ //完全一致して抜けてきたやつ(A・Cコアが確実にない)
                coreans++;
                if(bsp[1]>0){occart2[round][1] = rofs+x[y9-mrlen];}else{occart2[round][1] = -1;}
                if(bsp[1]>1){occart2[round][0] = rofs+x[y9-mrlen-1];}else{occart2[round][0] = -1;}
                occart2[round][2] = y8;
                occart2[round][3] = kpofs-ocofs; //コアとのずれを最初に払っておく
                if(bsp[2]>0){occart2[round][4] = rofs+x[y9+1];}else{occart2[round][4] = -1;}
                if(bsp[2]>1){occart2[round][5] = rofs+x[y9+2];}else{occart2[round][5] = -1;}
                if(bsp[2]>2){occart2[round][6] = rofs+x[y9+3];}else{occart2[round][6] = -1;}
                occart2[round][7] = 3; //ABC全部発見 
                if(DEBUGFLAG==1){
                    printf("\nチェック：");
                    for(int i = 0;i<10;i++){printf("[%d]",occart2[round][i]);}
                }
                findups(m,startm,mrlen,round+1,B1,B2,B3,Ls,Rs,1); //その不完全なコアの出現を探す
        }
        else{
            if(tg==coredata[5]){ //最後にBコアだけ出現
                //printf("\n(右にBコア出現[%d文字] +%d)\n",tg,ofs);
                coreans++;
                if(x.size()>tg+1){occart2[round][0] = rofs+x[x.size()-2-tg];}else{occart2[round][0] = -1;}
                if(x.size()>tg){occart2[round][1] = rofs+x[x.size()-1-tg];}else{occart2[round][1] = -1;}
                occart2[round][2] = y8;
                occart2[round][3] = kpofs-ocofs; //コアとのずれを最初に払っておく
                occart2[round][4] = -1;
                occart2[round][5] = -1;
                occart2[round][6] = -1;
                occart2[round][7] = 1; //Bのみ発見
                if(DEBUGFLAG==1){
                    printf("Bコアのみが最後に出現するタイプ\n");
                    for(int i = 0;i<10;i++){printf("[%d]",occart2[round][i]);}
                }
                findups(m,startm,mrlen,round+1,B1,B2,B3,Ls,Rs,1); //その不完全なコアの出現を探す
            }
        }
    }
    //printf("\nend of searching.(%d)[%d]",len,i);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xd8, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x1, -0x1c(%rbp)
jle 0x716b
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x718b(%rip), %rax      # 0xe2f0
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
leaq -0x44(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x20e0
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x714e(%rip), %rax      # 0xe2f0
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
leaq 0x7135(%rip), %rcx      # 0xe2f0
cmpl (%rcx,%rdx,4), %eax
jge 0x77e7
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x9db0
movq -0x90(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x34c0
jmp 0x71f3
movl $0x0, -0x58(%rbp)
movslq -0x58(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9d90
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x73af
movl -0x38(%rbp), %eax
movl %eax, -0x9c(%rbp)
movslq -0x58(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movq %rax, %rcx
movl -0x9c(%rbp), %eax
addl (%rcx), %eax
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %edx
addl -0x4c(%rbp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x72d0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x1, -0x4c(%rbp)
jne 0x7288
movl -0x50(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x7288
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9df0
jmp 0x77f3
movl -0x4c(%rbp), %eax
cmpl 0xa6f3(%rip), %eax      # 0x11984
jne 0x7295
jmp 0x7295
movl -0x4c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x72cb
movl -0x58(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9d90
movslq -0x58(%rbp), %rcx
subq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x3c(%rbp)
jmp 0x73af
jmp 0x7365
cmpl $0x0, -0x4c(%rbp)
je 0x735e
cmpl $0x117, -0x5c(%rbp)     # imm = 0x117
jne 0x7302
movslq -0x4c(%rbp), %rcx
movl %ecx, %esi
movq -0x28(%rbp), %rax
movl (%rax,%rcx,4), %edx
leaq 0x3ebd(%rip), %rdi      # 0xb1b4
xorl %eax, %eax
callq 0x2030
jmp 0x7300
jmp 0x7302
cmpl $0x0, -0x1c(%rbp)
jne 0x731e
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x7345
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x46f0
movl -0x4c(%rbp), %ecx
movq -0x28(%rbp), %rdx
movslq -0x4c(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
imull %ecx, %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rbp)
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x73a1
movl $0x0, -0x4c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x7396
movl -0x38(%rbp), %eax
movl %eax, -0xa0(%rbp)
movslq -0x58(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xa0(%rbp), %edi
addl (%rax), %edi
callq 0x46f0
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x739f
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x73a1
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x71fa
movl -0x4c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x7619
movl 0x706b(%rip), %eax      # 0xe42c
addl $0x1, %eax
movl %eax, 0x7062(%rip)      # 0xe42c
cmpl $0x0, -0x40(%rbp)
jle 0x740a
movl -0x38(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x58(%rbp), %eax
subl -0x18(%rbp), %eax
movslq %eax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xa4(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0xa0c2(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
jmp 0x7423
movslq -0x1c(%rbp), %rcx
leaq 0xa0ab(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
cmpl $0x1, -0x40(%rbp)
jle 0x7465
movl -0x38(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0x58(%rbp), %eax
subl -0x18(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xa8(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0xa066(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
jmp 0x747d
movslq -0x1c(%rbp), %rcx
leaq 0xa050(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x5c(%rbp), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0xa035(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x54(%rbp), %ecx
subl 0xa502(%rip), %ecx      # 0x119a0
movslq -0x1c(%rbp), %rdx
leaq 0xa017(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
cmpl $0x0, -0x3c(%rbp)
jle 0x74f3
movl -0x38(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xac(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x9fd9(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
jmp 0x750c
movslq -0x1c(%rbp), %rcx
leaq 0x9fc2(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
cmpl $0x1, -0x3c(%rbp)
jle 0x754c
movl -0x38(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0x58(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xb0(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x9f80(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
jmp 0x7565
movslq -0x1c(%rbp), %rcx
leaq 0x9f69(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
cmpl $0x2, -0x3c(%rbp)
jle 0x75a5
movl -0x38(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0x58(%rbp), %eax
addl $0x3, %eax
movslq %eax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xb4(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x9f27(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
jmp 0x75be
movslq -0x1c(%rbp), %rcx
leaq 0x9f10(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movslq -0x1c(%rbp), %rax
leaq (%rax,%rax,4), %rcx
leaq 0x9ef3(%rip), %rax      # 0x114c0
movl $0x3, 0x1c(%rax,%rcx,8)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
incl %ecx
movq -0x30(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %rbx
movq %rsp, %rax
movq %rbx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
movl $0x1, 0x18(%rax)
callq 0x62e0
jmp 0x7614
jmp 0x77d0
movl -0x4c(%rbp), %eax
cmpl 0xa362(%rip), %eax      # 0x11984
jne 0x77ce
movl 0x6dfe(%rip), %eax      # 0xe42c
addl $0x1, %eax
movl %eax, 0x6df5(%rip)      # 0xe42c
leaq -0x78(%rbp), %rdi
callq 0x9d90
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x7695
movl -0x38(%rbp), %eax
movl %eax, -0xb8(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9d90
movq %rax, %rsi
subq $0x2, %rsi
movslq -0x4c(%rbp), %rax
subq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xb8(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x9e36(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
jmp 0x76ad
movslq -0x1c(%rbp), %rcx
leaq 0x9e20(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq -0x78(%rbp), %rdi
callq 0x9d90
movslq -0x4c(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x7707
movl -0x38(%rbp), %eax
movl %eax, -0xbc(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x9d90
movq %rax, %rsi
subq $0x1, %rsi
movslq -0x4c(%rbp), %rax
subq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x9dd0
movl -0xbc(%rbp), %ecx
addl (%rax), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x9dc5(%rip), %rax      # 0x114c0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
jmp 0x7720
movslq -0x1c(%rbp), %rcx
leaq 0x9dae(%rip), %rax      # 0x114c0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movl -0x5c(%rbp), %edx
movslq -0x1c(%rbp), %rax
leaq (%rax,%rax,4), %rcx
leaq 0x9d8e(%rip), %rax      # 0x114c0
movl %edx, 0x8(%rax,%rcx,8)
movl -0x54(%rbp), %edx
movl 0xa261(%rip), %ecx      # 0x119a0
subl %ecx, %edx
movslq -0x1c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl %edx, 0xc(%rax,%rcx,8)
movslq -0x1c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0xffffffff, 0x10(%rax,%rcx,8) # imm = 0xFFFFFFFF
movslq -0x1c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0xffffffff, 0x14(%rax,%rcx,8) # imm = 0xFFFFFFFF
movslq -0x1c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0xffffffff, 0x18(%rax,%rcx,8) # imm = 0xFFFFFFFF
movslq -0x1c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl $0x1, 0x1c(%rax,%rcx,8)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
incl %ecx
movq -0x30(%rbp), %r8
movq 0x10(%rbp), %r9
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %rbx
movq %rsp, %rax
movq %rbx, 0x10(%rax)
movq %r11, 0x8(%rax)
movq %r10, (%rax)
movl $0x1, 0x18(%rax)
callq 0x62e0
jmp 0x77cc
jmp 0x77ce
jmp 0x77d0
leaq -0x78(%rbp), %rdi
callq 0x9df0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x71a8
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x2250
nopl (%rax)