// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/tools/src/gsacak.c
// Function: nameSubstr
uint_t nameSubstr(uint_t *SA, 
  int_t *s, uint_t *s1, uint_t n, 
  uint_t m, uint_t n1, int level, int cs) {
  uint_t i, j, cur_t, succ_t;

  // init the name array buffer
  for(i=n1; i<n; i++) SA[i]=EMPTY_k;

  // scan to compute the interim s1
  uint_t name=0, name_ctr=0;
  uint_t pre_pos=n-1, pre_len=0;
  for(i=0; i<n1; i++) {
    int diff=false;
    uint_t len, pos=SA[i];

    uint_t d;
    len=getLengthOfLMS(s, n, level, pos, cs);
    if(len!=pre_len) diff=true;
    else
      for(d=0; d<len; d++)
        if(pos+d==n-1 || pre_pos+d==n-1 ||
           chr(pos+d)!=chr(pre_pos+d)) {
          diff=true; break;
        }

    if(diff) {
      name=i; name_ctr++;
      SA[name]=1; // a new name.
      pre_pos=pos; pre_len=len;
    }
    else
      SA[name]++; // count this name.

    SA[n1+pos/2]=name;
  }

  // compact the interim s1 sparsely stored 
  //   in SA[n1, n-1] into SA[m-n1, m-1].
  for(i=n-1, j=m-1; i>=n1; i--)
    if(SA[i]!=EMPTY_k) SA[j--]=SA[i];

  // rename each S-type character of the
  //   interim s1 as the end of its bucket
  //   to produce the final s1.
  succ_t=1;
  for(i=n1-1; i>0; i--) {
    int_t ch=s1[i], ch1=s1[i-1];
    cur_t=(ch1< ch || (ch1==ch && succ_t==1))?1:0;
    if(cur_t==1) {
      s1[i-1]+=SA[s1[i-1]]-1;
    }
    succ_t=cur_t;
  }

  return name_ctr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0xdcaf
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xdc81
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xdedb
movl $0x0, -0x74(%rbp)
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl 0x10(%rbp), %edx
movq -0x88(%rbp), %rcx
movl 0x18(%rbp), %r8d
callq 0xd9f0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x70(%rbp), %rax
je 0xdd38
movl $0x1, -0x74(%rbp)
jmp 0xde5a
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x80(%rbp), %rax
jae 0xde58
movq -0x88(%rbp), %rax
addq -0x90(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0xde36
movq -0x68(%rbp), %rax
addq -0x90(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0xde36
movslq 0x18(%rbp), %rax
cmpq $0x8, %rax
jne 0xddb8
movq -0x10(%rbp), %rax
movq -0x88(%rbp), %rcx
addq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa8(%rbp)
jmp 0xddd5
movq -0x10(%rbp), %rax
movq -0x88(%rbp), %rcx
addq -0x90(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movslq 0x18(%rbp), %rax
cmpq $0x8, %rax
jne 0xde09
movq -0x10(%rbp), %rax
movq -0x68(%rbp), %rcx
addq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb8(%rbp)
jmp 0xde23
movq -0x10(%rbp), %rax
movq -0x68(%rbp), %rcx
addq -0x90(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
movq -0xb8(%rbp), %rcx
cmpq %rcx, %rax
je 0xde3f
movl $0x1, -0x74(%rbp)
jmp 0xde58
jmp 0xde41
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0xdd43
jmp 0xde5a
cmpl $0x0, -0x74(%rbp)
je 0xde99
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq -0x58(%rbp), %rcx
movq $0x1, (%rax,%rcx,8)
movq -0x88(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0xdead
movq -0x8(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdx
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x88(%rbp), %rsi
shrq %rsi
addq %rsi, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xdcdb
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0xdf48
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
cmpq %rdx, (%rax,%rcx,8)
je 0xdf38
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x8(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, %rsi
addq $-0x1, %rsi
movq %rsi, -0x40(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0xdf3a
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xdef3
movq $0x1, -0x50(%rbp)
movq -0x30(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jbe 0xe044
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rcx
movb $0x1, %al
cmpq -0x98(%rbp), %rcx
movb %al, -0xb9(%rbp)
jl 0xdfdb
movq -0xa0(%rbp), %rcx
xorl %eax, %eax
cmpq -0x98(%rbp), %rcx
movb %al, -0xba(%rbp)
jne 0xdfcf
cmpq $0x1, -0x50(%rbp)
sete %al
movb %al, -0xba(%rbp)
movb -0xba(%rbp), %al
movb %al, -0xb9(%rbp)
movb -0xb9(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
cltq
movq %rax, -0x48(%rbp)
cmpq $0x1, -0x48(%rbp)
jne 0xe02b
movq -0x8(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rdx
subq $0x1, %rdx
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xdf5c
movq -0x60(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)