// File: /workspace/github_c_makefile_star2_O3/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:
cmpq $0x2, %rdx
jl 0x81b6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, -0x8(%rsp)
leaq -0x1(%rdx), %r9
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
leaq 0x1(%rdx), %r10
movq %r9, %r11
movq (%rdi,%r11,8), %rbx
movl $0x1, %r14d
testq %rbx, %rbx
jle 0x8150
cmpl $0x8, %r8d
jne 0x8079
movq -0x8(%rsi,%rbx,8), %r12
movq (%rsi,%rbx,8), %rax
jmp 0x8083
movzbl -0x1(%rsi,%rbx), %r12d
movzbl (%rsi,%rbx), %eax
cmpq %rax, %r12
jl 0x809a
cmpq %r11, %r12
jle 0x8150
cmpq %rax, %r12
jne 0x8150
leaq (%rdi,%r12,8), %r15
movq (%r15), %rax
testq %rax, %rax
js 0x80d1
leaq (%rdi,%r12,8), %r14
addq $0x8, %r14
movq (%r14), %rbp
cmpq %r10, %rbp
jae 0x80f0
movq %rbp, %r13
movq %rax, (%r14)
movq 0x8(%r14), %rbp
addq $0x8, %r14
incq %r12
movq %r13, %rax
cmpq %r10, %rbp
jb 0x80b6
jmp 0x80f3
cmpq %rdx, %rax
je 0x8100
leaq (%rax,%r12), %rbp
cmpq %rdx, -0x8(%rdi,%rbp,8)
jne 0x8113
leaq (%rax,%r12), %rbp
decq %rbp
decq %rax
movq %rax, (%r15)
jmp 0x8131
movq %rax, %r13
movq %r13, (%r14)
xorl %r14d, %r14d
cmpq %r11, %r12
setl %r14b
cmpq %rdx, -0x8(%r15)
jne 0x8135
movq $-0x1, (%r15)
addq $-0x8, %r15
jmp 0x8135
xorl %r14d, %r14d
movq -0x8(%r15,%r14,8), %r13
movq %r13, (%r15,%r14,8)
decq %r14
cmpq %r14, %rax
jne 0x8116
xorl %r14d, %r14d
cmpq %r11, %r12
setle %r14b
leaq (%rdi,%rbp,8), %r15
decq %rbx
movq %rbx, (%r15)
testq %rcx, %rcx
jne 0x8150
leaq (%rdi,%r11,8), %rax
xorl %ebx, %ebx
testq %r14, %r14
sete %bl
movq %rdx, (%rax,%rbx,8)
subq %r14, %r11
jg 0x8055
movq -0x8(%rsp), %rsi
cmpq $0x2, %rsi
setl %al
testq %rcx, %rcx
setne %cl
orb %al, %cl
jne 0x81ac
leaq (%rdi,%rsi,8), %rcx
addq $-0x8, %rcx
movq (%rdi,%r9,8), %rax
cmpq %rdx, %rax
jbe 0x819b
xorl %esi, %esi
movq -0x8(%rcx,%rsi,8), %r8
movq %r8, (%rcx,%rsi,8)
decq %rsi
cmpq %rsi, %rax
jne 0x8182
leaq (%rdi,%r9,8), %rsi
movq %rdx, (%rsi,%rax,8)
leaq -0x1(%r9), %rax
addq $-0x8, %rcx
cmpq $0x1, %r9
movq %rax, %r9
jg 0x8177
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq