// File: /workspace/github_c_makefile_star2_O2/felipelouza[P]egap/tools/src/gsacak.c
// Function: putSubstr1
void putSubstr1(int_t *SA, int_t *s, int_t n, int cs) {
  int_t h, i, j;

  for(i=0; i<n; i++) SA[i]=EMPTY_k;

  int_t c, c1, t, t1;
  c1=chr(n-2);
  t1=0; 
  for(i=n-2; i>0; i--) {
    c=c1; t=t1; 
    c1=chr(i-1);
    t1=c1<c || (c1==c && t);
    if(t && !t1) {
      if(SA[c]>=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; h++)
        { bar=SA[h]; SA[h]=foo; foo=bar; }
        SA[h]=foo;

        SA[c]=EMPTY_k;
      }

      int_t d=SA[c];
      if(d==EMPTY_k) { // SA[c] is empty.
        if(SA[c-1]==EMPTY_k) {
          SA[c]=-1; // init the counter.
          SA[c-1]=i;
        }
        else
          SA[c]=i; // 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, i).
            for(h=0; h<-d; h++)
              SA[c-h]=SA[c-h-1];
            pos++;
          }
          else
            SA[c]--;

          SA[pos]=i;
      }
    }
  }

  // scan to shift-right the items in each bucket
  //   with its head being reused as a counter.
  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;
    }
  }

  // put the single sentinel LMS-substring.
  SA[0]=n-1;
}

// Assembly:
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
xorl %r8d, %r8d
testq %rdx, %rdx
movl $0x0, %r9d
cmovgq %rdx, %r9
cmpq %r8, %r9
je 0x7a59
movq %rax, (%rdi,%r8,8)
incq %r8
jmp 0x7a4b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x8, %ecx
jne 0x7a6f
movq -0x10(%rsi,%rdx,8), %rbx
jmp 0x7a74
movzbl -0x2(%rsi,%rdx), %ebx
leaq -0x2(%rdx), %r8
leaq 0x8(%rdi), %r9
xorl %r14d, %r14d
testq %r8, %r8
jle 0x7b35
cmpl $0x8, %ecx
jne 0x7a94
movq -0x8(%rsi,%r8,8), %r10
jmp 0x7a9a
movzbl -0x1(%rsi,%r8), %r10d
movb $0x1, %r11b
cmpq %rbx, %r10
jl 0x7b11
sete %bpl
testq %r14, %r14
setne %r11b
sete %r14b
andb %bpl, %r11b
orb %bpl, %r14b
jne 0x7b11
leaq (%rdi,%rbx,8), %r14
movq (%r14), %r15
testq %r15, %r15
js 0x7add
leaq (%r9,%rbx,8), %rbx
movq (%rbx), %r12
movq %r15, (%rbx)
addq $0x8, %rbx
movq %r12, %r15
testq %r12, %r12
jns 0x7ac9
jmp 0x7ae2
cmpq %rax, %r15
jne 0x7af2
cmpq %rax, -0x8(%r14)
jne 0x7b0e
orq $-0x1, (%r14)
addq $-0x8, %r14
jmp 0x7b0e
leaq (%r15,%rbx), %r12
cmpq %rax, -0x8(%rdi,%r12,8)
jne 0x7b20
leaq (%r15,%rbx), %r12
decq %r12
decq %r15
movq %r15, (%r14)
leaq (%rdi,%r12,8), %r14
movq %r8, (%r14)
movzbl %r11b, %r14d
decq %r8
movq %r10, %rbx
jmp 0x7a7f
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x7b0a
movq -0x8(%r14,%rbx,8), %r13
movq %r13, (%r14,%rbx,8)
decq %rbx
jmp 0x7b22
leaq (%rdi,%rdx,8), %rcx
addq $-0x8, %rcx
decq %rdx
movq %rdx, %rsi
testq %rsi, %rsi
jle 0x7b78
movq (%rdi,%rsi,8), %r8
cmpq %rax, %r8
jbe 0x7b6f
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x7b67
movq -0x8(%rcx,%r9,8), %r10
movq %r10, (%rcx,%r9,8)
decq %r9
jmp 0x7b54
leaq (%rdi,%rsi,8), %r9
movq %rax, (%r9,%r8,8)
decq %rsi
addq $-0x8, %rcx
jmp 0x7b43
movq %rdx, (%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq