// File: /workspace/github_cpp_makefile_star2_O2/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, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movl %esi, 0x1c(%rsp)
movq %rdi, 0x10(%rsp)
movl 0x90(%rsp), %ecx
movslq 0x5bfb(%rip), %r12      # 0xa19c
leaq 0x8f18(%rip), %rbx      # 0xd4c0
imulq $0x28, %r12, %rax
movl -0x20(%rax,%rbx), %ebp
movl %ecx, %r11d
notl %r11d
leaq 0x5d33(%rip), %r14      # 0xa2f0
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r11, 0x8(%rsp)
movslq 0x5be1(%rip), %rax      # 0xa1b0
cmpq %rax, %r13
jge 0x48fc
movq 0x5e59(%rip), %rax      # 0xa438
movl (%rax,%r13,4), %edi
movslq %r12d, %rdx
leaq -0x1(%rdx), %rsi
movl -0x4(%r14,%rdx,4), %ecx
leal (%rcx,%rdi), %r8d
cmpl %ebp, %r8d
jne 0x489e
incl 0x5e2a(%rip)            # 0xa42c
imulq $0x28, %rsi, %rdi
imulq $0x28, %rdx, %rdx
xorl %r8d, %r8d
cmpq $0xa, %r8
je 0x4628
leaq (%rdi,%r8,4), %r9
movl (%rbx,%r9), %r9d
leaq (%rdx,%r8,4), %r10
movl %r9d, (%rbx,%r10)
incq %r8
jmp 0x460d
movl %r15d, 0x4(%rsp)
testq %r13, %r13
je 0x46cf
cmpl $0x0, (%rdx,%rbx)
jns 0x46cf
leaq (%rbx,%rdx), %rdi
movl -0x4(%rax,%r13,4), %r8d
addl %ecx, %r8d
cmpl $-0x1, 0x4(%rdi)
je 0x466b
movl %r8d, (%rdi)
movq 0x10(%rsp), %rdi
movl 0x90(%rsp), %edx
movl %r12d, %ecx
callq 0x3d25
jmp 0x46ca
movl %r8d, 0x4(%rdi)
cmpq $0x1, %r13
je 0x467c
addl -0x8(%rax,%r13,4), %ecx
movl %ecx, (%rdi)
testb $0x1, 0x1c(%rdx,%rbx)
jne 0x46b6
movq 0x10(%rsp), %rdi
movl 0x90(%rsp), %edx
movl %r12d, %ecx
movl 0x1c(%rsp), %r8d
callq 0x3ead
cmpl $-0x1, %eax
je 0x47be
movslq 0x5af0(%rip), %rax      # 0xa19c
imulq $0x28, %rax, %rax
incl 0x1c(%rax,%rbx)
jmp 0x46ca
movq 0x10(%rsp), %rdi
movl 0x90(%rsp), %edx
movl %r12d, %ecx
callq 0x3dda
movq 0x8(%rsp), %r11
movslq 0x5ada(%rip), %rdx      # 0xa1b0
cmpq %rdx, %r13
movq 0x10(%rsp), %r12
jge 0x47f8
movslq 0x5ab1(%rip), %rcx      # 0xa19c
imulq $0x28, %rcx, %rax
cmpl $0x0, 0x18(%rax,%rbx)
jns 0x47f8
leaq (%rbx,%rax), %r9
cmpl $-0x1, 0x14(%r9)
je 0x4731
movq 0x5d2c(%rip), %rax      # 0xa438
movl -0x4(%r14,%rcx,4), %edx
movq %rcx, %rsi
decq %rsi
addl 0x4(%rax,%r13,4), %edx
movl %edx, 0x18(%r9)
movq %r12, %rdi
movl 0x90(%rsp), %edx
pushq $0x1
jmp 0x47ec
movq 0x5d00(%rip), %rdi      # 0xa438
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 0x4775
movl %r10d, 0x14(%r9)
cmpl %r11d, %edx
jle 0x4767
addl 0x8(%rdi,%r13,4), %r8d
movl %r8d, 0x18(%rax,%rbx)
movq %r12, %rdi
movl 0x90(%rsp), %edx
pushq $0x2
jmp 0x47ec
movl %r10d, 0x10(%r9)
cmpl %r11d, %edx
jle 0x478b
movl 0x8(%rdi,%r13,4), %r9d
addl %r8d, %r9d
movl %r9d, 0x14(%rax,%rbx)
leal 0x3(%r13), %r9d
cmpl %r9d, %edx
jle 0x479e
addl 0xc(%rdi,%r13,4), %r8d
movl %r8d, 0x18(%rax,%rbx)
cmpl $0x1, 0x1c(%rax,%rbx)
jg 0x47e0
movq %r12, %rdi
movl 0x90(%rsp), %edx
callq 0x3a68
cmpl $-0x1, %eax
movq 0x8(%rsp), %r11
jne 0x47f8
movq 0x5c73(%rip), %rax      # 0xa438
movl (%rax,%r13,4), %edi
movslq 0x59cc(%rip), %r12      # 0xa19c
movq %r12, %rsi
decq %rsi
movl 0x4(%rsp), %r15d
jmp 0x489e
movq %r12, %rdi
movl 0x90(%rsp), %edx
pushq $0x3
popq %r8
callq 0x3825
movq 0x8(%rsp), %r11
movq %r14, %r15
movslq 0x599a(%rip), %rax      # 0xa19c
imulq $0x28, %rax, %rcx
movq (%rcx,%rbx), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x40(%rsp)
leal (%rax,%r11), %r8d
movq %r12, %rdi
movq 0x80(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r11, %r14
callq 0x2c6e
movq %r12, %rdi
movl 0x595b(%rip), %r12d     # 0xa19c
testl %eax, %eax
jne 0x4883
movslq %r12d, %r8
imulq $0x28, %r8, %rax
movq 0x10(%rax,%rbx), %rcx
movq %rcx, 0x30(%rsp)
movl 0x18(%rax,%rbx), %eax
movl %eax, 0x38(%rsp)
addl %r14d, %r8d
movq 0x88(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x2eb0
movl 0x591d(%rip), %r12d     # 0xa19c
testl %eax, %eax
je 0x48b7
movq %r15, %r14
movl 0x4(%rsp), %r15d
movq 0x5ba6(%rip), %rax      # 0xa438
movl (%rax,%r13,4), %edi
leal -0x1(%r12), %eax
movslq %eax, %rsi
addl (%r14,%rsi,4), %edi
callq 0x3770
addl %eax, %r15d
incq %r13
movq 0x8(%rsp), %r11
jmp 0x45c8
movslq %r12d, %rax
imulq $0x28, %rax, %rax
movl 0xc(%rax,%rbx), %esi
movl 0x4(%rsp), %r14d
addl %r14d, %esi
leaq 0x2975(%rip), %rdi      # 0x7246
xorl %eax, %eax
callq 0x2030
movslq 0x58bd(%rip), %r12      # 0xa19c
imulq $0x28, %r12, %rax
movl 0xc(%rax,%rbx), %eax
addl %r14d, %eax
cmpl $0x5a6cfc6, %eax        # imm = 0x5A6CFC6
je 0x490d
movq %r15, %r14
incl 0x5b2e(%rip)            # 0xa428
jmp 0x4886
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b09(%rip), %rdi      # 0x741d
callq 0x2210
xorl %edi, %edi
callq 0x21c0