// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x28(%rbp), %eax
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)
movq %r9, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movl 0x20(%rbp), %eax
shll $0x2, %eax
addl $0x4, %eax
movslq %eax, %rdi
callq 0x21a0
movq %rax, -0x40(%rbp)
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0xffffffff, 0xa8e0(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0xa8de(%rip)      # 0xd650
movl 0x18(%rbp), %eax
addl 0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x18(%rbp), %eax
jle 0x2eee
movq 0xa98f(%rip), %rax      # 0xd720
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 0xa96d(%rip), %rax      # 0xd720
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0xa95a(%rip), %rcx      # 0xd720
movslq -0x54(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x2dd6
movl $0x0, -0x48(%rbp)
movq 0xa943(%rip), %rax      # 0xd720
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0xa930(%rip), %rcx      # 0xd720
movslq -0x54(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x2ed7
cmpl $0x0, -0x48(%rbp)
jne 0x2e9b
movq -0x28(%rbp), %rax
movslq 0x28(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x2e35
movl -0x50(%rbp), %edx
movq -0x28(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2e99
movl -0x50(%rbp), %ecx
subl $0x1, %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x54(%rbp), %edx
movl -0x50(%rbp), %ecx
movl 0x28(%rbp), %r8d
callq 0x25e0
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 0x2e81
movl $0xffffff9d, -0x4(%rbp) # imm = 0xFFFFFF9D
jmp 0x3069
movq -0x30(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x50(%rbp)
jmp 0x2e9b
cmpl $-0x1, -0x48(%rbp)
jne 0x2ed0
movl $0x1, 0xa79d(%rip)      # 0xd648
movq 0xa86e(%rip), %rax      # 0xd720
movl 0x18(%rbp), %ecx
addl 0x20(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xa785(%rip)      # 0xd64c
movl -0x50(%rbp), %eax
movl %eax, 0xa780(%rip)      # 0xd650
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 0x2d7e
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq 0xa822(%rip), %rax      # 0xd720
movslq 0x18(%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 0x2f4d
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0xa7ea(%rip), %rax      # 0xd720
movl 0x18(%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 0x2f17
movq -0x28(%rbp), %rax
movslq 0x28(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x2f9e
movl $0xffffffff, 0xa6cb(%rip) # imm = 0xFFFFFFFF
movl $0x0, 0xa6c9(%rip)      # 0xd638
movl $0x1, 0xa6c3(%rip)      # 0xd63c
movl $0x0, 0xa6bd(%rip)      # 0xd640
movl 0x20(%rbp), %eax
subl 0xa6c4(%rip), %eax      # 0xd650
movl %eax, 0xa6b2(%rip)      # 0xd644
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3069
movq -0x30(%rbp), %rax
movslq 0x28(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x3012
movl $0x1, 0xa67a(%rip)      # 0xd630
movl $0x0, 0xa674(%rip)      # 0xd634
movl 0x20(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq 0x28(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, 0xa664(%rip)      # 0xd638
movl $0x1, 0xa65e(%rip)      # 0xd63c
movl 0x20(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq 0x28(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, 0xa64e(%rip)      # 0xd640
movq -0x28(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl 0xa64d(%rip), %eax      # 0xd650
movl %eax, 0xa63b(%rip)      # 0xd644
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3069
movl 0x18(%rbp), %edx
movq -0x38(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %edx
movq -0x20(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x18(%rbp), %edx
movq -0x20(%rbp), %rax
movslq 0x28(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movq -0x30(%rbp), %rax
movslq 0x28(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movq 0x10(%rbp), %rax
movslq 0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x30(%rbp), %rax
movslq 0x28(%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)