// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %r10
movq %rdi, %r12
movl $0x0, (%rsp)
leaq 0x6fcf(%rip), %r14      # 0xa6a0
cmpl $0x2, %r9d
jl 0x36e2
leal -0x1(%r9), %eax
movl (%r14,%rax,4), %eax
movl %eax, (%rsp)
movslq %r9d, %r15
movslq (%r14,%r15,4), %rdi
cmpl 0x4(%r14,%r15,4), %edi
jge 0x3a7f
movslq %ecx, %rax
movq %rax, 0x60(%rsp)
leaq (%r15,%r15,4), %rax
incq %r15
leaq 0x6a66(%rip), %rdx      # 0xa170
leaq (%rdx,%rax,8), %rbp
leaq (%rdx,%rax,8), %rax
addq $0x4, %rax
movq %rax, 0x10(%rsp)
movl %r8d, %eax
notl %eax
movq %rax, 0x58(%rsp)
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
movq %r9, 0x50(%rsp)
movl %r8d, 0xc(%rsp)
movq %rcx, 0x48(%rsp)
movq %r10, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq %rbp, 0x28(%rsp)
movq %rdi, %rax
movl (%rsi,%rdi,4), %r13d
movl 0x4(%rsi,%rdi,4), %edi
movq %rax, 0x18(%rsp)
incq %rax
movq %rax, 0x20(%rsp)
cmpl %edi, %r13d
jge 0x387b
xorl %ebp, %ebp
xorl %r15d, %r15d
movl (%rsp), %r14d
movslq %r13d, %rax
movl (%r12,%rax,4), %edx
addl %r14d, %edx
movq 0x6f7b(%rip), %rax      # 0xa710
leal (%r15,%rcx), %r11d
movslq %r11d, %r11
cmpl (%rax,%r11,4), %edx
jne 0x37ba
leal 0x1(%r15), %eax
testl %r15d, %r15d
cmovel %ebp, %ebx
cmpl %r8d, %eax
je 0x387f
movl %eax, %r15d
jmp 0x3834
testl %r15d, %r15d
je 0x3831
movq %r12, %r14
movslq %r15d, %r12
cmpq $0x117, 0x18(%rsp)      # imm = 0x117
jne 0x3806
movq 0xa0(%rsp), %rax
movl (%rax,%r12,4), %edx
leaq 0x294b(%rip), %rdi      # 0x612e
movl %r15d, %esi
xorl %eax, %eax
callq 0x1030
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %r10
movq 0x48(%rsp), %rcx
movl 0xc(%rsp), %r8d
movq 0x50(%rsp), %r9
testl %r9d, %r9d
je 0x3845
movq 0x6efe(%rip), %rax      # 0xa710
movq 0x60(%rsp), %rdx
movslq (%rax,%rdx,4), %rax
movq 0xa0(%rsp), %rdx
subl (%rdx,%r12,4), %r15d
imull (%r10,%rax,4), %r15d
movq %rdx, %rax
jmp 0x3851
xorl %r15d, %r15d
testl %r9d, %r9d
jle 0x3841
movl %edx, %eax
addl (%r10,%rax,4), %ebp
jmp 0x3862
incl %ebp
jmp 0x3862
movq 0xa0(%rsp), %rax
subl (%rax,%r12,4), %r15d
addl %r15d, %ebx
movl (%rax,%r12,4), %r15d
decl %r13d
movq %r14, %r12
movl (%rsp), %r14d
incl %r13d
movq 0x20(%rsp), %rax
movl (%rsi,%rax,4), %edi
cmpl %edi, %r13d
jl 0x3784
movl %r15d, %eax
jmp 0x38a0
xorl %eax, %eax
jmp 0x38b1
movq 0x18(%rsp), %rdx
movl (%rsi,%rdx,4), %edx
addl %r8d, %edx
negl %edx
addl %r13d, %edx
incl %edx
movl %edx, 0x8(%rsp)
movl %r13d, %edx
notl %edx
addl %edx, %edi
movl %edi, 0x4(%rsp)
leaq 0x6df9(%rip), %r14      # 0xa6a0
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %rbp
cmpl %r8d, %eax
jne 0x38db
incl 0x6e30(%rip)            # 0xa6ec
cmpl $0x0, 0x8(%rsp)
jle 0x3924
movl %r13d, %eax
subl %r8d, %eax
cltq
movl (%r12,%rax,4), %eax
addl (%rsp), %eax
movq 0x10(%rsp), %rdx
movl %eax, (%rdx)
jmp 0x392f
cmpl 0x6d53(%rip), %eax      # 0xa634
jne 0x3a6a
incl 0x6dff(%rip)            # 0xa6ec
movq 0x20(%rsp), %rdx
movl (%rsi,%rdx,4), %edi
movl %edi, %edx
movq 0x18(%rsp), %r9
subl (%rsi,%r9,4), %edx
leal 0x1(%rax), %r8d
cmpl %r8d, %edx
jle 0x39c0
subl %eax, %edi
addl $-0x2, %edi
movslq %edi, %rdx
movl (%r12,%rdx,4), %edx
addl (%rsp), %edx
movl %edx, (%rbp)
jmp 0x39c7
movq 0x10(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl 0x4(%rsp), %edi
cmpl $0x2, 0x8(%rsp)
jl 0x3950
movq 0x58(%rsp), %rax
addl %r13d, %eax
cltq
movl (%r12,%rax,4), %eax
addl (%rsp), %eax
movl %eax, (%rbp)
jmp 0x3957
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
movl %ebx, %eax
subl 0x6dad(%rip), %eax      # 0xa70c
movq 0x18(%rsp), %rdx
movl %edx, 0x8(%rbp)
movl %eax, 0xc(%rbp)
movslq %r13d, %rax
testl %edi, %edi
jle 0x397e
movl 0x4(%r12,%rax,4), %edx
addl (%rsp), %edx
movl %edx, 0x10(%rbp)
jmp 0x3985
movl $0xffffffff, 0x10(%rbp) # imm = 0xFFFFFFFF
cmpl $0x2, %edi
jl 0x3997
movl 0x8(%r12,%rax,4), %edx
addl (%rsp), %edx
movl %edx, 0x14(%rbp)
jmp 0x399e
movl $0xffffffff, 0x14(%rbp) # imm = 0xFFFFFFFF
cmpl $0x3, %edi
jl 0x39b0
movl 0xc(%r12,%rax,4), %eax
addl (%rsp), %eax
movl %eax, 0x18(%rbp)
jmp 0x39b7
movl $0xffffffff, 0x18(%rbp) # imm = 0xFFFFFFFF
movl $0x3, 0x1c(%rbp)
jmp 0x3a15
movl $0xffffffff, (%rbp)     # imm = 0xFFFFFFFF
movq 0x20(%rsp), %rdx
movl (%rsi,%rdx,4), %edi
movl %edi, %edx
subl (%rsi,%r9,4), %edx
cmpl %eax, %edx
jle 0x39f0
notl %eax
addl %eax, %edi
movslq %edi, %rax
movl (%r12,%rax,4), %eax
addl (%rsp), %eax
movq 0x10(%rsp), %rdx
movl %eax, (%rdx)
jmp 0x39fb
movq 0x10(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl %r9d, 0x8(%rbp)
movl %ebx, %eax
subl 0x6d05(%rip), %eax      # 0xa70c
movl %eax, 0xc(%rbp)
movaps 0x260f(%rip), %xmm0     # 0x6020
movups %xmm0, 0x10(%rbp)
movq %r12, %rdi
movq %r10, %rdx
movl 0xc(%rsp), %r8d
movl %r15d, %r9d
pushq $0x1
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
pushq 0xd0(%rsp)
callq 0x2e6e
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %r10
movq 0x78(%rsp), %rcx
movl 0x3c(%rsp), %r8d
addq $0x30, %rsp
movq 0x50(%rsp), %r9
movslq (%r14,%r15,4), %rax
movq 0x20(%rsp), %rdx
movq %rdx, %rdi
cmpq %rax, %rdx
jl 0x375a
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq