// File: /workspace/github_c_makefile_star2_O1/yhg926[P]public_kssd/command_set.c
// Function: organize_taxf
compan_t *organize_taxf(char* taxfile){
 FILE *tf = fopen(taxfile,"r");
 if(tf == NULL) err(errno,"%s",taxfile);
 int ln = 0;
 for (char c = getc(tf); c != EOF; c = getc(tf))
  if (c == '\n') ln++;
 rewind(tf);
#define D_TAXID (-1)
 int hashsz = nextPrime( (int)((double) ln / LD_FCTR) );
 subset_t *tmphs = malloc(hashsz * sizeof(subset_t));
 for(int i = 0 ; i < hashsz ; i++) {
  tmphs[i].taxid = D_TAXID;
  tmphs[i].taxname = NULL;
 }
 char tmpstr[PATHLEN+1];
 const char s[2] = "\t";
 int tax_count = 0 ;
 for(int i= 0; i< ln ; i++) {
  fgets(tmpstr,PATHLEN,tf);
  if( tmpstr[strlen(tmpstr)-1] != '\n')
   err(errno,"organize_taxf(): %dth line %s is not full read, exceed PATHLEN %d ",i,tmpstr,PATHLEN);
  else tmpstr[strlen(tmpstr)-1] = '\0' ;
  int taxid = atoi(strtok(tmpstr,s)) ;
  char *taxname = strtok(NULL,s);
  for(int n = 0; n<hashsz ;n++){
   int hv = HASH(taxid,n,hashsz);
   if(tmphs[hv].taxid == D_TAXID) {
    tmphs[hv].taxid = taxid;
    tax_count++;
    if(taxname != NULL){
     tmphs[hv].taxname = malloc(strlen(taxname)+1);
     strcpy(tmphs[hv].taxname,taxname);
    }
    tmphs[hv].gids = malloc(2*sizeof(int));
    tmphs[hv].gids[0] = 1;
    tmphs[hv].gids[1] = i;
    break;
   }
   else if(tmphs[hv].taxid == taxid){
    if( (tmphs[hv].taxname == NULL && taxname != NULL )
     ||(tmphs[hv].taxname != NULL && taxname == NULL)
     || (taxname != NULL && strcmp(tmphs[hv].taxname,taxname) != 0)
     ) err(errno,"organize_taxf() abort!: taxid %d has different taxnames in %dth and %dth lines",taxid,tmphs[hv].gids[1],i);
     tmphs[hv].gids[0]++;
     tmphs[hv].gids = realloc(tmphs[hv].gids,(tmphs[hv].gids[0]+1) * sizeof(int));
     tmphs[hv].gids[tmphs[hv].gids[0]] = i;
     break;
   }
  }
 }
 fclose(tf);
 compan_t * subset = malloc(sizeof(compan_t));
 subset->taxn = tax_count;
 subset->gn = ln;
 subset->tax = malloc(tax_count * sizeof(subset_t)) ;
 int it = 0;
 for(int n = 0; n <hashsz; n++){
  if(tmphs[n].taxid != D_TAXID){
   subset->tax[it] = tmphs[n];
   it++;
  }
 }
 free(tmphs);
 return subset;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
leaq 0x6e4f(%rip), %rsi      # 0x16dbe
callq 0x33a0
testq %rax, %rax
je 0x102c6
movq %rax, %r14
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
callq 0x34b0
cmpb $0xa, %al
je 0xffa0
movzbl %al, %eax
cmpl $0xff, %eax
jne 0xff88
jmp 0xffa6
incl 0xc(%rsp)
jmp 0xff88
movq %r14, %rdi
callq 0x3190
cvtsi2sdl 0xc(%rsp), %xmm0
divsd 0x5234(%rip), %xmm0     # 0x151f0
cvttsd2si %xmm0, %edi
callq 0x120cc
movl %eax, %r15d
cltq
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
callq 0x3340
movl %r15d, %esi
testl %r15d, %r15d
jle 0x10006
leaq (,%rsi,8), %rcx
leaq (%rcx,%rcx,2), %rdx
xorl %ecx, %ecx
movl $0xffffffff, (%rax,%rcx) # imm = 0xFFFFFFFF
movq $0x0, 0x8(%rax,%rcx)
addq $0x18, %rcx
cmpq %rcx, %rdx
jne 0xffed
cmpl $0x0, 0xc(%rsp)
movq %rax, 0x20(%rsp)
movq %rsi, 0x30(%rsp)
je 0x101d7
leal -0x1(%r15), %eax
movl %eax, 0x2c(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x40(%rsp), %rbx
movl $0x0, 0x10(%rsp)
movq %r14, 0x38(%rsp)
movq %rbx, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x3290
movq %rbx, %rdi
callq 0x3130
cmpb $0xa, -0x1(%rax,%rbx)
jne 0x102a2
movb $0x0, 0x3f(%rsp,%rax)
movq %rbx, %rdi
leaq 0x5330(%rip), %r14      # 0x153a0
movq %r14, %rsi
callq 0x33c0
movq %rax, %rdi
callq 0x3410
movl %eax, %ebx
xorl %edi, %edi
movq %r14, %rsi
callq 0x33c0
testl %r15d, %r15d
jle 0x101b7
movq %rax, %r12
movl %ebx, %eax
cltd
idivl %r15d
movl %edx, %r14d
movl %ebx, %eax
cltd
idivl 0x2c(%rsp)
movl %edx, %ebp
incl %ebp
movl $0x1, %r13d
movq 0x20(%rsp), %rsi
movl %ebx, %edi
movl %ebx, 0x14(%rsp)
movl %r14d, %eax
cltd
idivl %r15d
movslq %edx, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsi,%rax,8), %rbx
movl (%rsi,%rax,8), %ecx
cmpl $-0x1, %ecx
je 0x10144
movb $0x1, %al
cmpl %edi, %ecx
jne 0x101a0
testq %r12, %r12
sete %al
setne %dl
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
sete %sil
setne %cl
testb %dl, %sil
jne 0x1027d
andb %al, %cl
jne 0x1027d
testq %r12, %r12
je 0x1011e
movq %r12, %rsi
callq 0x32b0
testl %eax, %eax
jne 0x1027d
movq 0x10(%rbx), %rdi
movslq (%rdi), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rdi)
leaq 0x8(,%rax,4), %rsi
callq 0x3350
movq %rax, 0x10(%rbx)
movslq (%rax), %rcx
leaq (%rax,%rcx,4), %rax
jmp 0x1018f
movl %edi, (%rbx)
testq %r12, %r12
je 0x1016b
movq %r12, %rdi
callq 0x3130
leaq 0x1(%rax), %rdi
callq 0x3340
movq %rax, 0x8(%rbx)
movq %rax, %rdi
movq %r12, %rsi
callq 0x3080
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movl $0x8, %edi
callq 0x3340
movq %rax, 0x10(%rbx)
movl $0x1, (%rax)
addq $0x4, %rax
movl 0x10(%rsp), %ecx
movl %ecx, (%rax)
xorl %eax, %eax
movq 0x20(%rsp), %rsi
movl 0x14(%rsp), %edi
testb %al, %al
je 0x101b7
leal 0x1(%r13), %eax
addl %ebp, %r14d
cmpl %r15d, %r13d
movl %eax, %r13d
jl 0x100bd
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl 0xc(%rsp), %eax
movq 0x38(%rsp), %r14
leaq 0x40(%rsp), %rbx
jne 0x1003e
jmp 0x101e0
movq $0x0, 0x18(%rsp)
movq %r14, %rdi
callq 0x3100
movl $0x10, %edi
callq 0x3340
movq %rax, %r14
movq 0x18(%rsp), %rcx
movl %ecx, (%rax)
movl 0xc(%rsp), %eax
movl %eax, 0x4(%r14)
movslq %ecx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
callq 0x3340
movq %rax, 0x8(%r14)
testl %r15d, %r15d
movq 0x20(%rsp), %rdi
jle 0x10263
movq 0x30(%rsp), %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpl $-0x1, (%rdi,%rdx)
je 0x1025a
leaq (%rdi,%rdx), %r10
movslq %esi, %rsi
leaq (%rsi,%rsi,2), %r8
movq 0x10(%r10), %r9
movq %r9, 0x10(%rax,%r8,8)
movupd (%r10), %xmm0
movupd %xmm0, (%rax,%r8,8)
incl %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x10233
callq 0x3040
movq %r14, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
movq 0x10(%rbx), %rax
movl 0x4(%rax), %ecx
leaq 0x6eaa(%rip), %rsi      # 0x1713c
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %r8d
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x6e49(%rip), %rsi      # 0x170f9
leaq 0x40(%rsp), %rcx
movl 0x10(%rsp), %edx
movl $0x100, %r8d            # imm = 0x100
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x60a2(%rip), %rsi      # 0x16376
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3330