// File: TooruAkagi[P]GCIS_Index/gcis_nep_build.cpp
// Function: purse(unsigned int*, int*, int*, long)
int purse(unsigned int *T,int *P,int *P_2,long int fsize){ //purse T and set P.
    std::cout << std::endl;
    int tn = -1; //temporary number
    int pn = 1;
    P[0] = 0;
    for (int i = 0 ; i < fsize-1 ; i++){
        if(T[i] > T[i+1]){ //T[i]がL 
            tn = i;
        }
        if(T[i] < T[i+1] && tn != -1){
            P[pn] = tn+1;
            P_2[pn-1] = P[pn] - P[pn-1];
            pn++;
            tn = -1;
        }
    }
    P[pn] = tn+1;
    P_2[pn-1] = fsize - P[pn-1]; //not to left last character
    
    int k = 0;
    for(int i = 0 ; i < fsize ; i++){
        if(P[k]==i){
            if(i+40 > fsize){printf("(%d,%d)",P[k],P_2[k]);}
            k++;
        }
        //if(i > fsize/2){exit(3);}
        if(i+40 > fsize){
            std::cout << std::hex << int(T[i]);
            std::cout << " ";
        }
    }
    return pn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq 0x46b9(%rip), %rdi      # 0x6fd8
movq 0x46a2(%rip), %rsi      # 0x6fc8
callq 0x2130
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jge 0x2a01
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jbe 0x2982
movl -0x2c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movl -0x2c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x29f1
cmpl $-0x1, -0x24(%rbp)
je 0x29f1
movl -0x24(%rbp), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
subl (%rax,%rcx,4), %edx
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
jmp 0x29f3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x294a
movl -0x24(%rbp), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl -0x28(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
subq %rcx, %rax
movl %eax, %edx
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movslq -0x34(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x2afa
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
jne 0x2aa3
movl -0x34(%rbp), %eax
addl $0x28, %eax
cltq
cmpq -0x20(%rbp), %rax
jle 0x2a9a
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x257d(%rip), %rdi      # 0x5010
movb $0x0, %al
callq 0x2030
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x28, %eax
cltq
cmpq -0x20(%rbp), %rax
jle 0x2aea
movq 0x4520(%rip), %rdi      # 0x6fd8
leaq 0x1021(%rip), %rsi      # 0x3ae0
callq 0x2070
movq %rax, %rdi
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x21d0
movq 0x44fa(%rip), %rdi      # 0x6fd8
leaq 0x27a3(%rip), %rsi      # 0x5288
callq 0x2110
jmp 0x2aec
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2a4a
movl -0x28(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)