// File: /workspace/github_cpp_makefile_star2_O3/TooruAkagi[P]GCIS_Index/gcis_nep_locate.cpp
// Function: patternmatching2(unsigned int*, int*, int*, int)
int patternmatching2(unsigned int *D,int *D_2,int *D_3,int absm){
    //alldr(D,D_2,D_3,1188,0);
    //alldr(D,D_2,D_3,1427,0);
    ans = 0;coreans = 0;ocofs = 0; //the difference of Core occurance and pattern occurance
    int startm = 0;int mrlen = absm; int round = 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]; //array of length O(log m) * 5
    
    for(int rs=0;rs<fround;rs++){
        if(DEBUGFLAG==1){printf("\nocofs = %d",ocofs);}
        int uy = ptrans(D,D_2,B1,B2,B3,Ls,Rs,startm,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+=D_3[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+=D_3[m[startm+i]];
                if(DEBUGFLAG==1){
                    printf("\n[A]ocofs+=%d(%d)",D_3[m[startm+i]],ocofs);
                }
            }
        }
    }
    int leftof = 0; //leftofはコアの出現位置とパターンの出現位置のずれを修正する
    transk = round;
    printf("パターン変形回数:%d\n",transk);
    if(DEBUGFLAG==1){
        printf("rs==%d/%d\n",round,fround);
        for(int i = 0;i<round;i++){
            for(int i2 = 0;i2<B1[i];i2++){printf(" %d",m[Ls[i]+i2]);}
            int y7 = pscheck(D,D_2,Ls[i],B1[i],i);
            if(y7>=0){printf("([%d]",y7);for(int i2 = D_2[y7];i2<D_2[y7+1];i2++){printf(" %d",D[i2]);}printf("にある)");}
            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]);}
            int y7 = pscheck(D,D_2,Rs[i],B2[i],i);
            if(y7>=0){printf("([%d]",y7);for(int i2 = D_2[y7];i2<D_2[y7+1];i2++){printf(" %d",D[i2]);}printf("にある)");}
            printf(" / ");
        }
    }
