// File: /workspace/github_cpp_makefile_star2_O3/TooruAkagi[P]GCIS_Index/gcis_nep_locate.cpp
// Function: findB(unsigned int*, int*, int*, int, int, int, int*, int*, int*, int*, int*, int*)
int findB(unsigned int *D,int *D_2,int *D_3,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;
        for(y9=D_2[y8];y9<D_2[y8+1];y9++){
            if(rofs+D[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-D_2[y8],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-D_2[y8]+1 - mrlen; //手前に残ってる文字数
                    bsp[2] = D_2[y8+1]-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+=D_3[m[startm]]*(tg - kmpc[tg]);}
                    tg = kmpc[tg];y9--;continue;}
                tg=0;
            }
            //printf(" %d",rofs+D[y9]);
            if(round>0){ofs+=D_3[rofs+D[y9]];}else{ofs++;}
        }
        //if(fis>0){printf("(左に右出現[%d文字])",fis);} //先頭から出現
        if(tg==mrlen){ //完全一致して抜けてきたやつ(A・Cコアが確実にない)
                coreans++;
                if(bsp[1]>0){occart2[round][1] = rofs+D[y9-mrlen];}else{occart2[round][1] = -1;}
                if(bsp[1]>1){occart2[round][0] = rofs+D[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+D[y9+1];}else{occart2[round][4] = -1;}
                if(bsp[2]>1){occart2[round][5] = rofs+D[y9+2];}else{occart2[round][5] = -1;}
                if(bsp[2]>2){occart2[round][6] = rofs+D[y9+3];}else{occart2[round][6] = -1;}
                occart2[round][7] = 3; //ABC全部発見 
                //transk==0なら，findinroundに行っても良いはず
                if(DEBUGFLAG==1){
                    printf("\nチェック：");
                    for(int i = 0;i<10;i++){printf("[%d]",occart2[round][i]);}
                }
                findups(D,D_2,D_3,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(D_2[y8+1]-D_2[y8]>tg+1){occart2[round][0] = rofs+D[D_2[y8+1]-2-tg];}else{occart2[round][0] = -1;}
                if(D_2[y8+1]-D_2[y8]>tg){occart2[round][1] = rofs+D[D_2[y8+1]-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(D,D_2,D_3,startm,mrlen,round+1,B1,B2,B3,Ls,Rs,1); //その不完全なコアの出現を探す
            }
        }
    }
    //printf("\nend of searching.(%d)[%d]",len,i);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r13
xorl %ebx, %ebx
leaq 0x7197(%rip), %rsi      # 0xa6a0
cmpl $0x2, %r9d
jl 0x3516
leal -0x1(%r9), %eax
movl (%rsi,%rax,4), %ebx
movslq %r9d, %r14
movslq (%rsi,%r14,4), %rdi
cmpl 0x4(%rsi,%r14,4), %edi
jge 0x38e9
movslq %ecx, %rax
movq %rax, 0x60(%rsp)
leaq (%r14,%r14,4), %rax
incq %r14
leaq 0x6c32(%rip), %rsi      # 0xa170
leaq (%rsi,%rax,8), %rax
movq %rax, 0x38(%rsp)
movl %r8d, %eax
notl %eax
movq %rax, 0x58(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
movl $0x0, 0x10(%rsp)
movq %r9, 0x50(%rsp)
movl %r8d, 0x14(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movl %ebx, 0x34(%rsp)
movq %r14, 0x18(%rsp)
movq 0x8(%rsp), %rax
movl (%rax,%rdi,4), %r14d
movl 0x4(%rax,%rdi,4), %r11d
movq %rdi, 0x20(%rsp)
leaq 0x1(%rdi), %rax
movq %rax, 0x28(%rsp)
cmpl %r11d, %r14d
jge 0x36a0
xorl %r15d, %r15d
movq 0x7161(%rip), %rax      # 0xa710
xorl %r12d, %r12d
movslq %r14d, %rsi
movl (%r13,%rsi,4), %esi
addl %ebx, %esi
leal (%r12,%rcx), %edi
movslq %edi, %rdi
cmpl (%rax,%rdi,4), %esi
jne 0x35de
leal 0x1(%r12), %r10d
testl %r12d, %r12d
cmovel %r15d, %ebp
cmpl %r8d, %r10d
jne 0x3653
jmp 0x3772
testl %r12d, %r12d
je 0x3650
movq %r13, %rbx
movslq %r12d, %r13
cmpq $0x117, 0x20(%rsp)      # imm = 0x117
jne 0x362c
movq 0xa0(%rsp), %rax
movl (%rax,%r13,4), %edx
leaq 0x2b1f(%rip), %rdi      # 0x6126
movl %r12d, %esi
xorl %eax, %eax
callq 0x1030
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movl 0x14(%rsp), %r8d
movq 0x50(%rsp), %r9
movq 0x70e4(%rip), %rax      # 0xa710
testl %r9d, %r9d
je 0x3665
movq 0x60(%rsp), %rsi
movslq (%rax,%rsi,4), %rsi
movq 0xa0(%rsp), %rdi
movl (%rdi,%r13,4), %r10d
subl %r10d, %r12d
imull (%rdx,%rsi,4), %r12d
jmp 0x3674
xorl %r10d, %r10d
testl %r9d, %r9d
jle 0x3660
movl %esi, %esi
addl (%rdx,%rsi,4), %r15d
jmp 0x368f
incl %r15d
jmp 0x368f
movq 0xa0(%rsp), %rsi
movl (%rsi,%r13,4), %r10d
subl %r10d, %r12d
addl %r12d, %ebp
decl %r14d
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rdi
movl (%rsi,%rdi,4), %r11d
movq %rbx, %r13
movl 0x34(%rsp), %ebx
incl %r14d
movl %r10d, %r12d
cmpl %r11d, %r14d
jl 0x35b2
jmp 0x36a3
xorl %r10d, %r10d
cmpl %r8d, %r10d
jne 0x36bb
movl 0x10(%rsp), %edi
movl 0x4(%rsp), %r9d
movq 0x20(%rsp), %rsi
jmp 0x3795
cmpl 0x6f72(%rip), %r10d     # 0xa634
movq 0x20(%rsp), %r15
jne 0x3768
incl 0x7019(%rip)            # 0xa6ec
movq 0x8(%rsp), %rax
movq 0x28(%rsp), %rsi
movl (%rax,%rsi,4), %r11d
movl %r11d, %edi
subl (%rax,%r15,4), %edi
leal 0x1(%r10), %r9d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpl %r9d, %edi
movq 0x18(%rsp), %r14
jle 0x3711
subl %r10d, %r11d
addl $-0x2, %r11d
movslq %r11d, %rsi
movl (%r13,%rsi,4), %esi
addl %ebx, %esi
movq 0x38(%rsp), %r11
movl %esi, (%r11)
movq 0x8(%rsp), %r9
movq 0x28(%rsp), %rsi
movl (%r9,%rsi,4), %edi
movl %edi, %esi
subl (%r9,%r15,4), %esi
cmpl %r10d, %esi
jle 0x3742
notl %r10d
addl %r10d, %edi
movslq %edi, %rax
movl (%r13,%rax,4), %eax
addl %ebx, %eax
movl %eax, 0x4(%r11)
movl %r15d, 0x8(%r11)
movl %ebp, %eax
subl 0x6fba(%rip), %eax      # 0xa70c
movl %eax, 0xc(%r11)
movq $-0x1, 0x10(%r11)
movl $0x1, %eax
jmp 0x3864
movq 0x18(%rsp), %r14
jmp 0x38be
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rsi
movl (%rax,%rsi,4), %eax
addl %r8d, %eax
negl %eax
leal (%r14,%rax), %edi
incl %edi
movl %r14d, %eax
notl %eax
addl %eax, %r11d
movl %r11d, %r9d
incl 0x6f51(%rip)            # 0xa6ec
testl %edi, %edi
movq 0x38(%rsp), %r11
jle 0x37c8
movl %r14d, %eax
subl %r8d, %eax
cltq
movl (%r13,%rax,4), %eax
addl %ebx, %eax
movl %eax, 0x4(%r11)
cmpl $0x1, %edi
jne 0x37d7
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %edi
jmp 0x37e8
movl $0xffffffff, 0x4(%r11)  # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x37e8
movq 0x58(%rsp), %rax
addl %r14d, %eax
cltq
movl (%r13,%rax,4), %eax
addl %ebx, %eax
movl %eax, (%r11)
movl %esi, 0x8(%r11)
movl %ebp, %eax
subl 0x6f15(%rip), %eax      # 0xa70c
movl %eax, 0xc(%r11)
testl %r9d, %r9d
movl %edi, 0x10(%rsp)
jle 0x3845
movslq %r14d, %rsi
movl 0x4(%r13,%rsi,4), %eax
addl %ebx, %eax
movl %eax, 0x10(%r11)
cmpl $0x1, %r9d
movq 0x18(%rsp), %r14
je 0x3852
movl 0x8(%r13,%rsi,4), %eax
addl %ebx, %eax
movl %eax, 0x14(%r11)
movl $0x3, %eax
cmpl $0x3, %r9d
jb 0x38dc
movl %r9d, 0x4(%rsp)
movl 0xc(%r13,%rsi,4), %esi
addl %ebx, %esi
jmp 0x3869
movl $0xffffffff, 0x10(%r11) # imm = 0xFFFFFFFF
movq 0x18(%rsp), %r14
movl %r9d, 0x4(%rsp)
movl $0xffffffff, 0x14(%r11) # imm = 0xFFFFFFFF
movl $0x3, %eax
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, 0x18(%r11)
movl %eax, 0x1c(%r11)
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movl %r14d, %r9d
pushq $0x1
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
callq 0x2c37
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl 0x44(%rsp), %r8d
addq $0x30, %rsp
movq 0x50(%rsp), %r9
leaq 0x6ddb(%rip), %rax      # 0xa6a0
movslq (%rax,%r14,4), %rax
movq 0x28(%rsp), %rsi
movq %rsi, %rdi
cmpq %rax, %rsi
jl 0x3580
jmp 0x38e9
movl $0x2, 0x4(%rsp)
jmp 0x3864
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq