// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rcx, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
movl 0x90(%rsp), %ebp
movl 0x88(%rsp), %ebx
leal 0x4(,%rbp,4), %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, %r10
movl $0xffffffff, 0x8d7b(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0x8d79(%rip)      # 0xa640
leal (%rbx,%rbp), %eax
decl %eax
movq 0x8e3d(%rip), %r15      # 0xa710
movslq 0x98(%rsp), %r13
cmpl %ebx, %eax
jle 0x19cc
movq %r12, 0x10(%rsp)
movslq %eax, %r12
movslq %ebx, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r11d, %r11d
movq %r12, 0x40(%rsp)
xorl %eax, %eax
xorl %r14d, %r14d
movq 0x8(%rsp), %r8
movq %r10, 0x28(%rsp)
movl (%r15,%r12,4), %esi
movslq %r14d, %rcx
movl %esi, (%r10,%rcx,4)
leal 0x1(%rax), %ecx
movl %ebp, %edx
cmpl %esi, -0x4(%r15,%r12,4)
cmovll %r11d, %edx
jle 0x1987
movl $0x1, %ebp
cmpl $-0x1, %edx
je 0x198b
testl %edx, %edx
jne 0x19aa
cmpl $0x0, (%r8,%r13,4)
je 0x19c1
subl %eax, %r14d
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl %r12d, %edx
movl 0x98(%rsp), %r8d
callq 0x14d5
movq 0x28(%rsp), %r10
movslq %r14d, %rcx
movl %eax, (%r10,%rcx,4)
testl %eax, %eax
js 0x1af1
movq 0x10(%rsp), %rax
incl (%rax,%r13,4)
xorl %eax, %eax
movl %r14d, %edx
movq 0x8(%rsp), %r8
xorl %r11d, %r11d
jmp 0x19af
movl %edx, %ebp
jmp 0x19aa
movl $0x1, 0x8ca3(%rip)      # 0xa638
movq 0x40(%rsp), %rax
movl (%r15,%rax,4), %eax
movl %eax, 0x8c98(%rip)      # 0xa63c
movl %ecx, 0x8c96(%rip)      # 0xa640
movl %r14d, %edx
movl %ecx, %eax
decq %r12
leal 0x1(%rdx), %r14d
cmpq %rbx, %r12
jg 0x190a
jmp 0x19e7
movl %ecx, (%r8,%r13,4)
xorl %eax, %eax
movl %r14d, %edx
jmp 0x19af
movslq %ebx, %rbx
movl (%r15,%rbx,4), %eax
movl %eax, (%r10)
xorl %ecx, %ecx
movl $0x1, %eax
xorl %r14d, %r14d
movq 0x8(%rsp), %r8
jmp 0x1a05
incl %eax
movl (%r15,%rbx,4), %esi
movslq %r14d, %rcx
movl %esi, (%r10,%rcx,4)
cmpl $-0x1, %edx
movq 0x10(%rsp), %r12
movl 0x90(%rsp), %ebp
jl 0x1a23
incl %r14d
leaq (%r15,%rbx,4), %rdx
leaq (%r10,%rcx,4), %rcx
xorl %esi, %esi
movl (%rcx), %edi
movl %edi, (%rdx,%rsi,4)
incq %rsi
addq $-0x4, %rcx
cmpq %rsi, %r14
jne 0x1a12
cmpl $0x0, (%r8,%r13,4)
je 0x1a6a
cmpl $0x0, (%r12,%r13,4)
je 0x1aa2
movq 0x80(%rsp), %rcx
movq 0x20(%rsp), %rdx
movl 0x88(%rsp), %esi
movl %esi, (%rdx,%r13,4)
movq 0x18(%rsp), %rdx
movl %eax, (%rdx,%r13,4)
addl %esi, %eax
addl (%r12,%r13,4), %eax
movl %eax, (%rcx,%r13,4)
movq %r10, %rdi
callq 0x1140
movl (%r12,%r13,4), %eax
jmp 0x1ae2
movl $0xffffffff, 0x8bac(%rip) # imm = 0xFFFFFFFF
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x8ba3(%rip)      # 0xa628
movl $0x0, 0x8ba1(%rip)      # 0xa630
subl 0x8bab(%rip), %ebp      # 0xa640
movl %ebp, 0x8b99(%rip)      # 0xa634
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x1ae2
movq $0x1, 0x8b73(%rip) # 0xa620
movl %ebp, %eax
subl (%r8,%r13,4), %eax
movl %eax, 0x8b6f(%rip)      # 0xa628
movl $0x1, 0x8b69(%rip)      # 0xa62c
subl (%r8,%r13,4), %ebp
movl %ebp, 0x8b63(%rip)      # 0xa630
movl (%r8,%r13,4), %eax
subl 0x8b69(%rip), %eax      # 0xa640
movl %eax, 0x8b57(%rip)      # 0xa634
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffff9d, %eax       # imm = 0xFFFFFF9D
jmp 0x1ae2