// File: /workspace/github_cpp_makefile_star2_O2/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 %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
movl 0xa0(%rsp), %ecx
movslq 0x7034(%rip), %rbp      # 0x9728
leaq 0x6a75(%rip), %rbx      # 0x9170
imulq $0x28, %rbp, %rax
movl -0x20(%rax,%rbx), %r12d
notl %ecx
movl %ecx, 0x24(%rsp)
leaq 0x6f8f(%rip), %r13      # 0x96a0
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %rdx, 0x18(%rsp)
movl %r12d, 0x14(%rsp)
movslq 0x6ff8(%rip), %rax      # 0x9720
cmpq %rax, %r14
jge 0x2a96
movq 0x6fe0(%rip), %rax      # 0x9718
movl (%rax,%r14,4), %esi
movslq %ebp, %r8
leaq -0x1(%r8), %rcx
movl -0x4(%r13,%r8,4), %r11d
leal (%r11,%rsi), %edi
cmpl %r12d, %edi
jne 0x2a7f
imulq $0x28, %rcx, %rdi
imulq $0x28, %r8, %rsi
xorl %r8d, %r8d
cmpq $0xa, %r8
je 0x277b
leaq (%rdi,%r8,4), %r9
movl (%rbx,%r9), %r9d
leaq (%rsi,%r8,4), %r10
movl %r9d, (%rbx,%r10)
incq %r8
jmp 0x2760
movl %r15d, 0x10(%rsp)
testq %r14, %r14
je 0x282e
cmpl $0x0, (%rsi,%rbx)
jns 0x282e
leaq (%rbx,%rsi), %rdi
movl -0x4(%rax,%r14,4), %r8d
addl %r11d, %r8d
cmpl $-0x1, 0x4(%rdi)
je 0x27c3
movl %r8d, (%rdi)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0xa0(%rsp), %r8d
movl %ebp, %r9d
callq 0x2068
jmp 0x282e
movl %r8d, 0x4(%rdi)
cmpq $0x1, %r14
je 0x27d5
addl -0x8(%rax,%r14,4), %r11d
movl %r11d, (%rdi)
testb $0x1, 0x1c(%rsi,%rbx)
jne 0x2815
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ecx, %edx
movl 0xa0(%rsp), %ecx
movl %ebp, %r8d
movl 0x20(%rsp), %r9d
callq 0x2150
cmpl $-0x1, %eax
je 0x294d
movslq 0x6f1d(%rip), %rax      # 0x9728
imulq $0x28, %rax, %rax
incl 0x1c(%rax,%rbx)
jmp 0x282e
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0xa0(%rsp), %r8d
movl %ebp, %r9d
callq 0x20bb
movslq 0x6eeb(%rip), %rcx      # 0x9720
cmpq %rcx, %r14
jge 0x2988
movslq 0x6ee3(%rip), %r8       # 0x9728
imulq $0x28, %r8, %rax
cmpl $0x0, 0x18(%rax,%rbx)
jns 0x2988
leaq (%rbx,%rax), %r9
cmpl $-0x1, 0x14(%r9)
je 0x2891
movq 0x6eb2(%rip), %rax      # 0x9718
movl -0x4(%r13,%r8,4), %ecx
movq %r8, %rdx
decq %rdx
addl 0x4(%rax,%r14,4), %ecx
movl %ecx, 0x18(%r9)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0xa0(%rsp), %ecx
pushq $0x1
jmp 0x2981
movq 0x6e80(%rip), %rsi      # 0x9718
leaq -0x1(%r8), %rdx
movl -0x4(%r13,%r8,4), %edi
movl 0x4(%rsi,%r14,4), %r10d
addl %edi, %r10d
leal 0x2(%r14), %r11d
cmpl $-0x1, 0x10(%r9)
je 0x28dd
movl %r10d, 0x14(%r9)
cmpl %r11d, %ecx
jle 0x28c6
addl 0x8(%rsi,%r14,4), %edi
movl %edi, 0x18(%rax,%rbx)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0xa0(%rsp), %ecx
pushq $0x2
jmp 0x2981
movl %r10d, 0x10(%r9)
cmpl %r11d, %ecx
jle 0x28f3
movl 0x8(%rsi,%r14,4), %r9d
addl %edi, %r9d
movl %r9d, 0x14(%rax,%rbx)
leal 0x3(%r14), %r9d
cmpl %r9d, %ecx
jle 0x2905
addl 0xc(%rsi,%r14,4), %edi
movl %edi, 0x18(%rax,%rbx)
cmpl $0x1, 0x1c(%rax,%rbx)
jg 0x296f
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0xa0(%rsp), %ecx
callq 0x1e48
cmpl $-0x1, %eax
jne 0x2988
movq 0x6deb(%rip), %rax      # 0x9718
movl (%rax,%r14,4), %esi
movslq 0x6df0(%rip), %rbp      # 0x9728
movq %rbp, %rcx
decq %rcx
movq 0x18(%rsp), %rdx
movl 0x14(%rsp), %r12d
jmp 0x2a7a
movq 0x6dc4(%rip), %rax      # 0x9718
movl (%rax,%r14,4), %esi
movslq 0x6dc9(%rip), %rbp      # 0x9728
movq %rbp, %rcx
decq %rcx
movq 0x18(%rsp), %rdx
jmp 0x2a7a
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0xa0(%rsp), %ecx
pushq $0x3
popq %r9
callq 0x1cce
movq %r13, %r15
movl 0x6d97(%rip), %ebp      # 0x9728
movslq %ebp, %r13
imulq $0x28, %r13, %r12
movq (%r12,%rbx), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x40(%rsp)
addl 0x24(%rsp), %r13d
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x90(%rsp), %rdx
movq 0x28(%rsp), %rcx
leaq 0x40(%rsp), %r8
movl %r13d, %r9d
callq 0x157f
testl %eax, %eax
jne 0x2a5c
movq 0x10(%r12,%rbx), %rax
movq %rax, 0x30(%rsp)
movl 0x18(%r12,%rbx), %eax
movl %eax, 0x38(%rsp)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0x80(%rsp), %rcx
leaq 0x30(%rsp), %r8
movl %r13d, %r9d
callq 0x16f6
movl 0x6d10(%rip), %ebp      # 0x9728
testl %eax, %eax
jne 0x2a5c
movslq %ebp, %rax
imulq $0x28, %rax, %rax
movl 0xc(%rax,%rbx), %esi
movl 0x10(%rsp), %r12d
addl %r12d, %esi
leaq 0x26ec(%rip), %rdi      # 0x5122
xorl %eax, %eax
callq 0x1030
movslq 0x6ce4(%rip), %rbp      # 0x9728
imulq $0x28, %rbp, %rax
movl 0xc(%rax,%rbx), %eax
addl %r12d, %eax
cmpl $0x5a6cfc6, %eax        # imm = 0x5A6CFC6
je 0x2aa7
incl 0x6c94(%rip)            # 0x96f0
movq 0x6cb5(%rip), %rax      # 0x9718
movl (%rax,%r14,4), %esi
leal -0x1(%rbp), %eax
movslq %eax, %rcx
movq 0x18(%rsp), %rdx
movl 0x14(%rsp), %r12d
movq %r15, %r13
movl 0x10(%rsp), %r15d
movslq (%r13,%rcx,4), %rax
movslq %esi, %rcx
addq %rax, %rcx
addl (%rdx,%rcx,4), %r15d
incq %r14
jmp 0x2721
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2905(%rip), %rdi      # 0x53b3
callq 0x11a0
xorl %edi, %edi
callq 0x1150