// File: /workspace/github_c_makefile_star2_O3/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)
testq %rdx, %rdx
jle 0x801c
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
leaq -0x1(%rdx), %r10
leaq 0x8(%rdi), %rax
movq %rax, -0x10(%rsp)
xorl %r11d, %r11d
leaq 0x1(%r13), %rbx
movq %r10, -0x18(%rsp)
movq (%rdi,%r11,8), %r15
movl $0x1, %r12d
testq %r15, %r15
jle 0x7fcd
cmpl $0x8, %r8d
jne 0x7e87
movq -0x8(%rsi,%r15,8), %rcx
movq (%rsi,%r15,8), %r14
jmp 0x7e92
movzbl -0x1(%rsi,%r15), %ecx
movzbl (%rsi,%r15), %r14d
cmpq %r14, %rcx
jl 0x7fcd
leaq (%rdi,%rcx,8), %rbp
movq (%rbp), %r9
testq %r9, %r9
js 0x7ed6
leaq (%rdi,%rcx,8), %rax
addq $-0x8, %rax
movq (%rax), %r12
cmpq %rbx, %r12
jae 0x7ef9
movq %rcx, %r13
movq %r12, %r10
movq %r9, (%rax)
movq -0x8(%rax), %r12
addq $-0x8, %rax
decq %r13
movq %r10, %r9
cmpq %rbx, %r12
jb 0x7ebb
jmp 0x7eff
cmpq %r13, %r9
je 0x7f1b
movq %rcx, %rax
subq %r9, %rax
cmpq %r10, %rax
jge 0x7f34
cmpq %r13, 0x8(%rdi,%rax,8)
jne 0x7f34
incq %rax
decq %r9
movq %r9, (%rbp)
jmp 0x7f6d
movq %r9, %r10
movq %rcx, %r13
movq %r10, (%rax)
xorl %r12d, %r12d
cmpq %r11, %r13
setg %r12b
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movq -0x18(%rsp), %r10
cmpq %r10, %rcx
jge 0x7f71
cmpq %r13, 0x8(%rbp)
jne 0x7f71
movq $-0x1, (%rbp)
addq $0x8, %rbp
jmp 0x7f71
negq %r9
movq -0x10(%rsp), %r10
leaq (%r10,%rcx,8), %r10
xorl %r12d, %r12d
movq (%r10,%r12,8), %r13
movq %r13, -0x8(%r10,%r12,8)
incq %r12
cmpq %r12, %r9
jne 0x7f43
xorl %r12d, %r12d
cmpq %r11, %rcx
setge %r12b
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movq -0x18(%rsp), %r10
leaq (%rdi,%rax,8), %rbp
leaq -0x1(%r15), %rax
movq %rax, (%rbp)
cmpq %r10, %r15
jge 0x7f8b
cmpl $0x8, %r8d
jne 0x7f8f
movq 0x8(%rsi,%r15,8), %rcx
jmp 0x7f95
xorl %eax, %eax
jmp 0x7fa7
movzbl 0x1(%rsi,%r15), %ecx
movb $0x1, %al
cmpq %rcx, %r14
jg 0x7fa7
sete %cl
cmpq %r11, %r14
setl %al
andb %cl, %al
cmpq $0x0, -0x8(%rsp)
setne %cl
testq %r11, %r11
jle 0x7fcd
andb %al, %cl
jne 0x7fcd
leaq (%rdi,%r11,8), %rax
cmpq $0x1, %r12
movl $0x0, %ecx
sbbq %rcx, %rcx
movq %r13, (%rax,%rcx,8)
addq %r12, %r11
cmpq %rdx, %r11
jl 0x7e63
cmpq $0x1, %rdx
je 0x801c
leaq 0x10(%rdi), %rax
movl $0x1, %esi
movq (%rdi,%rsi,8), %rcx
cmpq %r13, %rcx
jbe 0x8010
leaq (%rdi,%rsi,8), %r8
negq %rcx
xorl %r9d, %r9d
movq (%rax,%r9,8), %r10
movq %r10, -0x8(%rax,%r9,8)
incq %r9
cmpq %r9, %rcx
jne 0x7ffb
movq %r13, (%r8,%rcx,8)
incq %rsi
addq $0x8, %rax
cmpq %rdx, %rsi
jne 0x7fe8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq