// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movl %edx, %r12d
andl $0x0, 0x8579(%rip)      # 0xd9a0
movq %rsi, -0x58(%rbp)
movq %rdi, -0x70(%rbp)
leal 0x1(%r12), %ebx
movslq %ebx, %r14
pushq $0x4
popq %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x20d0
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x20d0
movq %rax, -0x50(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x20d0
movq %rax, %r14
movq %rsp, %rcx
leaq 0xf(,%rbx,4), %rax
movq -0x58(%rbp), %rbx
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
xorl %r15d, %r15d
testl %r12d, %r12d
movl $0x0, %eax
movq %r12, -0x80(%rbp)
cmovgl %r12d, %eax
movq %rax, -0x78(%rbp)
xorl %r9d, %r9d
movq %r13, -0x68(%rbp)
movq %r14, -0x60(%rbp)
movslq %r9d, %r12
cmpq -0x78(%rbp), %r15
movl %r9d, -0x2c(%rbp)
je 0x555f
subq $0x8, %rsp
movq %r13, %rdi
movq -0x50(%rbp), %rsi
movq %r14, %rdx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
pushq %r15
pushq %rbx
pushq -0x70(%rbp)
callq 0x3527
addq $0x20, %rsp
testl %eax, %eax
js 0x5565
testq %r15, %r15
je 0x553d
movq %r15, -0x38(%rbp)
movl (%r13,%r15,4), %r13d
movl 0x84a0(%rip), %ebx      # 0xd9a0
testl %r13d, %r13d
movl $0x0, %r14d
cmovgl %r13d, %r14d
movq -0x70(%rbp), %rax
leaq (%rax,%r12,4), %r12
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x5533
movl (%r12,%r15,4), %edi
callq 0x3770
addl %eax, %ebx
movl %ebx, 0x8472(%rip)      # 0xd9a0
incq %r15
jmp 0x5518
movq -0x60(%rbp), %r14
movq -0x38(%rbp), %r15
jmp 0x5548
movl (%r13), %r13d
addl %r13d, 0x8458(%rip)     # 0xd9a0
movl (%r14,%r15,4), %ebx
incq %r15
movl -0x2c(%rbp), %r9d
addl %r13d, %r9d
movq -0x68(%rbp), %r13
jmp 0x54b2
movq -0x78(%rbp), %r15
jmp 0x556e
cmpl $-0x1e, %eax
jb 0x5677
movq %rbx, -0x58(%rbp)
movq %r15, -0x38(%rbp)
cmpl -0x80(%rbp), %r15d
movq -0x70(%rbp), %r15
je 0x55c1
cmpl $0x0, 0x83e9(%rip)      # 0xd970
jle 0x55c1
movl 0x83e9(%rip), %eax      # 0xd978
movl 0x840a(%rip), %r13d     # 0xd9a0
xorl %ebx, %ebx
testl %eax, %eax
cmovlel %ebx, %eax
leaq (%r15,%r12,4), %r14
movq %rax, %r12
cmpq %rbx, %r12
je 0x55c1
movl (%r14,%rbx,4), %edi
callq 0x3770
addl %eax, %r13d
movl %r13d, 0x83e4(%rip)     # 0xd9a0
incq %rbx
jmp 0x55a4
movq -0x38(%rbp), %rax
movl %eax, 0x4f0d(%rip)      # 0xa4d8
movl %eax, %eax
leaq 0x4c6c(%rip), %rcx      # 0xa240
incl (%rcx,%rax,4)
callq 0x20e0
movq %rax, 0x83b5(%rip)      # 0xd998
movq -0x58(%rbp), %rbx
movslq %ebx, %rdi
pushq $0x4
popq %rsi
callq 0x20d0
movq %rax, %r12
movq %r15, %rdi
movl -0x2c(%rbp), %r14d
movl %r14d, %esi
movl %ebx, %edx
movq %rax, %rcx
callq 0x37ad
movl 0x4ec9(%rip), %eax      # 0xa4d8
cmpl 0x4b87(%rip), %eax      # 0xa19c
jne 0x564b
subq $0x20, %rsp
movq -0x40(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x48(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x50(%rbp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
movq %r12, %r8
movq -0x68(%rbp), %r9
callq 0x414c
jmp 0x5699
cmpl $-0x1, 0x831e(%rip)     # 0xd970
movq -0x68(%rbp), %r9
movq %r15, %rdi
je 0x567c
movl -0x2c(%rbp), %esi
movl %ebx, %edx
movq -0x38(%rbp), %rcx
pushq -0x40(%rbp)
pushq -0x48(%rbp)
pushq -0x60(%rbp)
pushq -0x50(%rbp)
callq 0x4dae
jmp 0x5699
pushq $-0x5
popq %rbx
jmp 0x56b9
movl -0x2c(%rbp), %esi
movl %ebx, %edx
movq -0x38(%rbp), %rcx
movq %r12, %r8
pushq -0x40(%rbp)
pushq -0x48(%rbp)
pushq -0x60(%rbp)
pushq -0x50(%rbp)
callq 0x500b
addq $0x20, %rsp
movl 0x4d85(%rip), %esi      # 0xa428
movl 0x4d83(%rip), %edx      # 0xa42c
leaq 0x1ae9(%rip), %rdi      # 0x7199
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2030
movl %ebx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq