// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, 0x28(%rsp)
movl %esi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
cmpl $0x0, 0x67bf(%rip)      # 0xb1a0
jle 0x4d1c
movl 0x90(%rsp), %ecx
movslq 0x6797(%rip), %r12      # 0xb18c
leaq 0x9ab4(%rip), %rbx      # 0xe4b0
leaq (%r12,%r12,4), %rax
movl -0x20(%rbx,%rax,8), %eax
movl %eax, 0x14(%rsp)
movl %ecx, %eax
notl %eax
movq %rax, 0x20(%rsp)
movq 0x6a10(%rip), %rbp      # 0xb428
leaq 0x68c1(%rip), %r14      # 0xb2e0
xorl %r13d, %r13d
xorl %r15d, %r15d
movl (%rbp,%r13,4), %edi
movslq %r12d, %rcx
leaq -0x1(%rcx), %rsi
movl -0x4(%r14,%rcx,4), %eax
leal (%rax,%rdi), %edx
cmpl 0x14(%rsp), %edx
jne 0x4cfd
incl 0x69d3(%rip)            # 0xb41c
leaq (%rcx,%rcx,4), %rcx
leaq (%rbx,%rcx,8), %rdx
movq $-0xa, %rdi
movl (%rdx,%rdi,4), %r8d
movl %r8d, 0x28(%rdx,%rdi,4)
incq %rdi
jne 0x4a58
testq %r13, %r13
je 0x4afc
cmpl $0x0, (%rbx,%rcx,8)
jns 0x4afc
movl -0x4(%rbp,%r13,4), %edi
addl %eax, %edi
cmpl $-0x1, 0x4(%rdx)
je 0x4a9e
movl %edi, (%rdx)
movq 0x8(%rsp), %rdi
movl 0x90(%rsp), %edx
movl %r12d, %ecx
callq 0x4092
jmp 0x4afc
movl %edi, 0x4(%rdx)
cmpq $0x1, %r13
je 0x4aae
addl -0x8(%rbp,%r13,4), %eax
movl %eax, (%rdx)
testb $0x1, 0x1c(%rbx,%rcx,8)
jne 0x4ae8
movq 0x8(%rsp), %rdi
movl 0x90(%rsp), %edx
movl %r12d, %ecx
movl 0x10(%rsp), %r8d
callq 0x424d
cmpl $-0x1, %eax
je 0x4bf3
movslq 0x66ae(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rax
incl 0x1c(%rbx,%rax,8)
jmp 0x4afc
movq 0x8(%rsp), %rdi
movl 0x90(%rsp), %edx
movl %r12d, %ecx
callq 0x4164
movslq 0x669d(%rip), %rdx      # 0xb1a0
cmpq %rdx, %r13
movq 0x8(%rsp), %rbp
movq 0x20(%rsp), %r12
jge 0x4c26
movslq 0x666f(%rip), %rcx      # 0xb18c
leaq (%rcx,%rcx,4), %rax
cmpl $0x0, 0x18(%rbx,%rax,8)
jns 0x4c26
leaq (%rbx,%rax,8), %r9
cmpl $-0x1, 0x14(%r9)
je 0x4b67
movq 0x68ea(%rip), %rax      # 0xb428
movl -0x4(%r14,%rcx,4), %edx
movq %rcx, %rsi
decq %rsi
addl 0x4(%rax,%r13,4), %edx
movl %edx, 0x18(%r9)
movq %rbp, %rdi
movl 0x90(%rsp), %edx
movl $0x1, %r8d
jmp 0x4c21
movq 0x68ba(%rip), %rdi      # 0xb428
leaq -0x1(%rcx), %rsi
movl -0x4(%r14,%rcx,4), %r8d
movl 0x4(%rdi,%r13,4), %r10d
addl %r8d, %r10d
leal 0x2(%r13), %r11d
cmpl $-0x1, 0x10(%r9)
je 0x4baf
movl %r10d, 0x14(%r9)
cmpl %r11d, %edx
jle 0x4b9d
addl 0x8(%rdi,%r13,4), %r8d
movl %r8d, 0x18(%rbx,%rax,8)
movq %rbp, %rdi
movl 0x90(%rsp), %edx
movl $0x2, %r8d
jmp 0x4c21
movl %r10d, 0x10(%r9)
cmpl %r11d, %edx
jle 0x4bc5
movl 0x8(%rdi,%r13,4), %r9d
addl %r8d, %r9d
movl %r9d, 0x14(%rbx,%rax,8)
leal 0x3(%r13), %r9d
cmpl %r9d, %edx
jle 0x4bd8
addl 0xc(%rdi,%r13,4), %r8d
movl %r8d, 0x18(%rbx,%rax,8)
cmpl $0x1, 0x1c(%rbx,%rax,8)
jg 0x4c11
movq %rbp, %rdi
movl 0x90(%rsp), %edx
callq 0x3dcb
cmpl $-0x1, %eax
jne 0x4c26
movq 0x682e(%rip), %rbp      # 0xb428
movl (%rbp,%r13,4), %edi
movslq 0x6586(%rip), %r12      # 0xb18c
movq %r12, %rsi
decq %rsi
jmp 0x4cfd
movq %rbp, %rdi
movl 0x90(%rsp), %edx
movl $0x3, %r8d
callq 0x3b48
movslq 0x655f(%rip), %rax      # 0xb18c
leaq (%rax,%rax,4), %rcx
movq (%rbx,%rcx,8), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x40(%rsp)
leal (%rax,%r12), %r8d
movq %rbp, %rdi
movq 0x80(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq 0x2ddb
movq %r12, %rdx
movl 0x6523(%rip), %r12d     # 0xb18c
testl %eax, %eax
jne 0x4ce9
movslq %r12d, %r8
leaq (%r8,%r8,4), %rax
movq 0x10(%rbx,%rax,8), %rcx
movq %rcx, 0x30(%rsp)
movl 0x18(%rbx,%rax,8), %eax
movl %eax, 0x38(%rsp)
addl %edx, %r8d
movq %rbp, %rdi
movq 0x88(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x3051
movl 0x64e2(%rip), %r12d     # 0xb18c
testl %eax, %eax
jne 0x4ce9
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
movl 0xc(%rbx,%rax,8), %esi
addl %r15d, %esi
leaq 0x3583(%rip), %rdi      # 0x8246
xorl %eax, %eax
callq 0x2030
movslq 0x64bb(%rip), %r12      # 0xb18c
leaq (%r12,%r12,4), %rax
movl 0xc(%rbx,%rax,8), %eax
addl %r15d, %eax
cmpl $0x5a6cfc6, %eax        # imm = 0x5A6CFC6
je 0x4d2d
incl 0x672f(%rip)            # 0xb418
movq 0x6738(%rip), %rbp      # 0xb428
movl (%rbp,%r13,4), %edi
leal -0x1(%r12), %eax
movslq %eax, %rsi
addl (%r14,%rsi,4), %edi
callq 0x3a9f
addl %eax, %r15d
incq %r13
movslq 0x648d(%rip), %rax      # 0xb1a0
cmpq %rax, %r13
jl 0x4a25
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x36e9(%rip), %rdi      # 0x841d
callq 0x21f0
xorl %edi, %edi
callq 0x21a0