// File: /workspace/github_cpp_makefile_star2_O3/TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: patternmatching1(int*, int, int)
int patternmatching1(int *m,int absm,int fround){
    int startm = 0;
    int mrlen = absm; 
    int round = 0;
    ocofs = 0;
    int *B1,*B2,*B3;
    B1 = (int*)calloc(fround+1,4);
    B2 = (int*)calloc(fround+1,4);
    B3 = (int*)calloc(fround+1,4);
    int Ls[fround+1],Rs[fround+1]; 
    for(int rs=0;rs<fround;rs++){
        int uy = ptrans(B1,B2,B3,Ls,Rs,startm,m,mrlen,round);
        if(uy<0){
            if(uy<-30){return -5;} //if pursing is not found in dictionary, end patternmatching
            break;
        }
        if(round==0){ocofs+=B1[round];}
        if(round>0){for(int i = 0;i<B1[round];i++){ocofs+=D3access(m[startm+i]);/*printf("\n[=%d]",m[startm+i]);*/}}
        startm += B1[round];mrlen = B3[round];round++;}
    if(round!=fround){    
        if(coredata[0]>0){ //Aコアがあるのでその分だけocofsをずらす
            for(int i = 0;i<coredata[2];i++){
                ocofs+=D3access(m[startm+i]);
            }
        }
    }
    transk = round;
    if(DEBUGFLAG==1){printf("rs==%d/%d\n",round,fround);}
    transreco[round]++;
    if(DEBUGFLAG==1){
    for(int i = 0;i<round;i++){
        for(int i2 = 0;i2<B1[i];i2++){
            printf(" %d",m[Ls[i]+i2]);
        }
        printf(" / ");
    }
    printf("(Core)");
    for(int i2 = 0;i2<mrlen;i2++){
            printf(" %d",m[startm+i2]);
    }
    printf(" / ");
    for(int i = round-1;i>=0;i--){
        for(int i2 = 0;i2<B2[i];i2++){
            printf(" %d",m[Rs[i]+i2]);
        }
        printf(" / ");
    }
    printf("\nlength of Core == %d\n",mrlen);
    }
    //fround[一番上]から指定の一文字を探して見る
    timessub = clock();
    int *kmpc = (int*)calloc(mrlen,4);
    mkkmpc(m,startm,mrlen,kmpc);
    //int possibleP = 1;
    if(DEBUGFLAG==1){
        printf("\nocofs = %d",ocofs);
        if(coredata[0]==-1){printf("\nAコア = なし");}
        else{printf("\nAコア = 位置%dから長さ%d",coredata[1],coredata[2]);}
        if(coredata[3]==-1){printf("\nBコア = なし");}
        else{printf("\nBコア = 位置%dから長さ%d",coredata[4],coredata[5]);}
        if(coredata[6]==-1){printf("\nCコア = なし");}
        else{printf("\nCコア = 文字%dが%d個",coredata[7],coredata[8]);}
    }
    if(transk==loops){
        findinNS(m,startm,mrlen,round,kmpc,B1,B2,B3,Ls,Rs);
        printf(" / ans :%d 個 (core : %d個)",ans,coreans);
        return 0;
    }
    if(coredata[0]==-1){
        if(DEBUGFLAG==1){printf("Bルートで検索");}
        findB(m,startm,mrlen,round,kmpc,B1,B2,B3,Ls,Rs);
    }
    else{
        if(DEBUGFLAG==1){printf("Aルートで検索");}
        findAB(m,startm,mrlen,round,kmpc,B1,B2,B3,Ls,Rs);
    }
    printf(" / ans :%d 個 (core : %d個)",ans,coreans);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, -0x38(%rbp)
movl $0x0, 0x9073(%rip)      # 0xe990
leal 0x1(%r12), %ebx
movslq %ebx, %r14
movl $0x4, %esi
movq %r14, %rdi
callq 0x20b0
movq %rax, %r15
movl $0x4, %esi
movq %r14, %rdi
callq 0x20b0
movq %rax, -0x58(%rbp)
movl $0x4, %esi
movq %r14, %rdi
callq 0x20b0
movq %rax, -0x40(%rbp)
movq %rsp, %rcx
leaq 0xf(,%rbx,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
testl %r12d, %r12d
movq %r12, -0x70(%rbp)
jle 0x5a44
movl %r12d, %eax
movq %rax, -0x68(%rbp)
xorl %r14d, %r14d
xorl %r12d, %r12d
movq -0x38(%rbp), %rbx
movq -0x40(%rbp), %rdx
movq %r15, -0x60(%rbp)
subq $0x8, %rsp
movq %r15, %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %r8
movl %r12d, %r9d
pushq %r14
pushq %r13
pushq %rbx
callq 0x3805
addq $0x20, %rsp
testl %eax, %eax
js 0x5a50
movl %r12d, -0x30(%rbp)
testq %r14, %r14
je 0x5a18
movslq (%r15,%r14,4), %r12
testq %r12, %r12
jle 0x5a22
movl 0x8fa8(%rip), %r13d     # 0xe990
movslq -0x30(%rbp), %rax
leaq (%rbx,%rax,4), %rbx
xorl %r15d, %r15d
movl (%rbx,%r15,4), %edi
callq 0x3a9f
addl %eax, %r13d
movl %r13d, 0x8f8a(%rip)     # 0xe990
incq %r15
cmpq %r15, %r12
jne 0x59f3
movq -0x60(%rbp), %r15
movq -0x38(%rbp), %rbx
jmp 0x5a22
movl (%r15), %r12d
addl %r12d, 0x8f6e(%rip)     # 0xe990
addl -0x30(%rbp), %r12d
movq -0x40(%rbp), %rdx
movl (%rdx,%r14,4), %r13d
incq %r14
cmpq -0x68(%rbp), %r14
jne 0x59a3
movq -0x70(%rbp), %r14
jmp 0x5ac6
xorl %r14d, %r14d
xorl %r12d, %r12d
movq -0x38(%rbp), %rbx
jmp 0x5a5e
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
cmpl $-0x1e, %eax
jb 0x5bbf
cmpl -0x70(%rbp), %r14d
je 0x5ac6
cmpl $0x0, 0x8ef5(%rip)      # 0xe960
jle 0x5ac6
movslq 0x8ef4(%rip), %rcx      # 0xe968
testq %rcx, %rcx
jle 0x5ac6
movq %r15, -0x60(%rbp)
movl %r12d, %eax
movl 0x8f09(%rip), %r12d     # 0xe990
movl %eax, -0x30(%rbp)
cltq
leaq (%rbx,%rax,4), %rax
movq %rax, -0x68(%rbp)
xorl %ebx, %ebx
movq -0x68(%rbp), %rax
movl (%rax,%rbx,4), %edi
movq %rcx, %r15
callq 0x3a9f
movq %r15, %rcx
addl %eax, %r12d
movl %r12d, 0x8ede(%rip)     # 0xe990
incq %rbx
cmpq %rbx, %r15
jne 0x5a96
movq -0x38(%rbp), %rbx
movl -0x30(%rbp), %r12d
movq -0x60(%rbp), %r15
movl %r14d, 0x59fb(%rip)     # 0xb4c8
movslq %r14d, %rax
leaq 0x5759(%rip), %rcx      # 0xb230
incl (%rcx,%rax,4)
callq 0x20c0
movq %rax, 0x8ea2(%rip)      # 0xe988
movslq %r13d, %rdi
movq %rdi, -0x30(%rbp)
movl $0x4, %esi
callq 0x20b0
movq %rbx, %rdi
movl %r12d, %esi
movq -0x30(%rbp), %rdx
movq %rax, -0x30(%rbp)
movq %rax, %rcx
callq 0x3adc
movl 0x59b5(%rip), %eax      # 0xb4c8
cmpl 0x5673(%rip), %eax      # 0xb18c
jne 0x5b50
subq $0x20, %rsp
movq -0x48(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x50(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
movq -0x30(%rbp), %r8
movq %r15, %r9
callq 0x4515
jmp 0x5b9f
movq -0x30(%rbp), %r8
cmpl $-0x1, 0x8e05(%rip)     # 0xe960
je 0x5b7f
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
movl %r14d, %ecx
movq %r15, %r9
pushq -0x48(%rbp)
pushq -0x50(%rbp)
pushq -0x40(%rbp)
pushq -0x58(%rbp)
callq 0x51f9
jmp 0x5b9f
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
movl %r14d, %ecx
movq %r15, %r9
pushq -0x48(%rbp)
pushq -0x50(%rbp)
pushq -0x40(%rbp)
pushq -0x58(%rbp)
callq 0x5476
addq $0x20, %rsp
movl 0x586f(%rip), %esi      # 0xb418
movl 0x586d(%rip), %edx      # 0xb41c
leaq 0x25e3(%rip), %rdi      # 0x8199
xorl %eax, %eax
callq 0x2030
xorl %ecx, %ecx
movl %ecx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq