// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rsi, %r14
movq %rdi, 0x58(%rsp)
movq 0x20(%rdi), %rdi
callq 0x2c3cc
movl %eax, 0xc(%rsp)
leaq 0x4f938(%rip), %rbp     # 0xcd870
movq (%rbp), %rax
movl 0x1c0(%rax), %edi
pushq $0x1
popq %rsi
movsd 0x17e73(%rip), %xmm0    # 0x95dc0
movsd 0x17e73(%rip), %xmm1    # 0x95dc8
callq 0x393f5
movq %rax, 0x38(%r14)
movq %rdx, 0x40(%r14)
movq (%rbp), %rax
movl 0x10(%rax), %edi
movsd 0x17e4f(%rip), %xmm0    # 0x95dc0
movsd 0x17e4f(%rip), %xmm1    # 0x95dc8
callq 0x35d84
movq (%r14), %rcx
movq %rax, 0x50(%rcx)
movq (%rbp), %rax
movl 0x10(%rax), %edi
movsd 0x17e2c(%rip), %xmm0    # 0x95dc0
movsd 0x17e2c(%rip), %xmm1    # 0x95dc8
callq 0x35d84
movq 0x8(%r14), %rcx
movq %rax, 0x50(%rcx)
movq (%rbp), %rax
movslq 0x1c0(%rax), %rdi
leaq 0x233a8(%rip), %r15     # 0xa1363
pushq $0x8
popq %r12
pushq $0x9
popq %r13
movq %r12, %rsi
movq %r15, %rdx
movl %r13d, %ecx
callq 0x35067
movq %rax, 0x40(%rsp)
movq (%rbp), %rax
movslq 0x10(%rax), %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %r13d, %ecx
callq 0x35067
movq %rax, 0x38(%rsp)
movq (%rbp), %rax
movslq 0x10(%rax), %rdi
movq %r12, %rsi
movq %r15, %rdx
movl %r13d, %ecx
callq 0x35067
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x60(%rsp)
movq %rbx, 0x18(%rsp)
cmpl 0x4(%rbx), %eax
jge 0x7e2ea
movq %rax, 0x50(%rsp)
movl 0xc(%rsp), %edi
callq 0x35cf7
movq %rax, 0x28(%rsp)
xorl %ecx, %ecx
cmpq 0x60(%rsp), %rcx
je 0x7e2c3
movq 0x58(%rsp), %r15
movq 0x20(%r15), %rdi
movq 0x28(%rsp), %rax
movq %rcx, 0x68(%rsp)
movl (%rax,%rcx,4), %esi
callq 0x2d761
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x7dcac
movq %rax, %r15
movq (%rbp), %rax
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0x4dd7c
movq %rbx, 0x70(%rsp)
movq %rbx, %rdi
callq 0x2b47e
movl %eax, %r12d
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq %r14, %rax
movq 0x18(%rax), %rcx
testq %rcx, %rcx
je 0x7e0c0
movsd (%rsp), %xmm0
mulsd 0x78(%rax), %xmm0
movsd %xmm0, (%rsp)
movq %rcx, %rax
jmp 0x7e0a3
xorl %r13d, %r13d
movq (%rbp), %rax
movslq 0x10(%rax), %rcx
cmpq %rcx, %r13
jge 0x7e1c6
movl %r12d, %edi
movl %r13d, %esi
callq 0x352f4
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movq 0x18(%rsp), %rbp
movsd 0x18(%rbp), %xmm1
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 0x352f4
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movq (%r14), %rax
mulsd 0x78(%rax), %xmm0
movsd %xmm0, (%rbx,%r13,8)
movl %r12d, %edi
movl %r13d, %esi
callq 0x352f4
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movsd 0x18(%rbp), %xmm1
leaq 0x4f703(%rip), %rbp     # 0xcd870
movq 0x30(%rsp), %rbx
mulsd (%rbx,%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 0x352f4
cvtsi2sd %eax, %xmm0
subsd (%r15,%r13,8), %xmm0
mulsd (%rsp), %xmm0
movq 0x8(%r14), %rax
mulsd 0x78(%rax), %xmm0
movsd %xmm0, (%rbx,%r13,8)
incq %r13
jmp 0x7e0c3
xorl %ebx, %ebx
movslq 0x1c0(%rax), %rax
cmpq %rax, %rbx
jge 0x7e2b1
movsd 0x17340(%rip), %xmm0    # 0x95520
movsd %xmm0, 0x48(%rsp)
testq %rbx, %rbx
je 0x7e1fe
leal -0x1(%rbx), %esi
movq 0x70(%rsp), %rdi
callq 0x2aea2
movsd %xmm0, 0x48(%rsp)
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
movq (%rbp), %rax
movslq 0x10(%rax), %rcx
cmpq %rcx, %r13
jge 0x7e27c
movl %r12d, %edi
movl %r13d, %esi
movsd %xmm1, 0x20(%rsp)
callq 0x352f4
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 0x48(%rsp), %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
jmp 0x7e205
movq 0x18(%rsp), %rcx
movsd 0x18(%rcx), %xmm0
movq 0x40(%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
jmp 0x7e1c8
movq 0x68(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rbx
jmp 0x7e03f
movq 0x28(%rsp), %rdi
callq 0x34ff7
movsd 0x10(%rsp), %xmm0
mulsd 0x10(%rbx), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x50(%rsp), %rax
incl %eax
jmp 0x7e021
movq 0x38(%rsp), %rdi
callq 0x34ff7
movq 0x30(%rsp), %rdi
callq 0x34ff7
movq 0x40(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34ff7