// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/hmm.c
// Function: calc_fwd
void calc_fwd(Hmmptr hmm, Instanceptr traindata, double **alpha, double *loglikelihood, double *scale)
{
 /*!Last Changed 13.03.2007*/
 int i, j, t;
 double sumvalue, obslik;
 double *temp1D2;
 Instanceptr inst = traindata;
 /*initialization t=0*/
 for (i = 0; i < hmm->statecount; i++)
  { 
   obslik = calc_obslik(hmm, inst, i);
   alpha[0][i] = hmm->states[i].pi * obslik;
   if (scale)
     scale[0] += alpha[0][i];
  }  
 /*recursion t=1:T-1*/
 t = 1;
 inst = inst->sublist;
 while (inst)
  {
   for (j = 0; j < hmm->statecount; j++)
    {
     temp1D2 = multiply_two_arrays_by_value(alpha[t - 1], hmm->states[j].a_dot_j, hmm->statecount);
     sumvalue = sum_of_list_double(temp1D2, hmm->statecount);
     obslik = calc_obslik(hmm, inst, j);
     alpha[t][j] = sumvalue * obslik;
     if (scale)
       scale[t] += alpha[t][j];
     safe_free(temp1D2);
    }
   inst = inst->next;
   t++;
  }
 if (scale)
  {
  	for (i=0;i<t;i++)
		   for (j = 0; j < hmm->statecount; j++)
		    	alpha[i][j] /= scale[i];
   temp1D2 = log_of_array(scale, hmm->statecount);
   *loglikelihood = sum_of_list_double(temp1D2, hmm->statecount);
   safe_free(temp1D2);
  }
 else
   *loglikelihood = safelog(sum_of_list_double(alpha[t - 1], hmm->statecount));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d268
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x3c030
movsd %xmm0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movsd 0x10(%rax), %xmm0
mulsd -0x48(%rbp), %xmm0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpq $0x0, -0x28(%rbp)
je 0x3d25b
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x3d25d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3d1eb
movl $0x1, -0x34(%rbp)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x3d37b
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d361
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x507c0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x50b50
movsd %xmm0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x3c030
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpq $0x0, -0x28(%rbp)
je 0x3d34a
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x50(%rbp), %rdi
callq 0x52e80
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3d28d
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3d27b
cmpq $0x0, -0x28(%rbp)
je 0x3d422
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x3d3eb
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d3de
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3d39c
jmp 0x3d3e0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3d38d
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x50690
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x50b50
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x50(%rbp), %rdi
callq 0x52e80
jmp 0x3d44c
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x50b50
callq 0x52b10
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)