// File: /workspace/github_c_makefile_star2_O1/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 0x2fa14
movl %eax, 0xc(%rsp)
leaq 0x499aa(%rip), %rbp     # 0xd2870
movq (%rbp), %rax
movl 0x1c0(%rax), %edi
movsd 0x19ee0(%rip), %xmm0    # 0xa2db8
movsd 0x19ee0(%rip), %xmm1    # 0xa2dc0
movl $0x1, %esi
callq 0x3dd75
movq %rax, 0x38(%r14)
movq %rdx, 0x40(%r14)
movq (%rbp), %rax
movl 0x10(%rax), %edi
movsd 0x19eb7(%rip), %xmm0    # 0xa2db8
movsd 0x19eb7(%rip), %xmm1    # 0xa2dc0
callq 0x3a083
movq (%r14), %rcx
movq %rax, 0x50(%rcx)
movq (%rbp), %rax
movl 0x10(%rax), %edi
movsd 0x19e94(%rip), %xmm0    # 0xa2db8
movsd 0x19e94(%rip), %xmm1    # 0xa2dc0
callq 0x3a083
movq 0x8(%r14), %rcx
movq %rax, 0x50(%rcx)
movq (%rbp), %rax
movslq 0x1c0(%rax), %rdi
leaq 0x25420(%rip), %r15     # 0xae36b
movl $0x8, %esi
movq %r15, %rdx
movl $0x9, %ecx
callq 0x39210
movq %rax, 0x30(%rsp)
movq (%rbp), %rax
movslq 0x10(%rax), %rdi
movl $0x8, %esi
movq %r15, %rdx
movl $0x9, %ecx
callq 0x39210
movq %rax, %r12
movq (%rbp), %rax
movslq 0x10(%rax), %rdi
movl $0x8, %esi
movq %r15, %rdx
movl $0x9, %ecx
callq 0x39210
movq %rax, %rbx
cmpl $0x0, 0x4(%r13)
jle 0x892dc
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 0x39fdc
movq %rax, 0x28(%rsp)
testl %r15d, %r15d
jle 0x892af
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 0x30fe5
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x88c28
movq %rax, %r15
movq (%rbp), %rax
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0x5458c
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0x2eaca
movl %eax, %r12d
movq 0x18(%r14), %rax
movsd 0x10(%rsp), %xmm0
movq %r14, %rcx
testq %rax, %rax
je 0x8904e
mulsd 0x78(%rcx), %xmm0
movq %rax, %rcx
movq 0x18(%rax), %rax
jmp 0x8903b
movq (%rbp), %rax
cmpl $0x0, 0x10(%rax)
movsd %xmm0, (%rsp)
jle 0x8917b
movq %r13, %rbx
xorl %r13d, %r13d
movl %r12d, %edi
movl %r13d, %esi
callq 0x39518
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 0x39518
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 0x49788(%rip), %rbp     # 0xd2870
movl %r12d, %edi
movl %r13d, %esi
callq 0x39518
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 0x39518
movsd (%rsp), %xmm1
movq 0x18(%rsp), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd %xmm1, %xmm0
movq 0x8(%r14), %rax
mulsd 0x78(%rax), %xmm0
movsd %xmm0, (%rcx,%r13,8)
incq %r13
movq (%rbp), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r13
jl 0x89067
movq (%rbp), %rax
cmpl $0x0, 0x1c0(%rax)
jle 0x8928d
xorl %ebx, %ebx
movsd 0x1938a(%rip), %xmm2    # 0xa2520
testq %rbx, %rbx
je 0x891ac
leal -0x1(%rbx), %esi
movq 0x68(%rsp), %rdi
callq 0x2e4b6
movapd %xmm0, %xmm2
movq (%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x89245
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
movsd %xmm2, 0x70(%rsp)
movsd %xmm1, 0x20(%rsp)
movl %r12d, %edi
movl %r13d, %esi
callq 0x39518
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), %rax
cmpq %rax, %r13
jl 0x891c7
jmp 0x89249
xorpd %xmm1, %xmm1
movq 0x40(%rsp), %rax
movsd 0x18(%rax), %xmm0
movq 0x30(%rsp), %rcx
mulsd (%rcx,%rbx,8), %xmm0
addsd %xmm1, %xmm0
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd %xmm1, (%rcx,%rbx,8)
incq %rbx
movq (%rbp), %rax
movslq 0x1c0(%rax), %rax
cmpq %rax, %rbx
jl 0x8918e
movq 0x60(%rsp), %rcx
incq %rcx
cmpq 0x50(%rsp), %rcx
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %r12
movq 0x18(%rsp), %rbx
jne 0x88fe3
movq 0x28(%rsp), %rdi
callq 0x39194
movsd 0x10(%rsp), %xmm0
mulsd 0x10(%r13), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x48(%rsp), %rax
incl %eax
cmpl 0x4(%r13), %eax
jl 0x88fc1
movq %r12, %rdi
callq 0x39194
movq %rbx, %rdi
callq 0x39194
movq 0x30(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39194