// File: /workspace/github_cpp_makefile_star2_O2/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, %r15d
movq %r8, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movl 0x88(%rsp), %ebx
movq 0x80(%rsp), %rbp
leal 0x4(,%rbx,4), %eax
movslq %eax, %rdi
callq 0x21d0
orl $-0x1, 0xa412(%rip)     # 0xd988
andl $0x0, 0xa413(%rip)      # 0xd990
movq %rax, %r10
leal (%r15,%rbx), %eax
decl %eax
cltq
movslq 0x90(%rsp), %r9
movq %r15, 0x28(%rsp)
movslq %r15d, %r12
xorl %edi, %edi
pushq $-0x1
popq %rcx
pushq $0x1
popq %r14
movq %rax, 0x40(%rsp)
movq %rax, %r15
xorl %r13d, %r13d
xorl %eax, %eax
movq %r10, 0x38(%rsp)
movslq %r13d, %rdx
cmpq %r12, %r15
jle 0x3661
movl (%rbp,%r15,4), %esi
movl %esi, (%r10,%rdx,4)
leal 0x1(%rax), %edx
cmpl %esi, -0x4(%rbp,%r15,4)
cmovll %edi, %ecx
jle 0x3654
cmpl $-0x1, %ecx
je 0x362a
testl %ecx, %ecx
jne 0x3651
movq 0x10(%rsp), %rcx
cmpl $0x0, (%rcx,%r9,4)
je 0x364b
movq %r9, %rbx
subl %eax, %r13d
movq %rbp, %rdi
movl %r15d, %esi
movl 0x90(%rsp), %ecx
callq 0x319a
movq 0x38(%rsp), %r10
movslq %r13d, %rcx
movl %eax, (%r10,%rcx,4)
testl %eax, %eax
js 0x375e
movq 0x8(%rsp), %rax
movq %rbx, %r9
incl (%rax,%rbx,4)
xorl %edx, %edx
movl %r14d, %ecx
xorl %edi, %edi
jmp 0x3654
movl $0x1, 0xa354(%rip)      # 0xd988
movq 0x40(%rsp), %rax
movl (%rbp,%rax,4), %eax
movl %eax, 0xa349(%rip)      # 0xd98c
movl %edx, 0xa347(%rip)      # 0xd990
jmp 0x3651
movl %edx, (%rcx,%r9,4)
xorl %edx, %edx
movl %r14d, %ecx
incl %r13d
decq %r15
movl %edx, %eax
jmp 0x35b3
leaq (,%r12,4), %rcx
addq %rbp, %rcx
movl (%rcx), %esi
movl %esi, (%r10,%rdx,4)
leaq (%r10,%rdx,4), %rsi
xorl %edi, %edi
movq 0x8(%rsp), %rbx
cmpq %rdx, %rdi
jg 0x3692
movl (%rsi), %r8d
movl %r8d, (%rcx,%rdi,4)
incq %rdi
addq $-0x4, %rsi
jmp 0x367d
movq 0x10(%rsp), %rdx
cmpl $0x0, (%rdx,%r9,4)
je 0x36e1
cmpl $0x0, (%rbx,%r9,4)
je 0x3717
incl %eax
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
movl %ecx, (%rdx,%r9,4)
movq 0x18(%rsp), %rdx
movl %eax, (%rdx,%r9,4)
addl %ecx, %eax
addl (%rbx,%r9,4), %eax
movq 0x30(%rsp), %rcx
movl %eax, (%rcx,%r9,4)
movq %r10, %rdi
movq %r9, %r14
callq 0x21b0
movl (%rbx,%r14,4), %eax
jmp 0x3761
orl $-0x1, 0xa288(%rip)     # 0xd970
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xa27f(%rip)      # 0xd978
andl $0x0, 0xa280(%rip)      # 0xd980
movl 0x88(%rsp), %eax
subl 0xa283(%rip), %eax      # 0xd990
movl %eax, 0xa271(%rip)      # 0xd984
pushq $-0x2
jmp 0x3760
movq $0x1, 0xa24e(%rip) # 0xd970
movl 0x88(%rsp), %eax
movq %rax, %rcx
subl (%rdx,%r9,4), %eax
movl %eax, 0xa242(%rip)      # 0xd978
movl $0x1, 0xa23c(%rip)      # 0xd97c
subl (%rdx,%r9,4), %ecx
movl %ecx, 0xa236(%rip)      # 0xd980
movl (%rdx,%r9,4), %eax
subl 0xa23c(%rip), %eax      # 0xd990
movl %eax, 0xa22a(%rip)      # 0xd984
pushq $-0x1
jmp 0x3760
pushq $-0x63
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq