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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x30(%rsp)
movl %ecx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
cmpl $0x0, 0x7c86(%rip)      # 0xa720
jle 0x2e4a
movq %rdx, %r13
movl 0x90(%rsp), %ecx
movslq 0x7c77(%rip), %rax      # 0xa728
leaq 0x76b8(%rip), %rdx      # 0xa170
leaq (%rax,%rax,4), %rax
movl -0x20(%rdx,%rax,8), %ebp
movl %ecx, %eax
notl %eax
movq %rax, 0x28(%rsp)
leaq 0x7bd0(%rip), %r15      # 0xa6a0
xorl %r12d, %r12d
xorl %ebx, %ebx
movq 0x7c3c(%rip), %rax      # 0xa718
movslq 0x7c45(%rip), %r9       # 0xa728
movl -0x4(%r15,%r9,4), %edx
movl (%rax,%r12,4), %ecx
addl %edx, %ecx
cmpl %ebp, %ecx
jne 0x2e18
leaq -0x1(%r9), %rcx
leaq (%r9,%r9,4), %rsi
leaq 0x766b(%rip), %rdi      # 0xa170
leaq (%rdi,%rsi,8), %rdi
movq $-0xa, %r8
movl (%rdi,%r8,4), %r10d
movl %r10d, 0x28(%rdi,%r8,4)
incq %r8
jne 0x2b10
testq %r12, %r12
je 0x2bdd
leaq 0x7642(%rip), %r8       # 0xa170
cmpl $0x0, (%r8,%rsi,8)
jns 0x2bdd
movl -0x4(%rax,%r12,4), %r8d
addl %edx, %r8d
cmpl $-0x1, 0x4(%rdi)
je 0x2b65
movl %r8d, (%rdi)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movl 0x90(%rsp), %r8d
callq 0x2340
jmp 0x2bdd
movl %r8d, 0x4(%rdi)
cmpq $0x1, %r12
je 0x2b76
addl -0x8(%rax,%r12,4), %edx
movl %edx, (%rdi)
leaq 0x75f3(%rip), %rax      # 0xa170
testb $0x1, 0x1c(%rax,%rsi,8)
jne 0x2bc4
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ecx, %edx
movl 0x90(%rsp), %ecx
movl %r9d, %r8d
movl 0x10(%rsp), %r9d
callq 0x244d
cmpl $-0x1, %eax
je 0x2e18
movslq 0x7b75(%rip), %rax      # 0xa728
leaq (%rax,%rax,4), %rax
leaq 0x75b2(%rip), %rcx      # 0xa170
incl 0x1c(%rcx,%rax,8)
jmp 0x2bdd
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
movl 0x90(%rsp), %r8d
callq 0x238f
movslq 0x7b3c(%rip), %rcx      # 0xa720
cmpq %rcx, %r12
jge 0x2d26
movslq 0x7b34(%rip), %r8       # 0xa728
leaq (%r8,%r8,4), %rax
leaq 0x7571(%rip), %rdx      # 0xa170
cmpl $0x0, 0x18(%rdx,%rax,8)
jns 0x2d26
leaq 0x755f(%rip), %rdx      # 0xa170
leaq (%rdx,%rax,8), %r9
cmpl $-0x1, 0x14(%r9)
je 0x2c52
movq 0x7af5(%rip), %rax      # 0xa718
movl -0x4(%r15,%r8,4), %ecx
movq %r8, %rdx
decq %rdx
addl 0x4(%rax,%r12,4), %ecx
movl %ecx, 0x18(%r9)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x90(%rsp), %ecx
movl $0x1, %r9d
jmp 0x2d21
movq 0x7abf(%rip), %rsi      # 0xa718
leaq -0x1(%r8), %rdx
movl -0x4(%r15,%r8,4), %edi
movl 0x4(%rsi,%r12,4), %r10d
addl %edi, %r10d
leal 0x2(%r12), %r11d
cmpl $-0x1, 0x10(%r9)
je 0x2ca7
movl %r10d, 0x14(%r9)
cmpl %r11d, %ecx
jle 0x2c8f
addl 0x8(%rsi,%r12,4), %edi
leaq 0x74e5(%rip), %rcx      # 0xa170
movl %edi, 0x18(%rcx,%rax,8)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x90(%rsp), %ecx
movl $0x2, %r9d
jmp 0x2d21
movl %r10d, 0x10(%r9)
cmpl %r11d, %ecx
jle 0x2cc4
movl 0x8(%rsi,%r12,4), %r9d
addl %edi, %r9d
leaq 0x74b1(%rip), %r10      # 0xa170
movl %r9d, 0x14(%r10,%rax,8)
leal 0x3(%r12), %r9d
cmpl %r9d, %ecx
jle 0x2cde
addl 0xc(%rsi,%r12,4), %edi
leaq 0x7496(%rip), %rcx      # 0xa170
movl %edi, 0x18(%rcx,%rax,8)
leaq 0x748b(%rip), %rcx      # 0xa170
cmpl $0x1, 0x1c(%rcx,%rax,8)
jg 0x2d0b
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x90(%rsp), %ecx
callq 0x20e9
cmpl $-0x1, %eax
jne 0x2d26
jmp 0x2e18
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x90(%rsp), %ecx
movl $0x3, %r9d
callq 0x1e6f
movl %ebp, %r14d
movslq 0x79f8(%rip), %rax      # 0xa728
leaq (%rax,%rax,4), %r15
leaq 0x7435(%rip), %rdx      # 0xa170
movl 0x4(%rdx,%r15,8), %ecx
movl %ecx, 0x14(%rsp)
movl (%rdx,%r15,8), %ecx
movl %ecx, 0x18(%rsp)
movq 0x28(%rsp), %rcx
leal (%rax,%rcx), %ebp
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x30(%rsp), %rcx
leaq 0x14(%rsp), %r8
movl %ebp, %r9d
callq 0x15f5
testl %eax, %eax
jne 0x2e0e
leaq 0x73ea(%rip), %rcx      # 0xa170
movl 0x10(%rcx,%r15,8), %eax
movl %eax, 0x1c(%rsp)
movl 0x14(%rcx,%r15,8), %eax
movl %eax, 0x20(%rsp)
movl 0x18(%rcx,%r15,8), %eax
movl %eax, 0x24(%rsp)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0x1c(%rsp), %r8
movl %ebp, %r9d
callq 0x175f
testl %eax, %eax
jne 0x2e0e
movslq 0x7959(%rip), %rax      # 0xa728
leaq (%rax,%rax,4), %rax
leaq 0x7396(%rip), %r15      # 0xa170
movl 0xc(%r15,%rax,8), %esi
addl %ebx, %esi
leaq 0x3342(%rip), %rdi      # 0x612a
xorl %eax, %eax
callq 0x1030
movslq 0x7932(%rip), %rax      # 0xa728
leaq (%rax,%rax,4), %rax
movl 0xc(%r15,%rax,8), %eax
addl %ebx, %eax
cmpl $0x5a6cfc6, %eax        # imm = 0x5A6CFC6
je 0x2e5b
incl 0x78e2(%rip)            # 0xa6f0
movl %r14d, %ebp
leaq 0x7888(%rip), %r15      # 0xa6a0
movq 0x78f9(%rip), %rax      # 0xa718
movslq (%rax,%r12,4), %rax
movslq 0x78fe(%rip), %rcx      # 0xa728
movslq -0x4(%r15,%rcx,4), %rcx
addq %rax, %rcx
addl (%r13,%rcx,4), %ebx
incq %r12
movslq 0x78df(%rip), %rax      # 0xa720
cmpq %rax, %r12
jl 0x2ad5
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3559(%rip), %rdi      # 0x63bb
callq 0x11a0
xorl %edi, %edi
callq 0x1150