// File: /workspace/github_c_makefile_star2_O2/UCLA-StarAI[P]TrimBN/src/trim/search.c
// Function: search_best_subset_aux
void search_best_subset_aux(SddNode** node, SddManager* manager,
    SearchData* data, SearchResult* result, int cur_depth,
    char* subset, int num_included, float cur_cost) {
  // Backtrack if budget exceeded
  if (cur_cost >= data->budget || cur_depth >= data->num_features) {
    return;
  }

  SddLiteral y_vtree, xy_vtree;   
  if (result->best_score > 0) {
    // compute MPA, with size of Y being number of included and unassigned features
    EsdpManager* e_manager = esdp_manager_new(*node, manager, data->literal_weights);
    Vtree* vtree = sdd_manager_vtree(manager);
    update_constrained_positions(
        vtree, data->num_features-cur_depth+num_included, data->num_features, &y_vtree, &xy_vtree);
    SddWmc bound = compute_mpa(e_manager, data->decision, data->threshold, xy_vtree, y_vtree, NULL);
    if (bound < result->best_score) {
      return;
    }
  }

  Feature* feature = data->features[cur_depth];
  if (cur_cost + data->costs[cur_depth] <= data->budget) {
    subset[cur_depth] = 1;

    // Move vtree variables so that features appear in right order
    *node = sdd_move_feature_to_pos(*node, manager, feature->indicators,
                                    feature->num_indicators, num_included, 0);

    // Update constrained positions for Y to include cur feature
    Vtree* vtree = sdd_manager_vtree(manager);
    update_constrained_positions(
        vtree, num_included+1, data->num_features, &y_vtree, &xy_vtree);

    // Compute agreement score
    EsdpManager* e_manager =
        esdp_manager_new(*node, manager, data->literal_weights);
    SddWmc maa = 0;
    SddWmc mpa = compute_mpa(e_manager, data->decision, data->threshold, xy_vtree, y_vtree, &maa);

    // Update the current best subset. Tie-break by cost
    if (maa > result->best_score || (maa == result->best_score
        && cur_cost + data->costs[cur_depth] < result->cost)) {
      update_search_result(result, maa, cur_cost+data->costs[cur_depth],
                           subset, data->num_features);
    }
    if (e_manager != NULL) esdp_manager_free(e_manager);

    search_best_subset_aux(node, manager, data, result, cur_depth+1, subset,
                           num_included+1, cur_cost + data->costs[cur_depth]);
    subset[cur_depth] = 0;
  }

  // move next_feature to (num included+unassigned feature) pos in vtree
  *node = sdd_move_feature_to_pos(*node, manager, feature->indicators, feature->num_indicators,
                                  data->num_features-cur_depth+num_included, 0);

  // recursive run with next_feature excluded
  search_best_subset_aux(node, manager, data, result, cur_depth+1, subset,
                         num_included, cur_cost);
}

