// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, -0x30(%rbp)
movq %rdi, %rbx
movl $0x0, 0x9024(%rip)      # 0xe990
leal 0x1(%r12), %r14d
movslq %r14d, %r15
movl $0x4, %esi
movq %r15, %rdi
callq 0x20b0
movq %rax, %r13
movl $0x4, %esi
movq %r15, %rdi
callq 0x20b0
movq %rax, -0x60(%rbp)
movl $0x4, %esi
movq %r15, %rdi
callq 0x20b0
movq %rsp, %rcx
leaq 0xf(,%r14,4), %rdx
andq $-0x10, %rdx
subq %rdx, %rcx
movq %rcx, -0x58(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movq %r12, -0x78(%rbp)
testl %r12d, %r12d
movq %rbx, -0x48(%rbp)
movq %rax, -0x68(%rbp)
jle 0x5aec
movq %rax, %r15
xorl %r9d, %r9d
xorl %r14d, %r14d
xorl %r10d, %r10d
movq %r13, %rdi
movq -0x30(%rbp), %r11
movq %r13, -0x70(%rbp)
movq %r11, -0x30(%rbp)
subq $0x8, %rsp
movq %rdi, %r12
movq -0x60(%rbp), %rsi
movq %r15, %rdx
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
movq %r9, -0x38(%rbp)
pushq %r10
pushq %r11
pushq %rbx
movq %r10, %r13
callq 0x38ab
addq $0x20, %rsp
movl %eax, %edx
testl %eax, %eax
js 0x5ab2
movl %edx, -0x30(%rbp)
testl %r13d, %r13d
jne 0x5a3f
movl (%r12), %eax
addl %eax, 0x8f51(%rip)      # 0xe990
movq %r13, -0x40(%rbp)
testl %r13d, %r13d
jle 0x5a89
movl -0x40(%rbp), %eax
movq -0x70(%rbp), %rcx
movslq (%rcx,%rax,4), %rbx
testq %rbx, %rbx
jle 0x5a89
movl 0x8f31(%rip), %r13d     # 0xe990
movslq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,4), %r15
xorl %r12d, %r12d
movl (%r15,%r12,4), %edi
callq 0x3b6f
addl %eax, %r13d
movl %r13d, 0x8f0f(%rip)     # 0xe990
incq %r12
cmpq %r12, %rbx
jne 0x5a6e
movq -0x40(%rbp), %r10
movslq %r10d, %rcx
movq -0x70(%rbp), %rdi
movq -0x38(%rbp), %r9
addl (%rdi,%rcx,4), %r9d
movq -0x68(%rbp), %r15
movl (%r15,%rcx,4), %r11d
incl %r10d
xorl %ecx, %ecx
movq -0x48(%rbp), %rbx
movl -0x30(%rbp), %edx
jmp 0x5aca
xorl %ecx, %ecx
cmpl $-0x1e, %edx
setge %cl
incl %ecx
movq -0x38(%rbp), %r9
movq %r13, %r10
movq %r12, %rdi
movq -0x30(%rbp), %r11
testl %edx, %edx
js 0x5ae0
incl %r14d
cmpl -0x78(%rbp), %r14d
jne 0x59f4
movl $0x2, %ecx
movq %r11, -0x30(%rbp)
cmpl $0x2, %ecx
sete %cl
jmp 0x5af7
movb $0x1, %cl
xorl %r10d, %r10d
xorl %r9d, %r9d
movq %r13, %rdi
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
testb %cl, %cl
je 0x5c62
movq %rdi, %r13
movq %r9, -0x38(%rbp)
movq %r10, -0x40(%rbp)
cmpl -0x78(%rbp), %r10d
je 0x5b59
cmpl $0x0, 0x8e43(%rip)      # 0xe960
jle 0x5b59
movslq 0x8e42(%rip), %r14      # 0xe968
testq %r14, %r14
jle 0x5b59
movl 0x8e5f(%rip), %ebx      # 0xe990
movslq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
leaq (%rcx,%rax,4), %r12
xorl %r15d, %r15d
movl (%r12,%r15,4), %edi
callq 0x3b6f
addl %eax, %ebx
movl %ebx, 0x8e3f(%rip)      # 0xe990
incq %r15
cmpq %r15, %r14
jne 0x5b40
movq -0x40(%rbp), %rax
movl %eax, 0x5965(%rip)      # 0xb4c8
cltq
leaq 0x56c4(%rip), %rcx      # 0xb230
incl (%rcx,%rax,4)
callq 0x20c0
movq %rax, 0x8e0d(%rip)      # 0xe988
movq -0x30(%rbp), %r14
movslq %r14d, %r12
movl $0x4, %esi
movq %r12, %rdi
callq 0x20b0
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq -0x38(%rbp), %r15
movl %r15d, %esi
movl %r12d, %edx
movq %rax, %r12
movq %rax, %rcx
callq 0x3bac
movl 0x5917(%rip), %eax      # 0xb4c8
cmpl 0x55d5(%rip), %eax      # 0xb18c
jne 0x5bed
subq $0x20, %rsp
movq -0x50(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x58(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x60(%rbp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
movq %r12, %r8
movq %r13, %r9
callq 0x4616
jmp 0x5c41
cmpl $-0x1, 0x8d6c(%rip)     # 0xe960
je 0x5c1b
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq %r13, %r9
pushq -0x50(%rbp)
pushq -0x58(%rbp)
pushq -0x68(%rbp)
pushq -0x60(%rbp)
callq 0x529b
jmp 0x5c41
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq %r12, %r8
movq %r13, %r9
pushq -0x50(%rbp)
pushq -0x58(%rbp)
pushq -0x68(%rbp)
pushq -0x60(%rbp)
callq 0x552a
addq $0x20, %rsp
movl 0x57cd(%rip), %esi      # 0xb418
movl 0x57cb(%rip), %edx      # 0xb41c
leaq 0x2511(%rip), %rdi      # 0x8169
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x2030
movl %r12d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq