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

  int i, p, r=1, s;
  int p_a1, p_b1, l_a, l_b;
  LCP[n-1] = LCP[n-2] = 0;//base case

  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++; //END_MARKER
    for(; i<n; i++) if(T[i]<T[s])r++;
    
    /*steps 2'*/
    p_a1=p+s-1;
    l_a=LCP[p_a1+1];
    while(T[p_a1]!=T[s])//RMQ function
      if(LCP[p_a1--]<l_a) l_a=LCP[p_a1+1];
    if(p_a1==s) l_a=0;
    else l_a++;
    
    /*steps 2''*/
    p_b1=p+s+1;
    l_b=LCP[p_b1];
    while(T[p_b1]!=T[s] && p_b1<n) //RMQ function
      if(LCP[++p_b1]<l_b) l_b=LCP[p_b1];
    if(p_b1==n) l_b=0;
    else l_b++;
    
    /*steps 3 and 4*/
    T[p+s]=T[s];
    for(i=s; i<s+r; i++){
      T[i]=T[i+1];
      LCP[i]=LCP[i+1];
    }
    T[s+r]=0; //END_MARKER;
    
    /*steps 4'*/
    LCP[s+r]=l_a;
    if(s+r+1<n)//If r+1 is not the last position
      LCP[s+r+1]=l_b;
    
    #if DEBUG
      printf("%c|%s\n", T[s], &T[s+1]);
      printf("lcp:\n");
      print_int(&LCP[s], n-s);
    #endif      
  }

return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x1, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movl -0xc(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x4f96
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x4d7d
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jg 0x4d70
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4d72
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4d3a
jmp 0x4d7f
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4db9
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jge 0x4dac
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4dae
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4d7f
movl -0x20(%rbp), %eax
addl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x8(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x4e23
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $-0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x34(%rbp), %eax
jge 0x4e21
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
jmp 0x4dd8
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x4e34
movl $0x0, -0x34(%rbp)
jmp 0x4e3d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
addl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rdx
movsbl (%rax,%rdx), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x39(%rbp)
je 0x4e84
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
setl %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x4e8d
jmp 0x4eb5
movq -0x18(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x30(%rbp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x38(%rbp), %eax
jge 0x4eb3
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
jmp 0x4e57
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x4ec6
movl $0x0, -0x38(%rbp)
jmp 0x4ecf
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
addl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x28(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x28(%rbp), %ecx
addl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4f3e
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4ef0
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x34(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl -0x24(%rbp), %eax
addl $0x1, %eax
cmpl -0xc(%rbp), %eax
jge 0x4f86
movl -0x38(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
addl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x4f88
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x4d17
xorl %eax, %eax
popq %rbp
retq
nopw (%rax,%rax)