// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/softtree.c
// Function: gradient_descent_soft_tree_K_class
void gradient_descent_soft_tree_K_class(Decisionnodeptr rootnode, Decisionnodeptr node, Softregtree_parameterptr param, double eta)
{
 int i, j, k, t, r, *array, datasize;
 double sum, multiplier, delta, feature_value, *output, *previous_update_left, *previous_update_right, *previous_update;
 Instanceptr inst;
 Decisionnodeptr tmpnode;
 datasize = data_size(rootnode->instances);
 node->w = random_matrix(current_dataset->multifeaturecount, 1, -0.01, +0.01);
 node->left->w0s = random_array_double(current_dataset->classno, -0.01, +0.01);
 node->right->w0s = random_array_double(current_dataset->classno, -0.01, +0.01);
 previous_update = safecalloc(current_dataset->multifeaturecount, sizeof(double), "gradient_descent_soft_tree_K_class", 9);
 previous_update_left = safecalloc(current_dataset->classno, sizeof(double), "gradient_descent_soft_tree_K_class", 9);
 previous_update_right = safecalloc(current_dataset->classno, sizeof(double), "gradient_descent_soft_tree_K_class", 9);
 for (i = 0; i < param->epochs; i++)
  {
   array = random_array(datasize);
   for (j = 0; j < datasize; j++)
    {
     inst = data_x(rootnode->instances, array[j]);
     output = soft_tree_output_K_class(rootnode, inst);
     softmax(output, current_dataset->classno);
     r = give_classno(inst);
     multiplier = eta;
     tmpnode = node;
     while (tmpnode->parent)
      {
       multiplier *= tmpnode->weight;
       tmpnode = tmpnode->parent;
      }
     for (k = 0; k < current_dataset->classno; k++)
      {      
       node->left->w0s[k] += multiplier * (kronecker_delta(r, k) - output[k]) * node->left->weight + param->alpha * previous_update_left[k];
       previous_update_left[k] = multiplier * (kronecker_delta(r, k) - output[k]) * node->left->weight;
       node->right->w0s[k] += multiplier * (kronecker_delta(r, k) - output[k]) * node->right->weight + param->alpha * previous_update_right[k];
       previous_update_right[k] = multiplier * (kronecker_delta(r, k) - output[k]) * node->right->weight;
      }
     for (t = 0; t < current_dataset->multifeaturecount; t++)
      {
       if (t != 0)
         feature_value = real_feature(inst, t - 1);
       else
         feature_value = 1;
       sum = 0;
       for (k = 0; k < current_dataset->classno; k++)
        {
         delta = multiplier * (kronecker_delta(r, k) - output[k]) * feature_value * (node->left->outputs[k] - node->right->outputs[k]) * node->left->weight * node->right->weight;
         sum += delta;
        }
       node->w.values[t][0] += sum + param->alpha * previous_update[t];
       previous_update[t] = sum;
     }
    }
   safe_free(array);
   eta = eta * param->etadecrease;
  }
 safe_free(previous_update_left);
 safe_free(previous_update_right);
 safe_free(previous_update);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm0, 0x10(%rsp)
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, 0x58(%rsp)
movq 0x20(%rdi), %rdi
callq 0x30309
movl %eax, 0xc(%rsp)
leaq 0x4a1c2(%rip), %rbp     # 0xd5870
movq (%rbp), %rax
movl 0x1c0(%rax), %edi
movsd 0x1a6f8(%rip), %xmm0    # 0xa5db8
movsd 0x1a6f8(%rip), %xmm1    # 0xa5dc0
movl $0x1, %esi
callq 0x3ef18
movq %rax, 0x38(%r14)
movq %rdx, 0x40(%r14)
movq (%rbp), %rax
movl 0x10(%rax), %edi
movsd 0x1a6cf(%rip), %xmm0    # 0xa5db8
movsd 0x1a6cf(%rip), %xmm1    # 0xa5dc0
callq 0x3b110
movq (%r14), %rcx
movq %rax, 0x50(%rcx)
movq (%rbp), %rax
movl 0x10(%rax), %edi
movsd 0x1a6ac(%rip), %xmm0    # 0xa5db8
movsd 0x1a6ac(%rip), %xmm1    # 0xa5dc0
callq 0x3b110
movq 0x8(%r14), %rcx
movq %rax, 0x50(%rcx)
movq (%rbp), %rax
movslq 0x1c0(%rax), %rdi
leaq 0x25cd0(%rip), %r15     # 0xb1403
movl $0x8, %esi
movq %r15, %rdx
movl $0x9, %ecx
callq 0x3a1fc
movq %rax, 0x30(%rsp)
movq (%rbp), %rax
movslq 0x10(%rax), %rdi
movl $0x8, %esi
movq %r15, %rdx
movl $0x9, %ecx
callq 0x3a1fc
movq %rax, %r12
movq (%rbp), %rax
movslq 0x10(%rax), %rdi
movl $0x8, %esi
movq %r15, %rdx
movl $0x9, %ecx
callq 0x3a1fc
movq %rax, %rbx
cmpl $0x0, 0x4(%r13)
jle 0x8babc
movl 0xc(%rsp), %eax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq %r13, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movq %rbx, 0x18(%rsp)
movq %rax, 0x48(%rsp)
movl 0xc(%rsp), %r15d
movl %r15d, %edi
callq 0x3afe4
movq %rax, 0x28(%rsp)
testl %r15d, %r15d
jle 0x8ba8f
xorl %ecx, %ecx
movq 0x58(%rsp), %r15
movq 0x20(%r15), %rdi
movq 0x28(%rsp), %rax
movq %rcx, 0x60(%rsp)
movl (%rax,%rcx,4), %esi
callq 0x31851
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x8b410
movq %rax, %r15
movq (%rbp), %rax
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0x55aa4
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0x2f33a
movl %eax, %r12d
movq 0x18(%r14), %rax
movsd 0x10(%rsp), %xmm0
movq %r14, %rcx
testq %rax, %rax
je 0x8b836
mulsd 0x78(%rcx), %xmm0
movq %rax, %rcx
movq 0x18(%rax), %rax
jmp 0x8b823
movq (%rbp), %rax
cmpl $0x0, 0x10(%rax)
movsd %xmm0, (%rsp)
jle 0x8b963
movq %r13, %rbx
xorl %r13d, %r13d
movl %r12d, %edi
movl %r13d, %esi
callq 0x3a524
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movsd 0x18(%rbx), %xmm1
movq %rbx, %rbp
movq 0x38(%rsp), %rbx
mulsd (%rbx,%r13,8), %xmm1
movq (%r14), %rax
mulsd 0x78(%rax), %xmm0
addsd %xmm1, %xmm0
movq 0x50(%rax), %rax
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
movl %r12d, %edi
movl %r13d, %esi
callq 0x3a524
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movq (%r14), %rax
mulsd 0x78(%rax), %xmm0
movsd %xmm0, (%rbx,%r13,8)
movq %rbp, %rbx
leaq 0x49fa0(%rip), %rbp     # 0xd5870
movl %r12d, %edi
movl %r13d, %esi
callq 0x3a524
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movsd 0x18(%rbx), %xmm1
movq 0x18(%rsp), %rax
mulsd (%rax,%r13,8), %xmm1
movq 0x8(%r14), %rax
mulsd 0x78(%rax), %xmm0
addsd %xmm1, %xmm0
movq 0x50(%rax), %rax
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
movl %r12d, %edi
movl %r13d, %esi
callq 0x3a524
movsd (%rsp), %xmm1
movq 0x18(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd %xmm1, %xmm0
movq 0x8(%r14), %rax
mulsd 0x78(%rax), %xmm0
movsd %xmm0, (%rdx,%r13,8)
incq %r13
movq (%rbp), %rax
movslq 0x10(%rax), %rcx
cmpq %rcx, %r13
jl 0x8b84f
cmpl $0x0, 0x1c0(%rax)
jle 0x8ba6d
xorl %ebx, %ebx
movsd 0x19ba6(%rip), %xmm2    # 0xa5520
testq %rbx, %rbx
je 0x8b994
leal -0x1(%rbx), %esi
movq 0x68(%rsp), %rdi
callq 0x2ed6a
movapd %xmm0, %xmm2
movq (%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x8ba29
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
movsd %xmm2, 0x70(%rsp)
movsd %xmm1, 0x20(%rsp)
movl %r12d, %edi
movl %r13d, %esi
callq 0x3a524
movsd 0x70(%rsp), %xmm2
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq 0x70(%rax), %rdx
movsd (%rdx,%r13,8), %xmm1
movq 0x70(%rcx), %rdx
subsd (%rdx,%r13,8), %xmm1
mulsd %xmm2, %xmm0
mulsd %xmm0, %xmm1
mulsd 0x78(%rax), %xmm1
mulsd 0x78(%rcx), %xmm1
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm1
incq %r13
movq (%rbp), %rax
movslq 0x10(%rax), %rcx
cmpq %rcx, %r13
jl 0x8b9ab
jmp 0x8ba2d
xorpd %xmm1, %xmm1
movq 0x40(%rsp), %rcx
movsd 0x18(%rcx), %xmm0
movq 0x30(%rsp), %rdx
mulsd (%rdx,%rbx,8), %xmm0
addsd %xmm1, %xmm0
movq 0x40(%r14), %rcx
movq (%rcx,%rbx,8), %rcx
addsd (%rcx), %xmm0
movsd %xmm0, (%rcx)
movsd %xmm1, (%rdx,%rbx,8)
incq %rbx
movslq 0x1c0(%rax), %rcx
cmpq %rcx, %rbx
jl 0x8b972
movq 0x60(%rsp), %rcx
incq %rcx
cmpq 0x50(%rsp), %rcx
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %r12
movq 0x18(%rsp), %rbx
jne 0x8b7cb
movq 0x28(%rsp), %rdi
callq 0x3a180
movsd 0x10(%rsp), %xmm0
mulsd 0x10(%r13), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x48(%rsp), %rax
incl %eax
cmpl 0x4(%r13), %eax
jl 0x8b7a9
movq %r12, %rdi
callq 0x3a180
movq %rbx, %rdi
callq 0x3a180
movq 0x30(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a180