// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/hmm.c
// Function: add_state
void add_state(Hmmptr hmm, int count, Instanceptr traindata)
{
 /*!Last Changed 06.04.2007*/
 int i, j, componentcount;
 double* pi, randvalue;
 hmm->states = alloc(hmm->states, (hmm->statecount + count) * sizeof(State), hmm->statecount + count);
 /*Reshuffle pi's*/
 pi = safemalloc(hmm->statecount * sizeof(double), "add_state", 5);
 for (i = 0; i < hmm->statecount; i++)
   pi[i] = hmm->states[i].pi;
 pi = add_probability_conserving(pi, hmm->statecount, count);
 for (i = 0; i < hmm->statecount + count; i++)
   hmm->states[i].pi = pi[i];   
 safe_free(pi);
 /*Reshuffle a_i_dot*/
 switch (hmm->hmmtype)
  {
   case    FULL_MODEL:for (i = 0; i < hmm->statecount; i++)
                        hmm->states[i].a_i_dot = add_probability_conserving(hmm->states[i].a_i_dot, hmm->statecount, count);
                      for (i = hmm->statecount; i < hmm->statecount + count; i++)
                        hmm->states[i].a_i_dot = random_normalized_array(hmm->statecount + count);
                      break;
   case      LR_MODEL:
   case LR_LOOP_MODEL:for (i = 0; i < hmm->statecount; i++)
                       {
                        hmm->states[i].a_i_dot = alloc(hmm->states[i].a_i_dot, (hmm->statecount + count) * sizeof(double), hmm->statecount + count);
                        for (j = hmm->statecount; j < hmm->statecount + count; j++)
                          hmm->states[i].a_i_dot[j] = 0.0;
                       }
                      for (i = hmm->statecount; i < hmm->statecount + count; i++)
                        hmm->states[i].a_i_dot = safecalloc(hmm->statecount + count, sizeof(double), "add_state", 27);
                      for (i = hmm->statecount - 1; i < hmm->statecount + count - 1; i++)
                       {
                        randvalue = produce_random_value(0.0, 1.0);
                        hmm->states[i].a_i_dot[i] = randvalue;
                        hmm->states[i].a_i_dot[i + 1] = 1 - randvalue;
                       }
                      if (hmm->hmmtype == LR_MODEL)
                        hmm->states[hmm->statecount + count - 1].a_i_dot[hmm->statecount + count - 1] = 1.0;
                      else
                       {
                        hmm->states[hmm->statecount - 1].a_i_dot[0] = 0.0;
                        randvalue = produce_random_value(0.0, 1.0);
                        hmm->states[hmm->statecount + count - 1].a_i_dot[hmm->statecount + count - 1] = randvalue;
                        hmm->states[hmm->statecount + count - 1].a_i_dot[0] = 1 - randvalue;
                       }
                      break;
  }
 /*Reshuffle a_dot_j*/
 for (i = 0; i < hmm->statecount; i++)
   hmm->states[i].a_dot_j = alloc(hmm->states[i].a_dot_j, (hmm->statecount + count) * sizeof(double), hmm->statecount + count);
 for (i = hmm->statecount; i < hmm->statecount + count; i++)
   hmm->states[i].a_dot_j = safemalloc((hmm->statecount + count) * sizeof(double), "add_state", 49);
 for (i = 0; i < hmm->statecount + count; i++)
   for (j = 0; j < hmm->statecount + count; j++)
     hmm->states[j].a_dot_j[i] = hmm->states[i].a_i_dot[j];
 /*Add b's*/
 for (i = hmm->statecount; i < hmm->statecount + count; i++)
  {
   componentcount = get_component_count(hmm->states[0], hmm->statetype);
   hmm->states[i].b = random_state_model(hmm->statetype, componentcount, traindata);
  }
 /*Update statecount*/
 hmm->statecount += count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
addl -0xc(%rbp), %eax
movslq %eax, %rsi
shlq $0x5, %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
addl -0xc(%rbp), %edx
callq 0x52d10
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rdi
shlq $0x3, %rdi
leaq 0xaa5e0(%rip), %rsi     # 0xe5167
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3abd7
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3ab9c
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movl -0xc(%rbp), %edx
callq 0x3a6d0
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3ac35
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsd %xmm0, 0x10(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3abf5
movq -0x30(%rbp), %rdi
callq 0x52e80
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0x3ac61
jmp 0x3ac4e
movl -0x3c(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x3ad10
jmp 0x3afc3
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3acbd
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movl -0xc(%rbp), %edx
callq 0x3a6d0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3ac68
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3ad0b
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
addl -0xc(%rbp), %edi
callq 0x54790
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3acc7
jmp 0x3afc3
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3adce
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
addl -0xc(%rbp), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
addl -0xc(%rbp), %edx
callq 0x52d10
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3adbe
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3ad80
jmp 0x3adc0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3ad17
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3ae30
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
addl -0xc(%rbp), %eax
movslq %eax, %rdi
movl $0x8, %esi
leaq 0xaa365(%rip), %rdx     # 0xe5167
movl $0x1b, %ecx
callq 0x52f40
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3add8
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x3aec9
xorps %xmm0, %xmm0
movsd 0xa71bc(%rip), %xmm1    # 0xe2018
callq 0x545a0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xa7186(%rip), %xmm0    # 0xe2018
subsd -0x38(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3ae3d
movq -0x8(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x3af17
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xa710b(%rip), %xmm0    # 0xe2018
movsd %xmm0, (%rax,%rcx,8)
jmp 0x3afc1
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
xorps %xmm0, %xmm0
movsd 0xa70d0(%rip), %xmm1    # 0xe2018
callq 0x545a0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0xa7082(%rip), %xmm0    # 0xe2018
subsd -0x38(%rbp), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movsd %xmm0, (%rax)
jmp 0x3afc3
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3b02e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
addl -0xc(%rbp), %eax
movslq %eax, %rsi
shlq $0x3, %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
addl -0xc(%rbp), %edx
callq 0x52d10
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3afca
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3b08e
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
addl -0xc(%rbp), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
leaq 0xaa106(%rip), %rsi     # 0xe5167
movl $0x31, %edx
callq 0x52d70
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3b038
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3b113
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3b106
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3b0ad
jmp 0x3b108
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3b095
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3b19d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movl 0xc(%rcx), %edi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x3b1b0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %edi
movl -0x24(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x383e0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3b11d
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
addq $0x60, %rsp
popq %rbp
retq