// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]lyndon-array/external/sacak-lyndon.c
// Function: nameSubstr
int_t nameSubstr(int_t *SA, 
  int_t *s, int_t *s1, int_t n, 
  int_t m, int_t n1, int level, int cs) {
  int_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
  int_t name=0, name_ctr=0;
  int_t pre_pos=n-1, pre_len=0;
  for(i=0; i<n1; i++) {
    int diff=false;
    int_t len, pos=SA[i];

    int_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 $0x80, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa620
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa5fe
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xa7d9
movl $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl 0x10(%rbp), %edx
movl -0x50(%rbp), %ecx
movl 0x18(%rbp), %r8d
callq 0xa3c0
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x44(%rbp), %eax
je 0xa693
movl $0x1, -0x48(%rbp)
jmp 0xa75b
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0xa759
movl -0x50(%rbp), %eax
addl -0x54(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xa740
movl -0x40(%rbp), %eax
addl -0x54(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xa740
movslq 0x18(%rbp), %rax
cmpq $0x4, %rax
jne 0xa6e9
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x60(%rbp)
jmp 0xa6fd
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x64(%rbp)
movslq 0x18(%rbp), %rax
cmpq $0x4, %rax
jne 0xa722
movq -0x10(%rbp), %rax
movl -0x40(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
jmp 0xa736
movq -0x10(%rbp), %rax
movl -0x40(%rbp), %ecx
addl -0x54(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
movl -0x68(%rbp), %ecx
cmpl %ecx, %eax
je 0xa749
movl $0x1, -0x48(%rbp)
jmp 0xa759
jmp 0xa74b
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xa69a
jmp 0xa75b
cmpl $0x0, -0x48(%rbp)
je 0xa78d
movl -0x28(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0xa79e
movq -0x8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %ecx
movl -0x50(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl -0x74(%rbp), %edx
movl %eax, %esi
movq -0x70(%rbp), %rax
addl %esi, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa645
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0xa831
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
cmpl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
je 0xa824
movq -0x8(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $-0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xa826
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa7eb
movl $0x1, -0x34(%rbp)
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jle 0xa8f1
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movb $0x1, %al
cmpl -0x58(%rbp), %ecx
movb %al, -0x75(%rbp)
jl 0xa896
movl -0x5c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x58(%rbp), %ecx
movb %al, -0x76(%rbp)
jne 0xa890
cmpl $0x1, -0x34(%rbp)
sete %al
movb %al, -0x76(%rbp)
movb -0x76(%rbp), %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x30(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0xa8dd
movq -0x8(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x28(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %edx
subl $0x1, %edx
movq -0x18(%rbp), %rax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa841
movl -0x3c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)