// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movl %ecx, %r10d
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x63a0(%rip), %r15      # 0x96a0
movl $0x0, %edi
cmpl $0x2, %r9d
jl 0x3313
leal -0x1(%r9), %eax
movl (%r15,%rax,4), %edi
movslq %r9d, %rax
movslq (%r15,%rax,4), %rcx
movq %rcx, 0x20(%rsp)
leal 0x1(%r9), %ecx
movl %ecx, 0x3c(%rsp)
movslq %ecx, %rcx
movq %rcx, 0x60(%rsp)
movslq %r10d, %rcx
movq %rcx, 0x68(%rsp)
imulq $0x28, %rax, %rax
leaq 0x5e2e(%rip), %rcx      # 0x9170
leaq (%rcx,%rax), %rsi
movq %rsi, 0x40(%rsp)
addq %rcx, %rax
addq $0x4, %rax
movq %rax, 0x30(%rsp)
movl %r8d, %eax
notl %eax
movl %eax, 0x38(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq %r9, 0x58(%rsp)
movl %r8d, 0x14(%rsp)
movq %r10, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movl %edi, 0xc(%rsp)
movq %rbx, 0x70(%rsp)
movq 0x20(%rsp), %rcx
movq 0x60(%rsp), %rax
movslq (%r15,%rax,4), %rax
cmpq %rax, %rcx
jge 0x36c5
movl (%r12,%rcx,4), %r15d
movq %rcx, 0x18(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x20(%rsp), %rax
movl (%r12,%rax,4), %r11d
movslq %r15d, %rax
cmpl %r11d, %r15d
jge 0x34ae
movl (%rbx,%rax,4), %esi
addl %edi, %esi
movq 0x6331(%rip), %rcx      # 0x9710
leal (%r10,%rbp), %edi
movslq %edi, %rdi
cmpl (%rcx,%rdi,4), %esi
jne 0x33fe
leal 0x1(%rbp), %ecx
testl %ebp, %ebp
cmovel %r13d, %r14d
cmpl %r8d, %ecx
jne 0x3472
jmp 0x3558
testl %ebp, %ebp
je 0x3470
movq %r12, %rbx
movslq %ebp, %r12
cmpq $0x117, 0x18(%rsp)      # imm = 0x117
jne 0x3443
movq 0xb0(%rsp), %rax
movl (%rax,%r12,4), %edx
leaq 0x1d00(%rip), %rdi      # 0x5126
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %r10
movl 0x14(%rsp), %r8d
movq 0x58(%rsp), %r9
testl %r9d, %r9d
movl 0xc(%rsp), %edi
je 0x3488
movq 0x62bd(%rip), %rax      # 0x9710
movq 0x68(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
movq 0xb0(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
subl %ecx, %ebp
imull (%rdx,%rax,4), %ebp
jmp 0x3496
xorl %ecx, %ecx
movl 0xc(%rsp), %edi
testl %r9d, %r9d
jle 0x3483
movl %esi, %eax
addl (%rdx,%rax,4), %r13d
jmp 0x34a4
incl %r13d
jmp 0x34a4
movq 0xb0(%rsp), %rax
movl (%rax,%r12,4), %ecx
subl %ecx, %ebp
addl %ebp, %r14d
decl %r15d
movq %rbx, %r12
movq 0x70(%rsp), %rbx
incl %r15d
movl %ecx, %ebp
jmp 0x33be
cmpl %r8d, %ebp
je 0x36b2
cmpl 0x6177(%rip), %ebp      # 0x9634
leaq 0x61dc(%rip), %r15      # 0x96a0
jne 0x3390
incl 0x621c(%rip)            # 0x96ec
movq 0x20(%rsp), %rax
movl (%r12,%rax,4), %eax
movl %eax, %edi
movq 0x18(%rsp), %rcx
subl (%r12,%rcx,4), %edi
leal 0x1(%rbp), %esi
pushq $-0x1
popq %rcx
cmpl %esi, %edi
movl 0xc(%rsp), %edi
jle 0x34fe
subl %ebp, %eax
addl $-0x2, %eax
cltq
movl (%rbx,%rax,4), %ecx
addl %edi, %ecx
movq 0x40(%rsp), %r8
movl %ecx, (%r8)
movq 0x20(%rsp), %rax
movl (%r12,%rax,4), %eax
movl %eax, %esi
movq 0x18(%rsp), %rcx
subl (%r12,%rcx,4), %esi
pushq $-0x1
popq %rcx
cmpl %ebp, %esi
jle 0x352c
notl %ebp
addl %ebp, %eax
cltq
movl (%rbx,%rax,4), %ecx
addl %edi, %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
movl %eax, 0x8(%r8)
movl %r14d, %eax
subl 0x61c7(%rip), %eax      # 0x970c
movl %eax, 0xc(%r8)
orq $-0x1, 0x10(%r8)
pushq $-0x1
popq %rax
pushq $0x1
jmp 0x3639
movq 0x18(%rsp), %r13
movl (%r12,%r13,4), %ecx
addl %r8d, %ecx
negl %ecx
addl %r15d, %ecx
incl %ecx
movl %r15d, %esi
notl %esi
addl %esi, %r11d
movl 0xc(%rsp), %edi
incl 0x616f(%rip)            # 0x96ec
testl %ecx, %ecx
jle 0x35b5
movl %r15d, %esi
subl %r8d, %esi
movslq %esi, %rsi
movl (%rbx,%rsi,4), %esi
addl %edi, %esi
movq 0x30(%rsp), %r8
movl %esi, (%r8)
pushq $0x1
popq %r9
pushq $-0x1
popq %rsi
cmpl $0x1, %ecx
je 0x35c3
addl 0x38(%rsp), %r15d
movslq %r15d, %rsi
movl (%rbx,%rsi,4), %esi
addl %edi, %esi
movl %ecx, %r9d
jmp 0x35c3
movq 0x30(%rsp), %rsi
orl $-0x1, (%rsi)
movl %ecx, %r9d
pushq $-0x1
popq %rsi
movq 0x40(%rsp), %r8
movl %esi, (%r8)
movl %r13d, 0x8(%r8)
movl %r14d, %ecx
subl 0x6134(%rip), %ecx      # 0x970c
movl %ecx, 0xc(%r8)
testl %r11d, %r11d
movl %r9d, 0x2c(%rsp)
jle 0x361e
movl 0x4(%rbx,%rax,4), %ecx
addl %edi, %ecx
movl %ecx, 0x10(%r8)
cmpl $0x1, %r11d
leaq 0x60a5(%rip), %r15      # 0x96a0
je 0x362a
movl 0x8(%rbx,%rax,4), %ecx
addl %edi, %ecx
movl %ecx, 0x14(%r8)
cmpl $0x3, %r11d
jb 0x36a3
movl %r11d, 0x10(%rsp)
movl 0xc(%rbx,%rax,4), %eax
addl %edi, %eax
jmp 0x3637
orl $-0x1, 0x10(%r8)
leaq 0x6076(%rip), %r15      # 0x96a0
movl %r11d, 0x10(%rsp)
orl $-0x1, 0x14(%r8)
pushq $-0x1
popq %rax
pushq $0x3
popq %rcx
movl %eax, 0x18(%r8)
movl %ecx, 0x1c(%r8)
movq %rbx, %rdi
movq %r12, %rsi
movl %r10d, %ecx
movl 0x14(%rsp), %r8d
movl 0x3c(%rsp), %r9d
pushq $0x1
pushq 0xe0(%rsp)
pushq 0xe0(%rsp)
pushq 0xe0(%rsp)
pushq 0xe0(%rsp)
pushq 0xe0(%rsp)
callq 0x2aba
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %r10
movl 0x44(%rsp), %r8d
addq $0x30, %rsp
movq 0x58(%rsp), %r9
movl 0xc(%rsp), %edi
jmp 0x3390
pushq $-0x1
popq %rax
pushq $0x3
popq %rcx
pushq $0x2
popq %rsi
movl %esi, 0x10(%rsp)
jmp 0x363a
movl 0x2c(%rsp), %ecx
movl 0x10(%rsp), %r11d
movq 0x18(%rsp), %r13
jmp 0x3577
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq