// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %r9, 0x30(%rsp)
movq %r8, %r15
movq %rcx, (%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
movl 0xa0(%rsp), %r13d
movl 0x98(%rsp), %r14d
leal 0x4(,%r13,4), %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, %r9
movl $0xffffffff, 0x8cb0(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x8cae(%rip)      # 0xa640
leal (%r14,%r13), %ebx
decl %ebx
movslq 0xa8(%rsp), %r8
movslq %r14d, %r11
cmpl %r14d, %ebx
setg %r14b
jle 0x1abf
movq %r15, 0x20(%rsp)
movq 0x8d54(%rip), %r15      # 0xa710
movslq %ebx, %r13
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r13, 0x50(%rsp)
xorl %ecx, %ecx
xorl %r12d, %r12d
movq (%rsp), %rdi
movq %r8, 0x18(%rsp)
movq %r9, 0x38(%rsp)
movq %r11, 0x10(%rsp)
movl (%r15,%r13,4), %edx
movslq %r12d, %rsi
movl %edx, (%r9,%rsi,4)
leal 0x1(%rcx), %r10d
movl %eax, %ebp
cmpl %edx, -0x4(%r15,%r13,4)
movl $0x0, %eax
cmovll %eax, %ebp
jle 0x1a60
testl %ebp, %ebp
jne 0x1a6b
cmpl $0x0, (%rdi,%r8,4)
je 0x1a64
subl %ecx, %r12d
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl %ebx, %edx
movl %r10d, %ecx
movl 0xa8(%rsp), %r8d
movl %r10d, 0xc(%rsp)
callq 0x14d5
movq 0x38(%rsp), %r9
movslq %r12d, %rcx
movl %eax, (%r9,%rcx,4)
testl %eax, %eax
js 0x1be8
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %r8
incl (%rax,%r8,4)
xorl %r10d, %r10d
movq (%rsp), %rdi
movq 0x10(%rsp), %r11
jmp 0x1a6b
movl %ebp, %eax
jmp 0x1a95
movl %r10d, (%rdi,%r8,4)
xorl %r10d, %r10d
movl $0x1, %eax
cmpl $-0x1, %ebp
jne 0x1a95
movl $0x1, 0x8bb9(%rip)      # 0xa638
movq 0x50(%rsp), %rcx
movl (%r15,%rcx,4), %ecx
movl %ecx, 0x8bae(%rip)      # 0xa63c
movl %r10d, 0x8bab(%rip)     # 0xa640
decq %r13
incl %r12d
decl %ebx
movl %r10d, %ecx
cmpq %r11, %r13
setg %r14b
jg 0x19e1
incl %r10d
movq 0x20(%rsp), %r15
movl 0xa0(%rsp), %r13d
jmp 0x1acc
xorl %r12d, %r12d
movl $0x1, %r10d
movq (%rsp), %rdi
movl $0xffffff9d, %eax       # imm = 0xFFFFFF9D
testb $0x1, %r14b
jne 0x1bd9
movq 0x8c2e(%rip), %rax      # 0xa710
movl (%rax,%r11,4), %ecx
movslq %r12d, %rdx
movl %ecx, (%r9,%rdx,4)
testl %edx, %edx
js 0x1b12
movl %r12d, %ecx
incl %r12d
leaq (%rax,%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, %r12
jne 0x1b01
cmpl $0x0, (%rdi,%r8,4)
je 0x1b5d
cmpl $0x0, (%r15,%r8,4)
je 0x1b97
movq 0x90(%rsp), %rax
movq 0x30(%rsp), %rcx
movl 0x98(%rsp), %edx
movl %edx, (%rcx,%r8,4)
movq 0x28(%rsp), %rcx
movl %r10d, (%rcx,%r8,4)
addl %edx, %r10d
addl (%r15,%r8,4), %r10d
movl %r10d, (%rax,%r8,4)
movq %r9, %rdi
movq %r8, %rbx
callq 0x1140
movl (%r15,%rbx,4), %eax
jmp 0x1bd9
movl $0xffffffff, 0x8ab9(%rip) # imm = 0xFFFFFFFF
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x8ab0(%rip)      # 0xa628
movl $0x0, 0x8aae(%rip)      # 0xa630
subl 0x8ab7(%rip), %r13d     # 0xa640
movl %r13d, 0x8aa4(%rip)     # 0xa634
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x1bd9
movq $0x1, 0x8a7e(%rip) # 0xa620
movl %r13d, %eax
subl (%rdi,%r8,4), %eax
movl %eax, 0x8a79(%rip)      # 0xa628
movl $0x1, 0x8a73(%rip)      # 0xa62c
subl (%rdi,%r8,4), %r13d
movl %r13d, 0x8a6c(%rip)     # 0xa630
movl (%rdi,%r8,4), %eax
subl 0x8a72(%rip), %eax      # 0xa640
movl %eax, 0x8a60(%rip)      # 0xa634
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rdi
movq 0x18(%rsp), %r8
movl 0xc(%rsp), %r10d
movq 0x10(%rsp), %r11
jmp 0x1aad