// Assembly:
movss 0x38(%rdx), %xmm3
ucomiss %xmm3, %xmm0
jae 0x3b1a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, %ebp
movq %rdx, %r15
movslq %r8d, %rbx
cmpq %rbx, 0x20(%rdx)
jbe 0x3b0c
movq %rcx, %r14
movq %rsi, %r12
movq %rdi, %r13
movq %r9, 0x20(%rsp)
movsd (%rcx), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
movss %xmm0, 0x14(%rsp)
jbe 0x393a
movq (%r13), %rdi
movq 0x8(%r15), %rdx
movq %r12, %rsi
callq 0xda70
movq %rax, 0x18(%rsp)
movq %r12, %rdi
callq 0x6010
movl 0x20(%r15), %edx
movl 0x90(%rsp), %ecx
movl %ecx, %esi
subl %ebp, %esi
addl %edx, %esi
leaq 0x30(%rsp), %rcx
leaq 0x28(%rsp), %r8
movq %rax, %rdi
callq 0x3184
movq 0x18(%r15), %rsi
movsd 0x30(%r15), %xmm0
leaq 0x28(%rsp), %rax
movq (%rax), %rdx
leaq 0x30(%rsp), %rax
movq (%rax), %rcx
movq 0x18(%rsp), %rdi
xorl %r8d, %r8d
callq 0xde50
movsd (%r14), %xmm1
ucomisd %xmm0, %xmm1
ja 0x3b0c
movss 0x38(%r15), %xmm3
movss 0x14(%rsp), %xmm0
movq 0x28(%r15), %rax
movq 0x40(%r15), %rcx
movq (%rax,%rbx,8), %rsi
movss (%rcx,%rbx,4), %xmm1
addss %xmm0, %xmm1
ucomiss %xmm1, %xmm3
movq %r14, 0x48(%rsp)
jae 0x396a
leal 0x1(%rbp), %eax
movl %eax, 0x18(%rsp)
movq 0x20(%rsp), %r14
jmp 0x3aba
movq 0x20(%rsp), %rax
movb $0x1, (%rax,%rbx)
movq (%r13), %rdi
movq (%rsi), %rdx
movq %rsi, 0x40(%rsp)
movq 0x8(%rsi), %rcx
movq %r12, %rsi
movl 0x90(%rsp), %eax
movq %rax, %r8
xorl %r9d, %r9d
callq 0x30cc
movq %rax, (%r13)
movq %r12, %rdi
callq 0x6010
movl 0x90(%rsp), %ecx
leal 0x1(%rcx), %esi
movl 0x20(%r15), %edx
leaq 0x30(%rsp), %rcx
leaq 0x28(%rsp), %r8
movq %rax, %rdi
movl %esi, 0x18(%rsp)
callq 0x3184
movq (%r13), %rdi
movq 0x8(%r15), %rdx
movq %r12, %rsi
callq 0xda70
leaq 0x50(%rsp), %rcx
andq $0x0, (%rcx)
movq %rcx, %r8
movq 0x18(%r15), %rsi
movsd 0x30(%r15), %xmm0
leaq 0x28(%rsp), %rcx
movq (%rcx), %rdx
leaq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, 0x38(%rsp)
movq %rax, %rdi
callq 0xde50
leaq 0x50(%rsp), %rax
movsd (%rax), %xmm0
ucomisd (%r14), %xmm0
jbe 0x3a2c
movq 0x40(%r15), %rax
movss (%rax,%rbx,4), %xmm1
addss 0x14(%rsp), %xmm1
jmp 0x3a4e
movss 0x14(%rsp), %xmm3
jne 0x3a65
jp 0x3a65
movq 0x40(%r15), %rax
movss (%rax,%rbx,4), %xmm1
addss %xmm3, %xmm1
movss 0x10(%r14), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x3a65
movq 0x20(%r15), %rdx
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x46d4
movss 0x14(%rsp), %xmm3
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x3a7a
callq 0xdb20
movss 0x14(%rsp), %xmm3
leal 0x1(%rbp), %r8d
movq 0x40(%r15), %rax
movss (%rax,%rbx,4), %xmm0
addss %xmm3, %xmm0
movl 0x18(%rsp), %eax
movl %eax, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movl %r8d, 0x18(%rsp)
movq 0x20(%rsp), %r14
movq %r14, %r9
callq 0x3863
movb $0x0, (%r14,%rbx)
movq 0x40(%rsp), %rsi
movq (%r13), %rdi
movq (%rsi), %rdx
movq 0x8(%rsi), %rcx
movl 0x90(%rsp), %eax
movq %rax, %rbx
movl %ebx, %r8d
subl %ebp, %r8d
addl 0x20(%r15), %r8d
movq %r12, %rsi
xorl %r9d, %r9d
callq 0x30cc
movq %rax, (%r13)
movl %ebx, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq 0x48(%rsp), %rcx
movl 0x18(%rsp), %r8d
movq %r14, %r9
movss 0x14(%rsp), %xmm0
callq 0x3863
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq