// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/hmm.c
// Function: calc_bwd
void calc_bwd(Hmmptr hmm, Instanceptr traindata, int seqlen, double **beta, double *scale)
{
 /*!Last Changed 13.03.2007*/
 int i, j, t;
 double sumvalue, obslik;
 double *temp1D2;
 Instanceptr inst;
 /*initialization t = T - 1*/
 for (i = 0; i < hmm->statecount; i++)
   beta[seqlen - 1][i] = 1;  
 /*recursion t=T-2:0*/
 reverse_instancelist(&(traindata->sublist));
 inst = traindata->sublist; /* listeyi ters cevirmek lazim*/
 inst = inst->next;
 t = seqlen - 2; 
 while (t >= 0)
  {
   for (i = 0; i < hmm->statecount; i++)
    {
     temp1D2 = multiply_two_arrays_by_value(beta[t + 1], hmm->states[i].a_i_dot, hmm->statecount);
     for (j = 0; j < hmm->statecount; j++)
      {
       obslik = calc_obslik(hmm, inst, j);
       temp1D2[j] *= obslik;
      }
     sumvalue = sum_of_list_double(temp1D2, hmm->statecount);
     beta[t][i] = sumvalue;
     safe_free(temp1D2);
    }
   t--;
   inst = inst->next;
   if (!inst)
     inst = traindata;
  }
 reverse_instancelist(&(traindata->sublist)); 
 if (scale)
  {
   for (i = 0; i < seqlen; i++)
		   for (j = 0; j < hmm->statecount; j++)
			    beta[i][j] /= scale[i];
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, %r13
movl %edx, %ebx
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
movslq 0x8(%rdi), %rax
testq %rax, %rax
jle 0x2ad33
movslq %ebx, %rcx
movq -0x8(%r13,%rcx,8), %rcx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x2ad27
movq 0x10(%rsp), %rax
leaq 0x28(%rax), %rdi
movq %rdi, (%rsp)
callq 0x2fd34
movq %rbx, 0x8(%rsp)
cmpl $0x2, %ebx
jl 0x2ae1f
movq 0x8(%rsp), %rax
leal -0x2(%rax), %ebx
movq (%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rbp
movl 0x8(%r12), %edx
testl %edx, %edx
jle 0x2ae02
xorl %r14d, %r14d
movq %rbx, 0x20(%rsp)
movq 0x8(%r13,%rbx,8), %rdi
movq (%r12), %rax
movq %r14, %rcx
shlq $0x5, %rcx
movq 0x8(%rax,%rcx), %rsi
callq 0x3792d
movq %rax, %r15
movl 0x8(%r12), %esi
testl %esi, %esi
jle 0x2add6
movq %r13, %rbx
xorl %r13d, %r13d
movq %r12, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x29dde
mulsd (%r15,%r13,8), %xmm0
movsd %xmm0, (%r15,%r13,8)
incq %r13
movslq 0x8(%r12), %rsi
cmpq %rsi, %r13
jl 0x2ada7
movq %rbx, %r13
movq 0x20(%rsp), %rbx
movq %r15, %rdi
callq 0x37ae1
movq (%r13,%rbx,8), %rax
movsd %xmm0, (%rax,%r14,8)
movq %r15, %rdi
callq 0x39194
incq %r14
movslq 0x8(%r12), %rdx
cmpq %rdx, %r14
jl 0x2ad7b
leaq -0x1(%rbx), %rax
movq 0x10(%rbp), %rbp
testq %rbp, %rbp
cmoveq 0x10(%rsp), %rbp
testq %rbx, %rbx
movq %rax, %rbx
jg 0x2ad66
movq (%rsp), %rdi
callq 0x2fd34
movq 0x18(%rsp), %r8
testq %r8, %r8
sete %al
movq 0x8(%rsp), %rdx
testl %edx, %edx
setle %cl
orb %al, %cl
jne 0x2ae75
movl 0x8(%r12), %eax
movl %edx, %ecx
xorl %edx, %edx
testl %eax, %eax
jle 0x2ae6d
movq (%r13,%rdx,8), %rsi
xorl %edi, %edi
movsd (%rsi,%rdi,8), %xmm0
divsd (%r8,%rdx,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rax
jne 0x2ae55
incq %rdx
cmpq %rcx, %rdx
jne 0x2ae4a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq