// File: /workspace/github_c_makefile_star2_O2/felipelouza[P]egap/tools/src/gsacak.c
// Function: induceSAs1
void induceSAs1(int_t *SA, int_t *s, 
  int_t n, int_t suffix, int cs) {
  int_t h, i, j, step=1;
  
  for(i=n-1; i>0; i-=step) {
    step=1; j=SA[i]-1;
    if(SA[i]<=0) continue;
    int_t c=chr(j), c1=chr(j+1);
    int_t isS=(c<c1) || (c==c1 && c>i);
    if(!isS) continue;

    // s[j] is S-type

    int_t d=SA[c];
    if(d>=0) {
      // SA[c] is borrowed by the right
      //   neighbor bucket.
      // shift-right the items in the
      //   right 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(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(SA[pos]!=EMPTY_k) {
          // we are running into the left
          //   neighbor bucket.
          // shift-right 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;
    }

    if(!suffix) {
      int_t i1=(step==0)?i+1:i;
      SA[i1]=EMPTY_k;
    }
  }

  // scan to shift-right the items in each bucket
  //   with its head being reused as a counter.
  if(!suffix)
    for(i=n-1; i>0; 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 %rsi, %r10
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
movq %rdx, -0x8(%rsp)
leaq -0x1(%rdx), %r9
movq %rcx, %rdx
movabsq $0x1, %rcx
leaq 0x1(%rsi), %r11
movq %r9, %rbx
movq %rdx, -0x10(%rsp)
testq %rbx, %rbx
jle 0x79d6
movq (%rdi,%rbx,8), %r14
movq %rcx, %r12
testq %r14, %r14
jle 0x79ce
cmpl $0x8, %r8d
jne 0x78d4
movq -0x8(%r10,%r14,8), %r13
movq (%r10,%r14,8), %rax
jmp 0x78df
movzbl -0x1(%r10,%r14), %r13d
movzbl (%r10,%r14), %eax
cmpq %rax, %r13
jl 0x78fc
movq %rcx, %r12
cmpq %rbx, %r13
jle 0x79ce
movq %rcx, %r12
cmpq %rax, %r13
jne 0x79ce
leaq (%rdi,%r13,8), %r15
movq (%r15), %rbp
testq %rbp, %rbp
js 0x792c
decq %r13
movq 0x10(%rdi,%r13,8), %rax
movq %rbp, 0x10(%rdi,%r13,8)
incq %r13
movq %rax, %rbp
cmpq %r11, %rax
jb 0x790b
xorl %r12d, %r12d
cmpq %rbx, %r13
setl %r12b
jmp 0x7934
movq %rcx, %r12
cmpq %rsi, %rbp
jne 0x7944
cmpq %rsi, -0x8(%r15)
jne 0x799a
orq $-0x1, (%r15)
addq $-0x8, %r15
jmp 0x799a
movq %rbp, %rax
addq %r13, %rax
cmpq %rsi, -0x8(%rdi,%rax,8)
jne 0x7967
leaq -0x1(,%r13), %rax
addq %rbp, %rax
decq %rbp
movq %rbp, (%r15)
movq %rcx, %r12
jmp 0x7996
xorl %r12d, %r12d
cmpq %r12, %rbp
je 0x797d
movq -0x8(%r15,%r12,8), %rdx
movq %rdx, (%r15,%r12,8)
decq %r12
jmp 0x796a
xorl %r12d, %r12d
cmpq %rbx, %r13
setle %r12b
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
movq -0x10(%rsp), %rdx
leaq (%rdi,%rax,8), %r15
decq %r14
movq %r14, (%r15)
testq %rdx, %rdx
jne 0x79ce
leaq (%rdi,%rbx,8), %rax
xorl %edx, %edx
testq %r12, %r12
sete %dl
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
movq %r14, (%rax,%rdx,8)
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
movq -0x10(%rsp), %rdx
subq %r12, %rbx
jmp 0x78aa
testq %rdx, %rdx
je 0x79e6
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x8(%rsp), %rax
leaq (%rdi,%rax,8), %rcx
addq $-0x8, %rcx
testq %r9, %r9
jle 0x79db
movq (%rdi,%r9,8), %rax
cmpq %rsi, %rax
jbe 0x7a28
xorl %esi, %esi
cmpq %rsi, %rax
je 0x7a16
movq -0x8(%rcx,%rsi,8), %rdx
movq %rdx, (%rcx,%rsi,8)
decq %rsi
jmp 0x7a03
leaq (%rdi,%r9,8), %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
movq %rsi, (%rdx,%rax,8)
decq %r9
addq $-0x8, %rcx
jmp 0x79f3