// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r9, 0x28(%rsp)
movl %ecx, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
cmpl $0x0, 0x7f76(%rip)      # 0xa720
jle 0x2c13
movl 0xa0(%rsp), %ecx
movslq 0x7f6a(%rip), %rbp      # 0xa728
leaq 0x79ab(%rip), %r11      # 0xa170
leaq (,%rbp,4), %rax
addq %rbp, %rax
movl -0x20(%r11,%rax,8), %r13d
notl %ecx
movl %ecx, 0x24(%rsp)
movq 0x7f36(%rip), %rax      # 0xa718
leaq 0x7eb7(%rip), %r12      # 0xa6a0
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %rsi, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
movl (%rax,%rbx,4), %r9d
movslq %ebp, %rdi
leaq -0x1(%rdi), %rcx
movl -0x4(%r12,%rdi,4), %r10d
leal (%r10,%r9), %r8d
cmpl %r13d, %r8d
jne 0x2afa
leaq (%rdi,%rdi,4), %r15
leaq (%r11,%r15,8), %rdx
movq $-0xa, %r8
movl (%rdx,%r8,4), %r9d
movl %r9d, 0x28(%rdx,%r8,4)
incq %r8
jne 0x2824
testq %rbx, %rbx
movq 0x10(%rsp), %rdi
je 0x2843
cmpl $0x0, (%r11,%r15,8)
js 0x28ba
movslq 0x7ed6(%rip), %rcx      # 0xa720
cmpq %rcx, %rbx
jge 0x29e3
movslq 0x7ece(%rip), %r8       # 0xa728
leaq (%r8,%r8,4), %rax
cmpl $0x0, 0x18(%r11,%rax,8)
jns 0x29e3
leaq (%r11,%rax,8), %r9
cmpl $-0x1, 0x14(%r9)
je 0x2974
movq 0x7e98(%rip), %rax      # 0xa718
movl -0x4(%r12,%r8,4), %ecx
movq %r8, %rdx
decq %rdx
addl 0x4(%rax,%rbx,4), %ecx
movl %ecx, 0x18(%r9)
movq 0x10(%rsp), %r15
movq %r15, %rdi
movl 0xa0(%rsp), %ecx
movl $0x1, %r9d
callq 0x1d78
movq %r15, %rdi
movq 0x8(%rsp), %rsi
jmp 0x29dc
movl -0x4(%rax,%rbx,4), %r8d
addl %r10d, %r8d
cmpl $-0x1, 0x4(%rdx)
je 0x2911
movl %r8d, (%rdx)
addl $-0x2, %ebp
movl 0xa0(%rsp), %eax
leal 0x1(%rbp), %r9d
xorl %ecx, %ecx
cmpl $0x2, %r9d
jl 0x28e7
movl %ebp, %ecx
movl (%r12,%rcx,4), %ecx
testl %r8d, %r8d
js 0x2843
movl %r8d, %r8d
movslq 0x4(%rsi,%r8,4), %r8
addl -0x4(%rdi,%r8,4), %ecx
movl %ecx, (%rdx)
cmpl $0x2, %eax
jl 0x2843
decl %eax
decl %ebp
movl %ecx, %r8d
jmp 0x28d5
movl %r8d, 0x4(%rdx)
cmpq $0x1, %rbx
je 0x2923
addl -0x8(%rax,%rbx,4), %r10d
movl %r10d, (%rdx)
testb $0x1, 0x1c(%r11,%r15,8)
jne 0x2b20
movl %ecx, %edx
movl 0xa0(%rsp), %ecx
movl %ebp, %r8d
movl 0x20(%rsp), %r9d
callq 0x21ed
cmpl $-0x1, %eax
je 0x2bd0
movslq 0x7dd3(%rip), %rax      # 0xa728
leaq (%rax,%rax,4), %rax
leaq 0x7810(%rip), %r11      # 0xa170
incl 0x1c(%r11,%rax,8)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
jmp 0x2843
movq 0x7d9d(%rip), %r15      # 0xa718
leaq -0x1(%r8), %rdx
movl -0x4(%r12,%r8,4), %edi
movl 0x4(%r15,%rbx,4), %r10d
addl %edi, %r10d
leal 0x2(%rbx), %r11d
cmpl $-0x1, 0x10(%r9)
je 0x2b46
movl %r10d, 0x14(%r9)
cmpl %r11d, %ecx
jle 0x29b4
addl 0x8(%r15,%rbx,4), %edi
leaq 0x77c0(%rip), %rcx      # 0xa170
movl %edi, 0x18(%rcx,%rax,8)
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
movl 0xa0(%rsp), %ecx
movl $0x2, %r9d
callq 0x1d78
movq %r12, %rdi
movq %r15, %rsi
leaq 0x778d(%rip), %r11      # 0xa170
movl %r13d, %r12d
movl 0x7d3c(%rip), %ebp      # 0xa728
movslq %ebp, %r13
leaq (,%r13,4), %r15
addq %r13, %r15
movq (%r11,%r15,8), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x40(%rsp)
addl 0x24(%rsp), %r13d
movq 0x90(%rsp), %rdx
movq 0x28(%rsp), %rcx
leaq 0x40(%rsp), %r8
movl %r13d, %r9d
callq 0x1587
leaq 0x773f(%rip), %r11      # 0xa170
movq 0x8(%rsp), %rsi
testl %eax, %eax
jne 0x2ada
movq 0x10(%r11,%r15,8), %rax
movq %rax, 0x30(%rsp)
movl 0x18(%r11,%r15,8), %eax
movl %eax, 0x38(%rsp)
movq 0x10(%rsp), %rdi
movq 0x98(%rsp), %rdx
movq 0x80(%rsp), %rcx
leaq 0x30(%rsp), %r8
movl %r13d, %r9d
movq %r11, %r15
callq 0x1748
movl 0x7cac(%rip), %ebp      # 0xa728
testl %eax, %eax
je 0x2a8a
movq 0x8(%rsp), %rsi
movq %r15, %r11
jmp 0x2ada
movslq %ebp, %rax
leaq (%rax,%rax,4), %rax
movl 0xc(%r15,%rax,8), %esi
addl %r14d, %esi
leaq 0x3682(%rip), %rdi      # 0x6122
xorl %eax, %eax
callq 0x1030
movslq 0x7c7a(%rip), %rbp      # 0xa728
leaq (,%rbp,4), %rax
addq %rbp, %rax
movl 0xc(%r15,%rax,8), %eax
addl %r14d, %eax
cmpl $0x5a6cfc6, %eax        # imm = 0x5A6CFC6
je 0x2c24
movq %r15, %r11
incl 0x7c1b(%rip)            # 0xa6f0
movq 0x8(%rsp), %rsi
movq 0x7c37(%rip), %rax      # 0xa718
movl (%rax,%rbx,4), %r9d
leal -0x1(%rbp), %ecx
movslq %ecx, %rcx
movq 0x18(%rsp), %rdx
movl %r12d, %r13d
leaq 0x7ba6(%rip), %r12      # 0xa6a0
movslq (%r12,%rcx,4), %rcx
movslq %r9d, %rdi
addq %rcx, %rdi
addl (%rdx,%rdi,4), %r14d
incq %rbx
movslq 0x7c0e(%rip), %rcx      # 0xa720
cmpq %rcx, %rbx
jl 0x27f8
jmp 0x2c13
movl 0xa0(%rsp), %r8d
movl %ebp, %r9d
callq 0x2158
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
leaq 0x762f(%rip), %r11      # 0xa170
jmp 0x2843
movl %r10d, 0x10(%r9)
cmpl %r11d, %ecx
leaq 0x761c(%rip), %r10      # 0xa170
jle 0x2b63
movl 0x8(%r15,%rbx,4), %r9d
addl %edi, %r9d
movl %r9d, 0x14(%r10,%rax,8)
leal 0x3(%rbx), %r9d
cmpl %r9d, %ecx
movq 0x8(%rsp), %rsi
jle 0x2b7b
addl 0xc(%r15,%rbx,4), %edi
movl %edi, 0x18(%r10,%rax,8)
cmpl $0x1, 0x1c(%r10,%rax,8)
movq 0x10(%rsp), %rdi
movl 0xa0(%rsp), %ecx
jg 0x2bfe
callq 0x1f41
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
cmpl $-0x1, %eax
leaq 0x75c8(%rip), %r11      # 0xa170
jne 0x29e3
movq 0x7b63(%rip), %rax      # 0xa718
movl (%rax,%rbx,4), %r9d
movslq 0x7b68(%rip), %rbp      # 0xa728
movq %rbp, %rcx
decq %rcx
movq 0x18(%rsp), %rdx
jmp 0x2afa
movq 0x7b41(%rip), %rax      # 0xa718
movl (%rax,%rbx,4), %r9d
movslq 0x7b46(%rip), %rbp      # 0xa728
movq %rbp, %rcx
decq %rcx
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rsi
leaq 0x7577(%rip), %r11      # 0xa170
jmp 0x2afa
movl $0x3, %r9d
callq 0x1d78
movq 0x10(%rsp), %rdi
jmp 0x28b0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3788(%rip), %rdi      # 0x63b3
callq 0x11a0
xorl %edi, %edi
callq 0x1150