// File: /workspace/github_c_makefile_star2_O1/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:
ucomiss 0x38(%rdx), %xmm0
jae 0x42dd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %r14d
movq %rcx, %r15
movq %rdx, %r12
movslq %r8d, %rcx
cmpq %rcx, 0x20(%rdx)
jbe 0x42cf
movaps %xmm0, %xmm2
movq %rsi, %r13
movq %rdi, %rbp
movq %r9, 0x20(%rsp)
movl 0x80(%rsp), %ebx
movsd (%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movss %xmm2, 0xc(%rsp)
jbe 0x4105
movq (%rbp), %rdi
movq 0x8(%r12), %rdx
movq %r13, %rsi
movq %rcx, 0x18(%rsp)
callq 0xe2f0
movq %rax, 0x10(%rsp)
movq %r13, %rdi
callq 0x6890
movl 0x20(%r12), %edx
movl 0x80(%rsp), %ecx
movl %ecx, %esi
subl %r14d, %esi
addl %edx, %esi
leaq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %r8
callq 0x38ec
movq 0x18(%r12), %rsi
movsd 0x30(%r12), %xmm0
movq (%rbx), %rdx
leaq 0x28(%rsp), %rax
movq (%rax), %rcx
movq 0x10(%rsp), %rdi
xorl %r8d, %r8d
callq 0xe6d0
movq 0x18(%rsp), %rcx
movl 0x80(%rsp), %ebx
movss 0xc(%rsp), %xmm2
movsd (%r15), %xmm1
ucomisd %xmm0, %xmm1
ja 0x42cf
movq 0x28(%r12), %rax
movq (%rax,%rcx,8), %rsi
movq 0x40(%r12), %rax
movss (%rax,%rcx,4), %xmm0
addss %xmm2, %xmm0
movss 0x38(%r12), %xmm1
ucomiss %xmm0, %xmm1
jb 0x4285
movq 0x20(%rsp), %rax
movq %rcx, 0x18(%rsp)
movb $0x1, (%rax,%rcx)
movq (%rbp), %rdi
movq (%rsi), %rdx
movq %rsi, 0x38(%rsp)
movq 0x8(%rsi), %rcx
movq %r13, %rsi
movl %ebx, %r8d
xorl %r9d, %r9d
callq 0x3825
movq %rax, (%rbp)
movq %r13, %rdi
callq 0x6890
leal 0x1(%rbx), %esi
movl 0x20(%r12), %edx
leaq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %r8
movq %rax, %rdi
movl %esi, 0x10(%rsp)
callq 0x38ec
movq (%rbp), %rdi
movq 0x8(%r12), %rdx
movq %r13, %rsi
callq 0xe2f0
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq $0x0, (%rax)
movq %rax, %r8
movq 0x18(%r12), %rsi
movsd 0x30(%r12), %xmm0
leaq 0x30(%rsp), %rax
movq (%rax), %rdx
leaq 0x28(%rsp), %rax
movq (%rax), %rcx
movq %rbx, %rdi
callq 0xe6d0
leaq 0x40(%rsp), %rax
movsd (%rax), %xmm0
ucomisd (%r15), %xmm0
ja 0x41fd
jne 0x4224
jp 0x4224
movq 0x40(%r12), %rax
movq 0x18(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
addss 0xc(%rsp), %xmm1
movss 0x10(%r15), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x4224
movq 0x20(%r12), %rdx
movq 0x40(%r12), %rax
movq 0x18(%rsp), %rcx
movss (%rax,%rcx,4), %xmm1
addss 0xc(%rsp), %xmm1
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x4f4f
testq %rbx, %rbx
je 0x4231
movq %rbx, %rdi
callq 0xe3a0
leal 0x1(%r14), %r8d
movq 0x40(%r12), %rax
movq 0x18(%rsp), %rbx
movss (%rax,%rbx,4), %xmm0
addss 0xc(%rsp), %xmm0
movl 0x10(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r15, 0x10(%rsp)
movq 0x20(%rsp), %r15
movq %r15, %r9
callq 0x4019
movb $0x0, (%r15,%rbx)
movq 0x10(%rsp), %r15
movl 0x80(%rsp), %ebx
movq 0x38(%rsp), %rsi
movq (%rbp), %rdi
movq (%rsi), %rdx
movq 0x8(%rsi), %rcx
movl %ebx, %r8d
subl %r14d, %r8d
addl 0x20(%r12), %r8d
movq %r13, %rsi
xorl %r9d, %r9d
callq 0x3825
movq %rax, (%rbp)
incl %r14d
movl %ebx, (%rsp)
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r14d, %r8d
movq 0x20(%rsp), %r9
movss 0xc(%rsp), %xmm0
callq 0x4019
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq