// File: /workspace/github_c_makefile_star2_O1/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, %rbp # imm = 0x8000000000000000
testq %rdx, %rdx
jle 0x8234
leaq -0x1(%rdx), %rax
movq %rax, -0x20(%rsp)
leaq 0x8(%rdi), %rax
movq %rax, -0x10(%rsp)
leaq 0x1(%rbp), %rbx
xorl %r14d, %r14d
movl %r8d, -0x24(%rsp)
movq %rsi, -0x18(%rsp)
movq (%rdi,%r14,8), %r12
movl $0x1, %r15d
testq %r12, %r12
jle 0x8228
leaq -0x1(%r12), %rax
cmpl $0x8, %r8d
jne 0x80ca
movq -0x8(%rsi,%r12,8), %r11
jmp 0x80cf
movzbl (%rsi,%rax), %r11d
cmpl $0x8, %r8d
jne 0x80db
movq (%rsi,%r12,8), %r13
jmp 0x80e0
movzbl (%rsi,%r12), %r13d
cmpq %r13, %r11
jl 0x8228
movq (%rdi,%r11,8), %r10
testq %r10, %r10
js 0x813c
movq %rax, %rsi
leaq (%rdi,%r11,8), %rcx
addq $-0x8, %rcx
movq (%rcx), %r15
cmpq %rbx, %r15
jae 0x8123
movq %r11, %r9
movq %r15, %rax
movq %r10, (%rcx)
movq -0x8(%rcx), %r15
addq $-0x8, %rcx
decq %r9
movq %rax, %r10
cmpq %rbx, %r15
jb 0x8108
jmp 0x8129
movq %r10, %rax
movq %r11, %r9
movq %rax, (%rcx)
xorl %r15d, %r15d
cmpq %r14, %r9
setg %r15b
movq %rbp, %r10
movq %rsi, %rax
leaq (%rdi,%r11,8), %r9
cmpq %rbp, %r10
jne 0x815f
cmpq -0x20(%rsp), %r11
jge 0x81bb
cmpq %rbp, 0x8(%r9)
jne 0x81bb
movq $-0x1, (%r9)
addq $0x8, %r9
jmp 0x81bb
movq %r11, %rcx
subq %r10, %rcx
cmpq -0x20(%rsp), %rcx
jge 0x817b
cmpq %rbp, 0x8(%rdi,%rcx,8)
jne 0x817b
incq %rcx
decq (%r9)
jmp 0x81b7
movq %rax, %rsi
negq %r10
movq -0x10(%rsp), %rax
leaq (%rax,%r11,8), %rax
xorl %r9d, %r9d
movq (%rax,%r9,8), %rbp
movq %rbp, -0x8(%rax,%r9,8)
incq %r9
cmpq %r9, %r10
jne 0x818d
cmpq %r14, %r11
movl $0x0, %eax
cmovlq %rax, %r15
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
movq %rsi, %rax
leaq (%rdi,%rcx,8), %r9
movq %rax, (%r9)
cmpq -0x20(%rsp), %r12
jge 0x81dc
movl -0x24(%rsp), %r8d
cmpl $0x8, %r8d
movq -0x18(%rsp), %rsi
jne 0x81ea
movq 0x8(%rsi,%r12,8), %rcx
jmp 0x81f0
xorl %eax, %eax
movl -0x24(%rsp), %r8d
movq -0x18(%rsp), %rsi
jmp 0x8202
movzbl 0x1(%rsi,%r12), %ecx
movb $0x1, %al
cmpq %rcx, %r13
jg 0x8202
sete %cl
cmpq %r14, %r13
setl %al
andb %cl, %al
cmpq $0x0, -0x8(%rsp)
setne %cl
testq %r14, %r14
jle 0x8228
andb %al, %cl
jne 0x8228
leaq (%rdi,%r14,8), %rax
cmpq $0x1, %r15
movl $0x0, %ecx
sbbq %rcx, %rcx
movq %rbp, (%rax,%rcx,8)
addq %r15, %r14
cmpq %rdx, %r14
jl 0x80a5
cmpq $0x2, %rdx
jl 0x8273
leaq 0x8(%rdi), %rax
movl $0x1, %ecx
movq (%rdi,%rcx,8), %rsi
cmpq %rbp, %rsi
jbe 0x8267
negq %rsi
xorl %r8d, %r8d
movq 0x8(%rax,%r8,8), %r9
movq %r9, (%rax,%r8,8)
incq %r8
cmpq %r8, %rsi
jne 0x8252
movq %rbp, (%rax,%r8,8)
incq %rcx
addq $0x8, %rax
cmpq %rdx, %rcx
jne 0x8243
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq