// File: 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 %rbx
subq $0x98, %rsp
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, 0xa16c(%rip)      # 0x119a0
movl -0x20(%rbp), %eax
incl %eax
movslq %eax, %rdi
movl $0x4, %esi
movq %rsi, -0x98(%rbp)
callq 0x2100
movq -0x98(%rbp), %rsi
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %eax
incl %eax
movslq %eax, %rdi
callq 0x2100
movq -0x98(%rbp), %rsi
movq %rax, -0x40(%rbp)
movl -0x20(%rbp), %eax
incl %eax
movslq %eax, %rdi
callq 0x2100
movq %rax, -0x48(%rbp)
movl -0x20(%rbp), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x50(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
movl -0x20(%rbp), %eax
incl %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x79ed
movq -0x88(%rbp), %r8
movq -0x90(%rbp), %rcx
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl -0x24(%rbp), %r9d
movq -0x18(%rbp), %r11
movl -0x28(%rbp), %r10d
movl -0x2c(%rbp), %eax
subq $0x20, %rsp
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x4390
addq $0x20, %rsp
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x68(%rbp)
jge 0x794f
cmpl $-0x1e, -0x68(%rbp)
jge 0x794a
movl $0xfffffffb, -0xc(%rbp) # imm = 0xFFFFFFFB
movl $0x1, -0x6c(%rbp)
jmp 0x7be4
jmp 0x79ed
cmpl $0x0, -0x2c(%rbp)
jne 0x796c
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl 0xa03a(%rip), %eax      # 0x119a0
movl %eax, 0xa034(%rip)      # 0x119a0
cmpl $0x0, -0x2c(%rbp)
jle 0x79b7
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
movq -0x38(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x79b5
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl -0x70(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x46f0
addl 0x9ffc(%rip), %eax      # 0x119a0
movl %eax, 0x9ff6(%rip)      # 0x119a0
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x7979
jmp 0x79b7
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x48(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x78d9
movl -0x2c(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x7a40
cmpl $0x0, 0x9f74(%rip)      # 0x11970
jle 0x7a3e
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl 0x9f6a(%rip), %eax      # 0x11978
jge 0x7a3c
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl -0x74(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
callq 0x46f0
addl 0x9f75(%rip), %eax      # 0x119a0
movl %eax, 0x9f6f(%rip)      # 0x119a0
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x7a05
jmp 0x7a3e
jmp 0x7a40
movl -0x2c(%rbp), %eax
movl %eax, 0x6a8f(%rip)      # 0xe4d8
movslq -0x2c(%rbp), %rcx
leaq 0x67ec(%rip), %rax      # 0xe240
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0x67df(%rip), %rax      # 0xe240
movl %edx, (%rax,%rcx,4)
callq 0x2110
movq %rax, 0x9f28(%rip)      # 0x11998
movslq -0x28(%rbp), %rdi
movl $0x4, %esi
callq 0x2100
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movq -0x80(%rbp), %rcx
callq 0x4760
movl 0x6a3d(%rip), %eax      # 0xe4d8
cmpl 0x66fb(%rip), %eax      # 0xe19c
jne 0x7b1b
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %r10
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x80(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x40(%rbp), %rbx
movq -0x48(%rbp), %r11
subq $0x20, %rsp
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x54f0
addq $0x20, %rsp
movl 0x6934(%rip), %esi      # 0xe428
movl 0x6932(%rip), %edx      # 0xe42c
leaq 0x36c0(%rip), %rdi      # 0xb1c1
movb $0x0, %al
callq 0x2030
movl $0x0, -0xc(%rbp)
movl $0x1, -0x6c(%rbp)
jmp 0x7be4
cmpl $-0x1, 0x9e4e(%rip)     # 0x11970
jne 0x7b71
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %r10
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x80(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x40(%rbp), %rbx
movq -0x48(%rbp), %r11
subq $0x20, %rsp
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x7110
addq $0x20, %rsp
jmp 0x7bbc
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %r10
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x80(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x40(%rbp), %rbx
movq -0x48(%rbp), %r11
subq $0x20, %rsp
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x6c10
addq $0x20, %rsp
movl 0x6866(%rip), %esi      # 0xe428
movl 0x6864(%rip), %edx      # 0xe42c
leaq 0x35f2(%rip), %rdi      # 0xb1c1
movb $0x0, %al
callq 0x2030
movl $0x0, -0xc(%rbp)
movl $0x1, -0x6c(%rbp)
movq -0x50(%rbp), %rax
movq %rax, %rsp
movl -0xc(%rbp), %eax
leaq -0x8(%rbp), %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)