// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d4bb
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd 0xa4b6d(%rip), %xmm0    # 0xe2018
movsd %xmm0, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3d482
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0x44ee0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x14(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jl 0x3d5fa
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d5d1
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x507c0
movq %rax, -0x50(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d58b
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x3c030
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movq -0x50(%rbp), %rax
movslq -0x30(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3d548
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x50b50
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x50(%rbp), %rdi
callq 0x52e80
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3d4fa
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x3d5f5
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x3d4e9
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0x44ee0
cmpq $0x0, -0x28(%rbp)
je 0x3d675
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3d673
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x3d666
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x20(%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 0x3d624
jmp 0x3d668
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3d615
jmp 0x3d675
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)