// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0x0, -0x44(%rbp)
movl 0x18(%rbp), %eax
shll $0x2, %eax
addl $0x4, %eax
movslq %eax, %rdi
callq 0x21f0
movq %rax, -0x40(%rbp)
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0xffffffff, 0xd593(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0xd591(%rip)      # 0x11990
movl -0x34(%rbp), %eax
addl 0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x4564
movq 0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq 0x10(%rbp), %rax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x10(%rbp), %rcx
movslq -0x54(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x445a
movl $0x0, -0x48(%rbp)
movq 0x10(%rbp), %rax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x10(%rbp), %rcx
movslq -0x54(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x454d
cmpl $0x0, -0x48(%rbp)
jne 0x4514
movq -0x18(%rbp), %rax
movslq 0x20(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x44b3
movl -0x50(%rbp), %edx
movq -0x18(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4512
movl -0x50(%rbp), %ecx
subl $0x1, %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
movq 0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
movl -0x50(%rbp), %edx
movl 0x20(%rbp), %ecx
callq 0x3f00
movl %eax, %edx
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jge 0x44fa
movl $0xffffff9d, -0x4(%rbp) # imm = 0xFFFFFF9D
jmp 0x46d9
movq -0x20(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x50(%rbp)
jmp 0x4514
cmpl $-0x1, -0x48(%rbp)
jne 0x4546
movl $0x1, 0xd464(%rip)      # 0x11988
movq 0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
addl 0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xd44f(%rip)      # 0x1198c
movl -0x50(%rbp), %eax
movl %eax, 0xd44a(%rip)      # 0x11990
movl $0x1, -0x48(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x440b
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq 0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jg 0x45bd
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x10(%rbp), %rax
movl -0x34(%rbp), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x458a
movq -0x18(%rbp), %rax
movslq 0x20(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x460e
movl $0xffffffff, 0xd39b(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0xd399(%rip)      # 0x11978
movl $0x1, 0xd393(%rip)      # 0x1197c
movl $0x0, 0xd38d(%rip)      # 0x11980
movl 0x18(%rbp), %eax
subl 0xd394(%rip), %eax      # 0x11990
movl %eax, 0xd382(%rip)      # 0x11984
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x46d9
movq -0x20(%rbp), %rax
movslq 0x20(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x4682
movl $0x1, 0xd34a(%rip)      # 0x11970
movl $0x0, 0xd344(%rip)      # 0x11974
movl 0x18(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq 0x20(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, 0xd334(%rip)      # 0x11978
movl $0x1, 0xd32e(%rip)      # 0x1197c
movl 0x18(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq 0x20(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, 0xd31e(%rip)      # 0x11980
movq -0x18(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl 0xd31d(%rip), %eax      # 0x11990
movl %eax, 0xd30b(%rip)      # 0x11984
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x46d9
movl -0x34(%rbp), %edx
movq -0x28(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %edx
movq -0x10(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %edx
movq -0x10(%rbp), %rax
movslq 0x20(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
movslq 0x20(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movq -0x30(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rdi
callq 0x21d0
movq -0x20(%rbp), %rax
movslq 0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)