// --------------------------------------
    //fround[一番上]から指定の一文字を探して見る
    timessub = clock();
    int *kmpc = (int*)calloc(mrlen,4);
    mkkmpc(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(CHECKFLAG==2){return 0;}
    if(transk==fround){
        findinNS(D,D_2,D_3,startm,mrlen,round,kmpc,B1,B2,B3,Ls,Rs);
        return 0;
    }
    if(coredata[0]==-1){
        if(DEBUGFLAG==1){printf("Bルートで検索");}
        findB(D,D_2,D_3,startm,mrlen,round,kmpc,B1,B2,B3,Ls,Rs);
    }
    else{
        if(DEBUGFLAG==1){printf("Aルートで検索");}
        findAB(D,D_2,D_3,startm,mrlen,round,kmpc,B1,B2,B3,Ls,Rs);
    }
    //int bgp = pscheckb(D,D_2,startm+possibleP,mrlen-possibleP,round);
    //int smp = pschecks(D,D_2,startm+possibleP,mrlen-possibleP,round);
    //findinroundで発見した後分割に，smpより大きくbgpより小さい分割が続いているものを
    //一つ上のroundで検索する
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %r12d
movq %rdx, %rbx
movq %rsi, -0x58(%rbp)
movq %rdi, -0x50(%rbp)
xorl %eax, %eax
movl %eax, 0x6b53(%rip)      # 0xa6f0
movl %eax, 0x6b49(%rip)      # 0xa6ec
movl %eax, 0x6b63(%rip)      # 0xa70c
movslq 0x6b78(%rip), %r14      # 0xa728
leaq 0x1(%r14), %r13
movl $0x4, %esi
movq %r13, %rdi
callq 0x1080
movq %rax, -0x30(%rbp)
movl $0x4, %esi
movq %r13, %rdi
callq 0x1080
movq %rax, -0x48(%rbp)
movl $0x4, %esi
movq %r13, %rdi
callq 0x1080
movl %r13d, %ecx
movq %rsp, %rdx
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rdx
movq %rdx, -0x40(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0x38(%rbp)
movq %rdx, %rsp
testq %r14, %r14
jle 0x3ccd
xorl %r10d, %r10d
xorl %r15d, %r15d
movq %r12, %r11
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq %rax, %r12
movq %rax, %r8
movq -0x40(%rbp), %r9
pushq %r10
pushq %r11
pushq %r15
pushq -0x38(%rbp)
movq %r10, %r14
movq %r11, %r13
callq 0x1869
addq $0x20, %rsp
testl %eax, %eax
js 0x3cd8
testq %r14, %r14
movq %r14, %r10
je 0x3c9d
movq -0x30(%rbp), %rax
movslq (%rax,%r10,4), %r13
testq %r13, %r13
movq %r12, %rax
jle 0x3cae
movl 0x6a96(%rip), %edi      # 0xa70c
movslq %r15d, %rcx
shlq $0x2, %rcx
addq 0x6a8c(%rip), %rcx      # 0xa710
xorl %edx, %edx
movslq (%rcx,%rdx,4), %rsi
addl (%rbx,%rsi,4), %edi
movl %edi, 0x6a79(%rip)      # 0xa70c
incq %rdx
cmpq %rdx, %r13
jne 0x3c86
jmp 0x3cae
movq -0x30(%rbp), %rax
movl (%rax), %r13d
addl %r13d, 0x6a61(%rip)     # 0xa70c
movq %r12, %rax
addl %r15d, %r13d
movl (%rax,%r10,4), %r11d
incq %r10
movl 0x6a69(%rip), %r14d     # 0xa728
movl %r13d, %r15d
cmpl %r10d, %r14d
jg 0x3c1e
jmp 0x3cf9
xorl %r13d, %r13d
xorl %r10d, %r10d
movq %r12, %r11
jmp 0x3cf9
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
cmpl $-0x1e, %eax
jb 0x3e71
movq %r13, %r11
movq %r14, %r10
movl 0x6a35(%rip), %r14d     # 0xa728
movl %r15d, %r13d
movq %r12, %rax
movq %r11, -0x60(%rbp)
movq %rax, -0x70(%rbp)
cmpl %r14d, %r10d
je 0x3d46
cmpl $0x0, 0x6913(%rip)      # 0xa620
jle 0x3d46
movslq 0x6912(%rip), %rax      # 0xa628
testq %rax, %rax
jle 0x3d46
movl 0x69eb(%rip), %ecx      # 0xa70c
movslq %r13d, %rdx
shlq $0x2, %rdx
addq 0x69e1(%rip), %rdx      # 0xa710
xorl %esi, %esi
movslq (%rdx,%rsi,4), %rdi
addl (%rbx,%rdi,4), %ecx
movl %ecx, 0x69ce(%rip)      # 0xa70c
incq %rsi
cmpq %rsi, %rax
jne 0x3d31
movl %r10d, 0x69d7(%rip)     # 0xa724
leaq 0x23df(%rip), %rdi      # 0x6133
movq %r10, -0x68(%rbp)
movl %r10d, %esi
xorl %eax, %eax
callq 0x1030
callq 0x1090
movq %rax, 0x69c2(%rip)      # 0xa730
movq -0x60(%rbp), %r12
movslq %r12d, %r15
movl $0x4, %esi
movq %r15, %rdi
callq 0x1080
movq %rax, %r14
movl %r13d, %edi
movl %r15d, %esi
movq %rax, %rdx
callq 0x1af8
movl 0x698b(%rip), %eax      # 0xa724
cmpl 0x6989(%rip), %eax      # 0xa728
jne 0x3de8
subq $0x30, %rsp
movq -0x38(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x48(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x30(%rbp), %rax
movq %rax, 0x8(%rsp)
movq %r14, (%rsp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x24fb
jmp 0x3e6b
cmpl $-0x1, 0x6831(%rip)     # 0xa620
je 0x3e3f
subq $0x30, %rsp
movq -0x38(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x70(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x48(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x30(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
movl %r13d, %ecx
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %r9
callq 0x3262
jmp 0x3e6b
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
movl %r13d, %ecx
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %r9
pushq -0x38(%rbp)
pushq -0x40(%rbp)
pushq -0x70(%rbp)
pushq -0x48(%rbp)
pushq -0x30(%rbp)
pushq %r14
callq 0x34ea
addq $0x30, %rsp
xorl %ecx, %ecx
movl %ecx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq