// File: /workspace/github_cpp_makefile_star2_O2/TooruAkagi[P]GCIS_Index/gcis_nep_locate.cpp
// Function: ptrans(unsigned int*, int*, int*, int*, int*, int*, int*, int, int, int)
int ptrans(unsigned int *D,int *D_2,int *B1,int *B2,int *B3,int *Ls,int *Rs,int startm,int mrlen,int round){
    int *Rp; //generate transformed pattern and put it into Rp with reversed order.
    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];
        //printf("\n<[%d]%d>",B2[round],m[i]);
        len++;
        if(m[i-1] < m[i]){ //S*
            tn=0;
        }
        if(m[i-1] > m[i]){
            if(tn==0){ //m[i-1] & m[i] == L & S
                if(B2[round] == 0){B2[round] = len;len = 0;flag++;}
                else{
                    Rpptr-=(len-1);
                    Rp[Rpptr] = pscheck(D,D_2,i,len,round); 
                    //check whether corresponding purse exists in round[round] or not
                    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++){
        m[startm+i] = Rp[Rpptr-i];
        //printf("%d ",m[startm+i]);
    }
    //printf("\nB2 = %d,B3 = %d",B2[round],B3[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
movq %r9, 0x20(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movl 0x90(%rsp), %ebx
movl 0x88(%rsp), %r14d
leal 0x4(,%rbx,4), %eax
movslq %eax, %rdi
callq 0x1160
orl $-0x1, 0x7deb(%rip)     # 0x9638
movq %rax, %r10
andl $0x0, 0x7de9(%rip)      # 0x9640
leal (%r14,%rbx), %eax
decl %eax
movq 0x7eac(%rip), %rbp      # 0x9710
movslq %eax, %r12
movslq 0x98(%rsp), %r15
movslq %r14d, %r14
xorl %edi, %edi
pushq $-0x1
popq %rdx
pushq $0x1
popq %r13
movq %r12, 0x40(%rsp)
xorl %ebx, %ebx
xorl %eax, %eax
movq %r10, 0x28(%rsp)
movslq %ebx, %rcx
cmpq %r14, %r12
jle 0x193c
movl (%rbp,%r12,4), %esi
movl %esi, (%r10,%rcx,4)
leal 0x1(%rax), %ecx
cmpl %esi, -0x4(%rbp,%r12,4)
cmovll %edi, %edx
jle 0x1930
cmpl $-0x1, %edx
je 0x1906
testl %edx, %edx
jne 0x192d
movq 0x10(%rsp), %rdx
cmpl $0x0, (%rdx,%r15,4)
je 0x1927
subl %eax, %ebx
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %r12d, %edx
movl 0x98(%rsp), %r8d
callq 0x14c2
movq 0x28(%rsp), %r10
movslq %ebx, %rcx
movl %eax, (%r10,%rcx,4)
testl %eax, %eax
js 0x1a3b
movq 0x8(%rsp), %rax
incl (%rax,%r15,4)
xorl %ecx, %ecx
movl %r13d, %edx
xorl %edi, %edi
jmp 0x1930
movl $0x1, 0x7d28(%rip)      # 0x9638
movq 0x40(%rsp), %rax
movl (%rbp,%rax,4), %eax
movl %eax, 0x7d1d(%rip)      # 0x963c
movl %ecx, 0x7d1b(%rip)      # 0x9640
jmp 0x192d
movl %ecx, (%rdx,%r15,4)
xorl %ecx, %ecx
movl %r13d, %edx
incl %ebx
decq %r12
movl %ecx, %eax
jmp 0x1889
leaq (,%r14,4), %rdx
addq %rbp, %rdx
movl (%rdx), %esi
movl %esi, (%r10,%rcx,4)
leaq (%r10,%rcx,4), %rsi
xorl %edi, %edi
movq 0x8(%rsp), %rbx
cmpq %rcx, %rdi
jg 0x196d
movl (%rsi), %r8d
movl %r8d, (%rdx,%rdi,4)
incq %rdi
addq $-0x4, %rsi
jmp 0x1958
movq 0x10(%rsp), %rdx
cmpl $0x0, (%rdx,%r15,4)
je 0x19be
cmpl $0x0, (%rbx,%r15,4)
je 0x19f4
incl %eax
movq 0x20(%rsp), %rcx
movl 0x88(%rsp), %edx
movl %edx, (%rcx,%r15,4)
movq 0x18(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
addl %edx, %eax
addl (%rbx,%r15,4), %eax
movq 0x80(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
movq %r10, %rdi
callq 0x1140
movl (%rbx,%r15,4), %eax
jmp 0x1a3e
orl $-0x1, 0x7c5b(%rip)     # 0x9620
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x7c52(%rip)      # 0x9628
andl $0x0, 0x7c53(%rip)      # 0x9630
movl 0x90(%rsp), %eax
subl 0x7c56(%rip), %eax      # 0x9640
movl %eax, 0x7c44(%rip)      # 0x9634
pushq $-0x2
jmp 0x1a3d
movq $0x1, 0x7c21(%rip) # 0x9620
movl 0x90(%rsp), %eax
movq %rax, %rcx
subl (%rdx,%r15,4), %eax
movl %eax, 0x7c15(%rip)      # 0x9628
movl $0x1, 0x7c0f(%rip)      # 0x962c
subl (%rdx,%r15,4), %ecx
movl %ecx, 0x7c09(%rip)      # 0x9630
movl (%rdx,%r15,4), %eax
subl 0x7c0f(%rip), %eax      # 0x9640
movl %eax, 0x7bfd(%rip)      # 0x9634
pushq $-0x1
jmp 0x1a3d
pushq $-0x63
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq