// File: /workspace/github_c_makefile_star2_O2/felipelouza[P]egap/tools/src/gsacak.c
// Function: induceSAl1
void induceSAl1(int_t *SA, int_t *s, 
  int_t n, int_t suffix, int cs) {
  int_t h, i, j, step=1;
  
  for(i=0; i<n; i+=step) {
    step=1; j=SA[i]-1;
    if(SA[i]<=0) continue;
    int_t c=chr(j), c1=chr(j+1);
    int_t isL=c>=c1;
    if(!isL) continue;

    // s[j] is L-type.

    int_t d=SA[c];
    if(d>=0) {
      // SA[c] is borrowed by the left
      //   neighbor bucket.
      // shift-left the items in the
      //   left neighbor bucket.
      int_t foo, bar;
      foo=SA[c];
      for(h=c-1; SA[h]>=0||SA[h]==EMPTY_k; h--)
      { bar=SA[h]; SA[h]=foo; foo=bar; }
      SA[h]=foo;
      if(h<i) step=0;

      d=EMPTY_k;
    }

    if(d==EMPTY_k) { // SA[c] is empty.
      if(c<n-1 && SA[c+1]==EMPTY_k) {
        SA[c]=-1; // init the counter.
        SA[c+1]=j;
      }
      else        
        SA[c]=j; // a size-1 bucket.
    }
    else { // SA[c] is reused as a counter.
        int_t pos=c-d+1;
        if(pos>n-1 || SA[pos]!=EMPTY_k) {
          // we are running into the right
          //   neighbor bucket.
          // shift-left one step the items
          //   of bucket(SA, S, j).
          for(h=0; h<-d; h++)
            SA[c+h]=SA[c+h+1];
          pos--;
          if(c<i) step=0;
        }
        else
          SA[c]--;

        SA[pos]=j;
    }

    int_t c2;
    int_t isL1=(j+1<n-1) && (c1>(c2=chr(j+2)) || (c1==c2 && c1<i));  // is s[SA[i]] L-type?
    if((!suffix || !isL1) && i>0) {
      int_t i1=(step==0)?i-1:i;
      SA[i1]=EMPTY_k;
    }
  }

  // scan to shift-left the items in each bucket 
  //   with its head being reused as a counter.
  for(i=1; i<n; i++) {
    j=SA[i];
    if(j<0 && j!=EMPTY_k) { // is SA[i] a counter?
      for(h=0; h<-j; h++)
        SA[i+h]=SA[i+h+1];
      SA[i+h]=EMPTY_k;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, -0x8(%rsp)
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
leaq -0x1(%rdx), %rcx
movq %rcx, -0x18(%rsp)
leaq 0x8(%rdi), %rcx
movq %rcx, -0x10(%rsp)
xorl %r11d, %r11d
movabsq $0x1, %rbx
leaq 0x1(%rax), %r14
cmpq %rdx, %r11
jge 0x7816
movq (%rdi,%r11,8), %r15
movq %rbx, %r13
testq %r15, %r15
jle 0x780e
cmpl $0x8, %r8d
jne 0x76d8
movq -0x8(%rsi,%r15,8), %rbp
movq (%rsi,%r15,8), %r12
jmp 0x76e3
movzbl -0x1(%rsi,%r15), %ebp
movzbl (%rsi,%r15), %r12d
movq %rbx, %r13
cmpq %r12, %rbp
jl 0x780e
leaq (%rdi,%rbp,8), %r10
movq (%r10), %r9
testq %r9, %r9
js 0x7720
leaq 0x1(%rbp), %rcx
movq -0x10(%rdi,%rcx,8), %r13
movq %r9, -0x10(%rdi,%rcx,8)
decq %rcx
movq %r13, %r9
cmpq %r14, %r13
jb 0x76ff
xorl %r13d, %r13d
cmpq %r11, %rcx
setg %r13b
jmp 0x7732
movq %rbx, %r13
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmpq %rax, %r9
jne 0x7753
cmpq -0x18(%rsp), %rbp
jge 0x77a5
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmpq %rax, 0x8(%r10)
jne 0x77a5
orq $-0x1, (%r10)
addq $0x8, %r10
jmp 0x77a5
movq %rbp, %rcx
subq %r9, %rcx
cmpq -0x18(%rsp), %rcx
jge 0x7775
cmpq %rax, 0x8(%rdi,%rcx,8)
jne 0x7775
incq %rcx
decq %r9
movq %r9, (%r10)
movq %rbx, %r13
jmp 0x77a1
negq %r9
movq -0x10(%rsp), %rax
leaq (%rax,%rbp,8), %r10
xorl %r13d, %r13d
cmpq %r13, %r9
je 0x7797
movq (%r10,%r13,8), %rax
movq %rax, -0x8(%r10,%r13,8)
incq %r13
jmp 0x7784
xorl %r13d, %r13d
cmpq %r11, %rbp
setge %r13b
leaq (%rdi,%rcx,8), %r10
leaq -0x1(%r15), %rax
movq %rax, (%r10)
cmpq -0x18(%rsp), %r15
jge 0x77c0
cmpl $0x8, %r8d
jne 0x77c4
movq 0x8(%rsi,%r15,8), %r9
jmp 0x77ca
xorl %ecx, %ecx
jmp 0x77dc
movzbl 0x1(%rsi,%r15), %r9d
movb $0x1, %cl
cmpq %r9, %r12
jg 0x77dc
sete %al
cmpq %r11, %r12
setl %cl
andb %al, %cl
cmpq $0x0, -0x8(%rsp)
setne %r9b
testq %r11, %r11
jle 0x780e
andb %cl, %r9b
jne 0x780e
leaq (%rdi,%r11,8), %rax
cmpq $0x1, %r13
movl $0x0, %ecx
sbbq %rcx, %rcx
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
movq %r9, (%rax,%rcx,8)
addq %r13, %r11
jmp 0x76ae
leaq 0x10(%rdi), %rcx
movabsq $0x1, %rsi
movabsq $-0x8000000000000000, %r11 # imm = 0x8000000000000000
cmpq %rdx, %rsi
jge 0x7866
movq (%rdi,%rsi,8), %r8
cmpq %r11, %r8
jbe 0x785d
leaq (%rdi,%rsi,8), %r9
negq %r8
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x7859
movq (%rcx,%r10,8), %rax
movq %rax, -0x8(%rcx,%r10,8)
incq %r10
jmp 0x7846
movq %r11, (%r9,%r8,8)
incq %rsi
addq $0x8, %rcx
jmp 0x782e
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq