// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]lyndon-array/lib/bwt.c
// Function: bwt_lyndon_suffix_order
int bwt_lyndon_suffix_order(char *T, int_t *LA, int n){

int p, r=1;
int i, s;

int_t size=1;
//base cases
LA[n-2]=size++;
LA[n-1]=size++;

for(s=n-3; s>=0; s--){

  /*steps 1 and 2*/
  p=r+1;
  for(i=s+1, r=0; T[i]!=0; i++)if(T[i]<=T[s])r++;
  for(; i<n; i++) if(T[i]<T[s])r++;
  
  T[p+s] = T[s]; //replace('$', T[s]);

  for(i=s; i<s+r; i++){
    T[i] = T[i+1];
    LA[i] = LA[i+1];
  }

  T[s+r] = 0; //END_MARKER;
  LA[s+r]=size++;
}

for(i=n-1; i>0; i--){
  int_t max=0;
  for(s=i-1; s>=0; s--){
    if(LA[s]<LA[i] && LA[s]>max) max = LA[s];
  }
  LA[i]-=max;
}

return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x5147
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x5062
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jg 0x5055
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5057
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x501f
jmp 0x5064
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x509e
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jge 0x5091
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5093
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x5064
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x24(%rbp), %ecx
addl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x510d
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x50bf
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x28(%rbp), %edx
movl %edx, %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4ffc
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x51cd
movl $0x0, -0x2c(%rbp)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x51af
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movslq -0x20(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x51a2
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x2c(%rbp), %eax
jle 0x51a2
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
jmp 0x51a4
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5166
movl -0x2c(%rbp), %esi
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x5150
xorl %eax, %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)