// File: /workspace/github_cpp_makefile_star2_O1/TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: findupsintop(int*, int, int, int*, int*, int*, int*, int*, int)
int findupsintop(int *m,int startm,int mrlen,int *B1,int *B2,int *B3,int *Ls,int *Rs,int count){ //一番上の階層まで来てもまだ見つからない例があるなら全力で対処する
    if(DEBUGFLAG==1){
        printf("\nfround(%d)まで到達[%d] / 探すもの[%d]\n",loops,count,occart2[loops-1][2]);
        uhdisp(occart2[loops-1][2]);
        for(int i = 0; i<10; i++){printf("[%d]",occart2[loops-1][i]);}
    }
    int len = 0;
    int tg = occart2[loops-1][2];
    int ofs = occart2[loops-1][3];
    for(int y1 = 0;y1<Sizelist[0];y1++){
        if(len < 82134000 && len>82124000){
            if(DEBUGFLAG==1){
                printf("\n[%d]",y1);
                printf("%d(+%d [%d])",len,D3access(NS[y1]+dc2s[loops-1]),NS[y1]+dc2s[loops-1]);
             }
        }
        if(NS[y1]+dc2s[loops-1]==tg){
            if(DEBUGFLAG==1){printf("\nコア(単独)を発見%d(+%d)",len+ofs,ofs);}
            coreans++;
            for(int i = 0; i<10; i++){occart2[loops][i] = occart2[loops-1][i];} //コアを見つけたら下階層からゲット
            if(DEBUGFLAG==1){
                printf("\n最初 → ");
                for(int i = 0; i<10; i++){printf("[%d]",occart2[loops][i]);}
            }
            if(y1>0 && occart2[loops][0]<0){ //左が埋まっていなくて，かつ左があるなら
                if(occart2[loops][1] == -1){ //2つとも埋まっていないなら
                    occart2[loops][1] = NS[y1-1]+dc2s[loops-1];
                    if(y1>1){occart2[loops][0] = NS[y1-2]+dc2s[loops-1];}
                    if(occart2[loops][7]%2==0){
                        if(coreAcheck(m,loops-1,count,loops,startm)==-1){
                            if(DEBUGFLAG==1){printf("Aコアミスマッチ");}
                            len+= D3access(NS[y1]+dc2s[loops-1]);
                            continue;
                        }
                        else{occart2[loops][7]++;}//1文字は入れたんだから0が帰ってきていればAはもう探し終わっている
                    }
                    else{leftopennd(m,loops-1,count,loops);}
                }
                else{ //1つ埋まっていないなら
                    occart2[loops][0] = NS[y1-1]+dc2s[loops-1];
                    leftopen(m,loops-1,count,loops);
                }
            }
            if(y1<Sizelist[0] && occart2[loops][6]<0){ //右が埋まっていなくて，かつ右があるなら
                if(occart2[loops][5]==-1){ //2文字埋まってないなら
                        if(occart2[loops][4]==-1){ //3文字埋まってないなら
                            occart2[loops][4] = NS[y1+1]+dc2s[loops-1];
                            if(y1+2<Sizelist[0]){occart2[loops][5] = NS[y1+2]+dc2s[loops-1];}
                            if(y1+3<Sizelist[0]){occart2[loops][6] = NS[y1+3]+dc2s[loops-1];}
                            if(occart2[loops][7]/2<1){
                                if(coreCcheck(m,loops-1,count,loops)==-1){
                                    if(DEBUGFLAG==1){printf("\nCコアミスマッチ[top内]");}
                                    len+= D3access(NS[y1]+dc2s[loops-1]);
                                    continue;
                                }
                            } //Cコアがあるなら調べる
                            else{rightopennd3(m,loops-1,count,loops,3);} //3文字count回解体
                        }
                        else{
                            occart2[loops][5] = NS[y1+1]+dc2s[loops-1];
                            if(y1+2<Sizelist[0]){occart2[loops][6] = NS[y1+2]+dc2s[loops-1];}
                            rightopennd3(m,loops-1,count,loops,2);
                        }
                    }
                    else{ //1つだけ
                        occart2[loops][6] = NS[y1+1]+dc2s[loops-1];
                        rightopennd3(m,loops-1,count,loops,1);
                    }
            }
            if(DEBUGFLAG==1){
                printf("\nこうなる → ");
                for(int i = 0; i<10; i++){printf("[%d]",occart2[loops][i]);}
            }
            //occart2[round][6]> -1 && occart2[round][0] > -1 ?
            //printf("\n[早速チェック]");
            int e2[2] = {occart2[loops][1],occart2[loops][0]};
            int tk = rpsck(m,Ls,B1,e2,loops-count-1);
            //if(tk==-1){printf("\nこれはコアではない");}
            if(tk==0){
                int e[3] = {occart2[loops][4],occart2[loops][5],occart2[loops][6]};
                tk = psck(m,Rs,B2,e,loops-count-1);
                    //if(tk==-1){printf("\nこれはコアではない");}
                if(tk==0){ //左右も完璧に合ってた
                    if(DEBUGFLAG==1){printf("答え");}
                    printf(" %d",len+occart2[loops][3]);
                    if(len+occart2[loops][3]==94818246){printf("ここで強制終了\n");exit(0);}
                    if(ans<1000 && CHECKFLAG==1){checkans[ans]=len+occart2[loops][3];}
                    ans++;
                }
            }
            //exit(5);
        }
        len+= D3access(NS[y1]+dc2s[loops-1]);
        //if(len<100){printf("\n[.%d < %d + (%d)%d]",len,D_3[NS[y1]+dc2s[fround-1]],y1,NS[y1]+dc2s[fround-1]);
        //    alldr(D,D_2,D_3,NS[y1]+dc2s[fround-1],fround-1);
        //}
    }
    if(DEBUGFLAG==1){printf("\n[findupsintop 終了]");}
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movl %esi, 0x4(%rsp)
cmpl $0x0, 0x66fc(%rip)      # 0xb1a0
jle 0x4dba
movq %rdi, %r15
movl 0x80(%rsp), %ecx
movslq 0x66d1(%rip), %rax      # 0xb18c
leaq 0x99ee(%rip), %r12      # 0xe4b0
leaq (%rax,%rax,4), %rax
movl -0x20(%r12,%rax,8), %ebx
movl %ecx, %eax
notl %eax
movq %rax, 0x8(%rsp)
leaq 0x6805(%rip), %r13      # 0xb2e0
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x6941(%rip), %rax      # 0xb428
movslq 0x669e(%rip), %rcx      # 0xb18c
movl -0x4(%r13,%rcx,4), %edx
movl (%rax,%r14,4), %esi
addl %edx, %esi
cmpl %ebx, %esi
jne 0x4d89
incl 0x6915(%rip)            # 0xb41c
leaq -0x1(%rcx), %rsi
leaq (%rcx,%rcx,4), %rdi
leaq (%r12,%rdi,8), %r8
movq $-0xa, %r9
movl (%r8,%r9,4), %r10d
movl %r10d, 0x28(%r8,%r9,4)
incq %r9
jne 0x4b1a
testq %r14, %r14
je 0x4bb3
cmpl $0x0, (%r12,%rdi,8)
jns 0x4bb3
movl -0x4(%rax,%r14,4), %r9d
addl %edx, %r9d
cmpl $-0x1, 0x4(%r8)
je 0x4b5b
movl %r9d, (%r8)
movq %r15, %rdi
movl 0x80(%rsp), %edx
callq 0x418b
jmp 0x4bb3
movl %r9d, 0x4(%r8)
cmpq $0x1, %r14
je 0x4b6d
addl -0x8(%rax,%r14,4), %edx
movl %edx, (%r8)
testb $0x1, 0x1c(%r12,%rdi,8)
jne 0x4ba4
movq %r15, %rdi
movl 0x80(%rsp), %edx
movl 0x4(%rsp), %r8d
callq 0x4342
cmpl $-0x1, %eax
je 0x4d89
movslq 0x65f3(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rax
incl 0x1c(%r12,%rax,8)
jmp 0x4bb3
movq %r15, %rdi
movl 0x80(%rsp), %edx
callq 0x4259
movslq 0x65e6(%rip), %rdx      # 0xb1a0
cmpq %rdx, %r14
jge 0x4cbc
movslq 0x65c2(%rip), %rcx      # 0xb18c
leaq (%rcx,%rcx,4), %rax
cmpl $0x0, 0x18(%r12,%rax,8)
jns 0x4cbc
leaq (%r12,%rax,8), %r9
cmpl $-0x1, 0x14(%r9)
je 0x4c15
movq 0x683c(%rip), %rax      # 0xb428
movl -0x4(%r13,%rcx,4), %edx
movq %rcx, %rsi
decq %rsi
addl 0x4(%rax,%r14,4), %edx
movl %edx, 0x18(%r9)
movq %r15, %rdi
movl 0x80(%rsp), %edx
movl $0x1, %r8d
jmp 0x4cb7
movq 0x680c(%rip), %rdi      # 0xb428
leaq -0x1(%rcx), %rsi
movl -0x4(%r13,%rcx,4), %r8d
movl 0x4(%rdi,%r14,4), %r10d
addl %r8d, %r10d
leal 0x2(%r14), %r11d
cmpl $-0x1, 0x10(%r9)
je 0x4c5d
movl %r10d, 0x14(%r9)
cmpl %r11d, %edx
jle 0x4c4b
addl 0x8(%rdi,%r14,4), %r8d
movl %r8d, 0x18(%r12,%rax,8)
movq %r15, %rdi
movl 0x80(%rsp), %edx
movl $0x2, %r8d
jmp 0x4cb7
movl %r10d, 0x10(%r9)
cmpl %r11d, %edx
jle 0x4c73
movl 0x8(%rdi,%r14,4), %r9d
addl %r8d, %r9d
movl %r9d, 0x14(%r12,%rax,8)
leal 0x3(%r14), %r9d
cmpl %r9d, %edx
jle 0x4c86
addl 0xc(%rdi,%r14,4), %r8d
movl %r8d, 0x18(%r12,%rax,8)
cmpl $0x1, 0x1c(%r12,%rax,8)
jg 0x4ca7
movq %r15, %rdi
movl 0x80(%rsp), %edx
callq 0x3ec9
cmpl $-0x1, %eax
jne 0x4cbc
jmp 0x4d89
movq %r15, %rdi
movl 0x80(%rsp), %edx
movl $0x3, %r8d
callq 0x3c18
movslq 0x64c9(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rcx
movl 0x4(%r12,%rcx,8), %edx
movl %edx, 0x14(%rsp)
movl (%r12,%rcx,8), %ecx
movl %ecx, 0x18(%rsp)
movq 0x8(%rsp), %rcx
leal (%rax,%rcx), %r8d
movq %r15, %rdi
movq 0x70(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x14(%rsp), %rcx
callq 0x2e6b
testl %eax, %eax
jne 0x4d89
movslq 0x6485(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rcx
movl 0x10(%r12,%rcx,8), %edx
movl %edx, 0x1c(%rsp)
movl 0x14(%r12,%rcx,8), %edx
movl %edx, 0x20(%rsp)
movl 0x18(%r12,%rcx,8), %ecx
movl %ecx, 0x24(%rsp)
movq 0x8(%rsp), %rcx
leal (%rax,%rcx), %r8d
movq %r15, %rdi
movq 0x78(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x30de
testl %eax, %eax
jne 0x4d89
movslq 0x643b(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rax
movl 0xc(%r12,%rax,8), %esi
addl %ebp, %esi
leaq 0x34b3(%rip), %rdi      # 0x8216
xorl %eax, %eax
callq 0x2030
movslq 0x641b(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rax
movl 0xc(%r12,%rax,8), %eax
addl %ebp, %eax
cmpl $0x5a6cfc6, %eax        # imm = 0x5A6CFC6
je 0x4dcb
incl 0x668f(%rip)            # 0xb418
movq 0x6698(%rip), %rax      # 0xb428
movslq 0x63f5(%rip), %rcx      # 0xb18c
movl -0x4(%r13,%rcx,4), %edi
addl (%rax,%r14,4), %edi
callq 0x3b6f
addl %eax, %ebp
incq %r14
movslq 0x63ef(%rip), %rax      # 0xb1a0
cmpq %rax, %r14
jl 0x4ae0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x361b(%rip), %rdi      # 0x83ed
callq 0x21f0
xorl %edi, %edi
callq 0x21a0