// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movl %r9d, %r15d
movq %r8, 0x40(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, %r14
movq %rsi, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movl 0x98(%rsp), %ebx
leal 0x4(,%rbx,4), %eax
movslq %eax, %rdi
callq 0x21b0
movq %rax, %r9
movl $0xffffffff, 0xb082(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0xb080(%rip)      # 0xe980
addl %r15d, %ebx
decl %ebx
movslq 0xa0(%rsp), %r8
movslq %r15d, %r11
movq %r15, 0x38(%rsp)
cmpl %r15d, %ebx
setg %r12b
jle 0x3a21
movq %r14, 0x20(%rsp)
movslq %ebx, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r14, 0x50(%rsp)
xorl %ecx, %ecx
xorl %r15d, %r15d
movq 0x8(%rsp), %r10
movq 0x90(%rsp), %rdi
movq %r8, 0x18(%rsp)
movq %r9, 0x48(%rsp)
movq %r11, 0x10(%rsp)
movl (%rdi,%r14,4), %edx
movslq %r15d, %rsi
movl %edx, (%r9,%rsi,4)
leal 0x1(%rcx), %ebp
movl %eax, %r13d
cmpl %edx, -0x4(%rdi,%r14,4)
movl $0x0, %eax
cmovll %eax, %r13d
jle 0x39cd
testl %r13d, %r13d
jne 0x39d8
cmpl $0x0, (%r10,%r8,4)
je 0x39d2
subl %ecx, %r15d
movl %ebx, %esi
movl %ebp, %edx
movl 0xa0(%rsp), %ecx
callq 0x3404
movq 0x48(%rsp), %r9
movslq %r15d, %rcx
movl %eax, (%r9,%rcx,4)
testl %eax, %eax
js 0x3b53
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %r8
incl (%rax,%r8,4)
xorl %ebp, %ebp
movq 0x8(%rsp), %r10
movq 0x90(%rsp), %rdi
movq 0x10(%rsp), %r11
jmp 0x39d8
movl %r13d, %eax
jmp 0x3a01
movl %ebp, (%r10,%r8,4)
xorl %ebp, %ebp
movl $0x1, %eax
cmpl $-0x1, %r13d
jne 0x3a01
movl $0x1, 0xaf8b(%rip)      # 0xe978
movq 0x50(%rsp), %rcx
movl (%rdi,%rcx,4), %ecx
movl %ecx, 0xaf81(%rip)      # 0xe97c
movl %ebp, 0xaf7f(%rip)      # 0xe980
incl %r15d
decq %r14
decl %ebx
movl %ebp, %ecx
cmpq %r11, %r14
setg %r12b
jg 0x3955
incl %ebp
movq 0x20(%rsp), %r14
jmp 0x3a36
xorl %r15d, %r15d
movl $0x1, %ebp
movq 0x8(%rsp), %r10
movq 0x90(%rsp), %rdi
movl $0xffffff9d, %eax       # imm = 0xFFFFFF9D
testb $0x1, %r12b
jne 0x3b44
movl (%rdi,%r11,4), %eax
movslq %r15d, %rcx
movl %eax, (%r9,%rcx,4)
testl %ecx, %ecx
js 0x3a75
movl %r15d, %ecx
incl %r15d
leaq (%rdi,%r11,4), %rax
leaq (%r9,%rcx,4), %rcx
xorl %edx, %edx
movl (%rcx), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
addq $-0x4, %rcx
cmpq %rdx, %r15
jne 0x3a64
cmpl $0x0, (%r10,%r8,4)
je 0x3abd
cmpl $0x0, (%r14,%r8,4)
je 0x3afc
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movl %eax, (%rcx,%r8,4)
movq 0x28(%rsp), %rcx
movl %ebp, (%rcx,%r8,4)
addl %eax, %ebp
addl (%r14,%r8,4), %ebp
movq 0x40(%rsp), %rax
movl %ebp, (%rax,%r8,4)
movq %r9, %rdi
movq %r8, %rbx
callq 0x2190
movl (%r14,%rbx,4), %eax
jmp 0x3b44
movl $0xffffffff, 0xae99(%rip) # imm = 0xFFFFFFFF
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xae90(%rip)      # 0xe968
movl $0x0, 0xae8e(%rip)      # 0xe970
movl 0x98(%rsp), %eax
subl 0xae91(%rip), %eax      # 0xe980
movl %eax, 0xae7f(%rip)      # 0xe974
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x3b44
movq $0x1, 0xae59(%rip) # 0xe960
movl 0x98(%rsp), %eax
movq %rax, %rcx
subl (%r10,%r8,4), %eax
movl %eax, 0xae4d(%rip)      # 0xe968
movl $0x1, 0xae47(%rip)      # 0xe96c
subl (%r10,%r8,4), %ecx
movl %ecx, 0xae41(%rip)      # 0xe970
movl (%r10,%r8,4), %eax
subl 0xae47(%rip), %eax      # 0xe980
movl %eax, 0xae35(%rip)      # 0xe974
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %r10
movq 0x18(%rsp), %r8
movq 0x90(%rsp), %rdi
movq 0x10(%rsp), %r11
jmp 0x3a18