// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/tools/src/gsacak.c
// Function: gSACA_K
int_t gSACA_K(uint_t *s, uint_t *SA,
  uint_t n, unsigned int K,
  int cs, uint_t separator, int level) {
  uint_t i;
  uint_t *bkt=NULL;
  uint_t m=n;
  
  #if PHASES
  time_t t_start_phase = 0.0; 
  clock_t c_start_phase = 0.0;
  #endif

  #if DEPTH
  time_t t_start = time(NULL);
  clock_t c_start =  clock();
  #endif

  #if PHASES
	t_start_phase = time(NULL);
	c_start_phase =  clock();
  #endif
  // stage 1: reduce the problem by at least 1/2.

  bkt=(uint_t *)malloc(sizeof(int_t)*K);
  putSubstr0_generalized(SA, s, bkt, n, K, cs, separator);
 
  induceSAl0_generalized(SA, s, bkt, n, K, false, cs, separator);
  induceSAs0_generalized(SA, s, bkt, n, K, false, cs, separator);
  
  // insert separator suffixes in their buckets
  // bkt[separator]=1; // gsa-is
  for(i=n-3; i>0; i--)
    if(chr(i)==separator)
      SA[bkt[chr(i)]--]=i;

  // now, all the LMS-substrings are sorted and 
  //   stored sparsely in SA.

  // compact all the sorted substrings into
  //   the first n1 items of SA.
  // 2*n1 must be not larger than n.
  uint_t n1=0;
  for(i=0; i<n; i++) 
    if((SA[i]>0))
      SA[n1++]=SA[i];

  uint_t *SA1=SA, *s1=SA+m-n1;
  uint_t name_ctr;
  name_ctr=nameSubstr_generalized(SA,s,s1,n,m,n1,level,cs,separator);

  #if PHASES
	printf("phase 1:\n");
	time_stop(t_start_phase, c_start_phase);
  #endif

  #if PHASES
	t_start_phase = time(NULL);
	c_start_phase =  clock();
  #endif

  // stage 2: solve the reduced problem.
  int_t depth=1;
  // recurse if names are not yet unique.
  if(name_ctr<n1)
    depth += SACA_K((int_t*)s1, SA1, 
          n1, 0, m-n1, sizeof(int_t), level+1);
  else // get the suffix array of s1 directly.
    for(i=0; i<n1; i++) SA1[s1[i]]=i;

  // stage 3: induce SA(S) from SA(S1).

  getSAlms(SA, (int_t*)s, s1, n, n1, level, cs);

  for(i=0; i<n1; i++) SA[i]=s1[SA[i]];
  for(i=n1; i<n; i++) SA[i]=0; 

  putSuffix0_generalized(SA, s, bkt, n, K, n1, cs, separator);
  
  #if PHASES
	printf("phase 2:\n");
	time_stop(t_start_phase, c_start_phase);
  #endif

  #if PHASES
	t_start_phase = time(NULL);
	c_start_phase =  clock();
  #endif

  induceSAl0_generalized(SA, s, bkt, n, K, true, cs, separator);

  #if PHASES
      printf("phase 3:\n");
      time_stop(t_start_phase, c_start_phase);
  #endif
  
  #if PHASES
      t_start_phase = time(NULL);
      c_start_phase =  clock();
  #endif

  induceSAs0_generalized(SA, s, bkt, n, K, true, cs, separator);

  free(bkt);

  #if DEPTH
  printf("depth %" PRIdN ":\nname_ctr = %" PRIdN ", n1 =%" PRIdN ", n = %" PRIdN "\n", depth, name_ctr, n1, n);
  time_stop(t_start, c_start);
  #endif

  #if PHASES
      printf("phase 4:\n");
      time_stop(t_start_phase, c_start_phase);
  #endif

return depth;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x10960
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl -0x20(%rbp), %r9d
movq -0x28(%rbp), %rax
movq %rax, (%rsp)
callq 0xc7f0
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl -0x20(%rbp), %r10d
movq -0x28(%rbp), %rax
xorl %r9d, %r9d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x8f50
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %eax
movl %eax, %r8d
movl -0x20(%rbp), %r10d
movq -0x28(%rbp), %rax
xorl %r9d, %r9d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x9130
movq -0x18(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jbe 0xf3fe
movslq -0x20(%rbp), %rax
cmpq $0x8, %rax
jne 0xf35b
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
jmp 0xf36b
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0xf3eb
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movslq -0x20(%rbp), %rax
cmpq $0x8, %rax
jne 0xf3af
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x90(%rbp)
jmp 0xf3c2
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x90(%rbp)
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rdx
movq -0x78(%rbp), %rsi
movq -0x90(%rbp), %rdi
movq (%rsi,%rdi,8), %rcx
movq %rcx, %r8
addq $-0x1, %r8
movq %r8, (%rsi,%rdi,8)
movq %rdx, (%rax,%rcx,8)
jmp 0xf3ed
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xf334
movq $0x0, -0x48(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xf45a
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jbe 0xf44a
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0xf44c
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xf40e
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
xorl %ecx, %ecx
subq -0x48(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %r9
movl 0x10(%rbp), %r11d
movl -0x20(%rbp), %r10d
movq -0x28(%rbp), %rax
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0xe060
movq %rax, -0x60(%rbp)
movq $0x1, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0xf503
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %r8
subq -0x48(%rbp), %r8
movl 0x10(%rbp), %eax
addl $0x1, %eax
xorl %ecx, %ecx
movl $0x8, %r9d
movl %eax, (%rsp)
callq 0xeea0
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xf53d
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0xf53b
movq -0x30(%rbp), %rdx
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xf50b
jmp 0xf53d
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %r8
movl 0x10(%rbp), %r9d
movl -0x20(%rbp), %eax
movl %eax, (%rsp)
callq 0xe9d0
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0xf5a0
movq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xf568
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xf5d0
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xf5a8
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movq -0x48(%rbp), %r9
movl -0x20(%rbp), %r10d
movq -0x28(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x8400
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %r8d
movl -0x20(%rbp), %r10d
movq -0x28(%rbp), %rax
movl $0x1, %r9d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x8f50
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl -0x1c(%rbp), %eax
movl %eax, %r8d
movl -0x20(%rbp), %r10d
movq -0x28(%rbp), %rax
movl $0x1, %r9d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x9130
movq -0x38(%rbp), %rdi
callq 0x10ad0
movq -0x68(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)