// File: /workspace/github_cpp_makefile_star2_O3/TooruAkagi[P]GCIS_Index/gcis_uni_locate.cpp
// Function: ptrans(int*, int*, int*, int*, int*, int, int*, int, int)
int ptrans(int *B1,int *B2,int *B3,int *Ls,int *Rs,int startm,int *m,int mrlen,int round){
    int *Rp;int flag = 0;Rp = (int*)malloc(mrlen*4+4);
    int tn = -1;int Rpptr = 0;int len = 0;
    coredata[6] = -1;coredata[8]=0; //Cコアは,最初はないし，長さも0;
    if(DEBUGFLAG==1){printf("\n[変換%d]",round);}
    for(int i = startm+mrlen-1;i>startm;i--){ //check from right(for setting L&S type)
        Rp[Rpptr] = m[i];len++;
        if(m[i-1] < m[i]){tn=0;}
        if(m[i-1] > m[i]){
            if(tn==0){
                if(B2[round] == 0){B2[round] = len;len = 0;flag++;}
                else{
                    Rpptr-=(len-1);
                    Rp[Rpptr] = pscheck(m,i,len,round); //i = 初期値 len = 長さ,round
                    if(Rp[Rpptr]<0){return -99;}
                    B3[round]++;
                    len = 0;
                }
            }
            if(tn==-1){
                coredata[6] = 1;
                coredata[7] = m[startm+mrlen-1]; //Cコアの番号は
                coredata[8] = len; //Cコア長さは1
            } //Cコアの長さ
            tn=1;
        }
        Rpptr++;
    }
    len++;
    Rp[Rpptr] = m[startm];
    for(int i = 0;i<=Rpptr;i++){ //reverse Rp >> m
        m[startm+i] = Rp[Rpptr-i];
    }
    if(DEBUGFLAG==1){printf("\n[変換%d]end",round);}
    if(B2[round]==0){ //確実に切れる場所[Aコア]がない
        coredata[0] = -1; //Aコアはない
        coredata[2] = 0;
        coredata[3] = 1; //Bコアはある
        coredata[4] = 0; //Bコア開始位置は0
        coredata[5] = mrlen-coredata[8]; //Bコア長さはmrlen - Cコア(あれば)
        if(DEBUGFLAG==1){printf("(in round%d) input string can't be pursed anymore．",round);}
        return -2;
    }
    if(B3[round]==0){ //Aコアがある
        coredata[0] = 1; //Aコアはある
        coredata[1] = 0; //Aコア開始位置は0
        coredata[2] = mrlen-B2[round]; //Aコアの長さは mrlen(Core) - B2[round]
        coredata[3] = 1; //Bコアはある
        coredata[4] = mrlen-B2[round]; //Bコア開始位置はmrlen-B2[eound]
        coredata[5] = B2[round]-coredata[8]; //Bコア長さはmrlen - Cコア(あれば)
        if(DEBUGFLAG==1){printf("(in round%d) input string desn't have core",round);}
        return -1;
    }

    Ls[round] = startm;B1[round]=len; //B1:leftside of core / Ls:starting posision of it
    Rs[round] = startm + B1[round] + B3[round]; //Rs corresponds to Ls, B3 to B1.
    free(Rp);
    return B3[round];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %ebx
movq %r8, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r12
movq %rsi, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movl 0x88(%rsp), %ebp
movq 0x80(%rsp), %r13
leal 0x4(,%rbp,4), %eax
movslq %eax, %rdi
callq 0x21b0
movq %rax, %r10
movl $0xffffffff, 0xb120(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0xb11e(%rip)      # 0xe980
leal (%rbx,%rbp), %eax
decl %eax
movslq 0x90(%rsp), %r14
cmpl %ebx, %eax
movq %rbx, 0x28(%rsp)
jle 0x396f
movq %r12, 0x10(%rsp)
movslq %eax, %rbp
movslq %ebx, %rdi
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r11d, %r11d
movq %rbp, 0x40(%rsp)
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x8(%rsp), %r8
movq %rdi, 0x38(%rsp)
movl (%r13,%rbp,4), %esi
movslq %r15d, %rcx
movl %esi, (%r10,%rcx,4)
leal 0x1(%rax), %edx
movl %r12d, %ecx
cmpl %esi, -0x4(%r13,%rbp,4)
cmovll %r11d, %ecx
jle 0x3928
movl $0x1, %r12d
cmpl $-0x1, %ecx
je 0x392d
testl %ecx, %ecx
jne 0x394d
cmpl $0x0, (%r8,%r14,4)
je 0x3964
subl %eax, %r15d
movq %r13, %rbx
movq %r13, %rdi
movl %ebp, %esi
movl 0x90(%rsp), %ecx
movq %r10, %r13
callq 0x336d
movslq %r15d, %rcx
movl %eax, (%r13,%rcx,4)
testl %eax, %eax
js 0x3a98
movq %r13, %r10
movq 0x10(%rsp), %rax
incl (%rax,%r14,4)
xorl %eax, %eax
movl %r15d, %ecx
movq 0x8(%rsp), %r8
movq %rbx, %r13
movq 0x38(%rsp), %rdi
xorl %r11d, %r11d
jmp 0x3952
movl %ecx, %r12d
jmp 0x394d
movl $0x1, 0xb041(%rip)      # 0xe978
movq 0x40(%rsp), %rax
movl (%r13,%rax,4), %eax
movl %eax, 0xb035(%rip)      # 0xe97c
movl %edx, 0xb033(%rip)      # 0xe980
movl %r15d, %ecx
movl %edx, %eax
leal 0x1(%rcx), %r15d
decq %rbp
cmpq %rdi, %rbp
jg 0x38a4
jmp 0x398b
movl %edx, (%r8,%r14,4)
xorl %eax, %eax
movl %r15d, %ecx
jmp 0x3952
movslq %ebx, %rdi
movl (%r13,%rdi,4), %eax
movl %eax, (%r10)
xorl %edx, %edx
movl $0x1, %eax
xorl %r15d, %r15d
movq 0x8(%rsp), %r8
jmp 0x39aa
incl %eax
movl (%r13,%rdi,4), %esi
movslq %r15d, %rdx
movl %esi, (%r10,%rdx,4)
cmpl $-0x1, %ecx
movq 0x10(%rsp), %r12
movl 0x88(%rsp), %ebp
jl 0x39cf
incl %r15d
leaq (,%rdi,4), %rcx
addq %r13, %rcx
leaq (%r10,%rdx,4), %rdx
xorl %esi, %esi
movl (%rdx), %edi
movl %edi, (%rcx,%rsi,4)
incq %rsi
addq $-0x4, %rdx
cmpq %rsi, %r15
jne 0x39be
cmpl $0x0, (%r8,%r14,4)
je 0x3a11
cmpl $0x0, (%r12,%r14,4)
je 0x3a49
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
movl %ecx, (%rdx,%r14,4)
movq 0x18(%rsp), %rdx
movl %eax, (%rdx,%r14,4)
addl %ecx, %eax
addl (%r12,%r14,4), %eax
movq 0x30(%rsp), %rcx
movl %eax, (%rcx,%r14,4)
movq %r10, %rdi
callq 0x2190
movl (%r12,%r14,4), %eax
jmp 0x3a89
movl $0xffffffff, 0xaf45(%rip) # imm = 0xFFFFFFFF
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xaf3c(%rip)      # 0xe968
movl $0x0, 0xaf3a(%rip)      # 0xe970
subl 0xaf44(%rip), %ebp      # 0xe980
movl %ebp, 0xaf32(%rip)      # 0xe974
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x3a89
movq $0x1, 0xaf0c(%rip) # 0xe960
movl %ebp, %eax
subl (%r8,%r14,4), %eax
movl %eax, 0xaf08(%rip)      # 0xe968
movl $0x1, 0xaf02(%rip)      # 0xe96c
subl (%r8,%r14,4), %ebp
movl %ebp, 0xaefc(%rip)      # 0xe970
movl (%r8,%r14,4), %eax
subl 0xaf02(%rip), %eax      # 0xe980
movl %eax, 0xaef0(%rip)      # 0xe974
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffff9d, %eax       # imm = 0xFFFFFF9D
jmp 0x3a89