// File: /workspace/github_c_makefile_star2_O1/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
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
leaq -0x1(%rdx), %r9
movq %rdx, -0x8(%rsp)
cmpq $0x2, %rdx
jl 0x83d9
leaq 0x1(%r13), %r10
movq %r9, %rbx
movq (%rdi,%rbx,8), %rax
movl $0x1, %r15d
testq %rax, %rax
jle 0x83d0
leaq -0x1(%rax), %r14
cmpl $0x8, %r8d
jne 0x82d0
movq -0x8(%rsi,%rax,8), %r12
jmp 0x82d5
movzbl (%rsi,%r14), %r12d
cmpl $0x8, %r8d
jne 0x82e1
movq (%rsi,%rax,8), %rax
jmp 0x82e5
movzbl (%rsi,%rax), %eax
cmpq %rax, %r12
jl 0x82fc
cmpq %rbx, %r12
jle 0x83d0
cmpq %rax, %r12
jne 0x83d0
movq (%rdi,%r12,8), %rax
testq %rax, %rax
js 0x8353
leaq (%rdi,%r12,8), %r15
addq $0x8, %r15
movq (%r15), %r11
cmpq %r10, %r11
jae 0x8333
movq %r12, %rbp
movq %r11, %r13
movq %rax, (%r15)
movq 0x8(%r15), %r11
addq $0x8, %r15
incq %rbp
movq %r13, %rax
cmpq %r10, %r11
jb 0x8318
jmp 0x8339
movq %rax, %r13
movq %r12, %rbp
movq %r13, (%r15)
xorl %r15d, %r15d
cmpq %rbx, %rbp
setl %r15b
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movq %r13, %rax
leaq (%rdi,%r12,8), %r11
cmpq %r13, %rax
jne 0x836f
cmpq %r13, -0x8(%r11)
jne 0x83b8
movq $-0x1, (%r11)
addq $-0x8, %r11
jmp 0x83b8
leaq (%rax,%r12), %rbp
cmpq %r13, -0x8(%rdi,%rbp,8)
jne 0x8386
leaq (%rax,%r12), %rbp
decq %rbp
decq (%r11)
jmp 0x83b4
leaq (%rdi,%r12,8), %r11
xorl %r13d, %r13d
movq -0x8(%r11,%r13,8), %rdx
movq %rdx, (%r11,%r13,8)
decq %r13
cmpq %r13, %rax
jne 0x838d
cmpq %rbx, %r12
movl $0x0, %eax
cmovgq %rax, %r15
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
leaq (%rdi,%rbp,8), %r11
movq %r14, (%r11)
testq %rcx, %rcx
jne 0x83d0
leaq (%rdi,%rbx,8), %rax
xorl %edx, %edx
testq %r15, %r15
sete %dl
movq %r13, (%rax,%rdx,8)
subq %r15, %rbx
jg 0x82ac
testq %rcx, %rcx
setne %al
movq -0x8(%rsp), %rdx
cmpq $0x2, %rdx
setl %cl
orb %al, %cl
jne 0x8428
leaq (%rdi,%rdx,8), %rcx
addq $-0x8, %rcx
movq (%rdi,%r9,8), %rax
cmpq %r13, %rax
jbe 0x8417
xorl %esi, %esi
movq -0x8(%rcx,%rsi,8), %rdx
movq %rdx, (%rcx,%rsi,8)
decq %rsi
cmpq %rsi, %rax
jne 0x8402
movq %r13, (%rcx,%rsi,8)
leaq -0x1(%r9), %rax
addq $-0x8, %rcx
cmpq $0x1, %r9
movq %rax, %r9
jg 0x83f7
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq