// File: /workspace/github_c_makefile_star2_O1/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
testq %rdx, %rdx
jle 0x8451
xorl %r8d, %r8d
movq %rax, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x8445
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpl $0x8, %ecx
jne 0x8467
movq -0x10(%rsi,%rdx,8), %rbx
jmp 0x846c
movzbl -0x2(%rsi,%rdx), %ebx
cmpq $0x3, %rdx
jl 0x8576
leaq -0x2(%rdx), %r8
xorl %r14d, %r14d
movl $0x1, %r9d
cmpl $0x8, %ecx
jne 0x848f
movq -0x8(%rsi,%r8,8), %r10
jmp 0x8495
movzbl -0x1(%rsi,%r8), %r10d
movb $0x1, %r11b
cmpq %rbx, %r10
jl 0x84ab
sete %bpl
testq %r14, %r14
setne %r11b
andb %bpl, %r11b
testq %r14, %r14
sete %bpl
orb %r11b, %bpl
testb $0x1, %bpl
jne 0x855e
leaq (%rdi,%rbx,8), %r14
movq (%r14), %r12
testq %r12, %r12
js 0x84fc
leaq (%rdi,%rbx,8), %r15
addq $0x8, %r15
movq (%r15), %r13
testq %r13, %r13
js 0x84f3
movq %r13, %rbp
movq %r12, (%r15)
movq 0x8(%r15), %r13
addq $0x8, %r15
movq %rbp, %r12
testq %r13, %r13
jns 0x84db
jmp 0x84f6
movq %r12, %rbp
movq %rbp, (%r15)
movq %rax, (%r14)
movq (%r14), %r12
cmpq %rax, %r12
jne 0x8517
cmpq %rax, -0x8(%r14)
jne 0x855b
movq $-0x1, (%r14)
addq $-0x8, %r14
jmp 0x855b
leaq (%r12,%rbx), %r15
cmpq %rax, -0x8(%rdi,%r15,8)
jne 0x8531
leaq (%r12,%rbx), %r15
decq %r15
decq %r12
movq %r12, (%r14)
jmp 0x8557
testq %r12, %r12
jns 0x8557
negq %r12
cmpq $0x2, %r12
cmovlq %r9, %r12
negq %r12
xorl %ebx, %ebx
movq -0x8(%r14,%rbx,8), %r13
movq %r13, (%r14,%rbx,8)
decq %rbx
cmpq %rbx, %r12
jne 0x8546
leaq (%rdi,%r15,8), %r14
movq %r8, (%r14)
movzbl %r11b, %r14d
leaq -0x1(%r8), %r11
movq %r10, %rbx
cmpq $0x1, %r8
movq %r11, %r8
jg 0x8483
leaq -0x1(%rdx), %rcx
cmpq $0x2, %rdx
jl 0x85bd
leaq (%rdi,%rdx,8), %rdx
addq $-0x8, %rdx
movq %rcx, %rsi
movq (%rdi,%rsi,8), %r8
cmpq %rax, %r8
jbe 0x85ac
xorl %r9d, %r9d
movq -0x8(%rdx,%r9,8), %r10
movq %r10, (%rdx,%r9,8)
decq %r9
cmpq %r9, %r8
jne 0x8597
movq %rax, (%rdx,%r9,8)
leaq -0x1(%rsi), %r8
addq $-0x8, %rdx
cmpq $0x1, %rsi
movq %r8, %rsi
jg 0x858b
movq %rcx, (%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq