// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movl 0xa0(%rsp), %eax
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movl %r8d, 0x74(%rsp)
movq %r9, 0x68(%rsp)
movss %xmm0, 0x64(%rsp)
movss 0x64(%rsp), %xmm0
movq 0x80(%rsp), %rax
ucomiss 0x38(%rax), %xmm0
jae 0x4982
movslq 0x74(%rsp), %rax
movq 0x80(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jb 0x4987
jmp 0x4d55
movq 0x78(%rsp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4a6f
movq 0x90(%rsp), %rax
movq (%rax), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0xf280
movq %rax, 0x48(%rsp)
movq 0x88(%rsp), %rdi
callq 0x7820
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq 0x80(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x74(%rsp), %rcx
subq %rcx, %rax
movslq 0xa0(%rsp), %rcx
addq %rcx, %rax
movl %eax, %esi
movq 0x80(%rsp), %rax
movq 0x20(%rax), %rax
movl %eax, %edx
leaq 0x58(%rsp), %rcx
leaq 0x50(%rsp), %r8
callq 0x3c40
movq 0x48(%rsp), %rdi
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x80(%rsp), %rax
movsd 0x30(%rax), %xmm0
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0xf660
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm1
movq 0x78(%rsp), %rax
movsd (%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4a6d
jmp 0x4d55
jmp 0x4a6f
movq 0x80(%rsp), %rax
movq 0x28(%rax), %rax
movslq 0x74(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movss 0x64(%rsp), %xmm1
movq 0x80(%rsp), %rax
movq 0x40(%rax), %rax
movslq 0x74(%rsp), %rcx
addss (%rax,%rcx,4), %xmm1
movq 0x80(%rsp), %rax
movss 0x38(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x4cb9
movq 0x68(%rsp), %rax
movslq 0x74(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movq 0x90(%rsp), %rax
movq (%rax), %rdi
movq 0x88(%rsp), %rsi
movq 0x30(%rsp), %rax
movq (%rax), %rdx
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
movl 0xa0(%rsp), %r8d
xorl %r9d, %r9d
callq 0x3b00
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, (%rax)
movq 0x88(%rsp), %rdi
callq 0x7820
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movl 0xa0(%rsp), %esi
addl $0x1, %esi
movq 0x80(%rsp), %rax
movq 0x20(%rax), %rax
movl %eax, %edx
leaq 0x58(%rsp), %rcx
leaq 0x50(%rsp), %r8
callq 0x3c40
movq 0x90(%rsp), %rax
movq (%rax), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0xf280
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rax
movq 0x18(%rax), %rsi
movq 0x80(%rsp), %rax
movsd 0x30(%rax), %xmm0
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0xf660
movsd %xmm0, 0x10(%rsp)
movsd 0x18(%rsp), %xmm0
movq 0x78(%rsp), %rax
ucomisd (%rax), %xmm0
ja 0x4c02
movsd 0x18(%rsp), %xmm0
movq 0x78(%rsp), %rax
ucomisd (%rax), %xmm0
jne 0x4c3f
jp 0x4c3f
movss 0x64(%rsp), %xmm1
movq 0x80(%rsp), %rax
movq 0x40(%rax), %rax
movslq 0x74(%rsp), %rcx
addss (%rax,%rcx,4), %xmm1
movq 0x78(%rsp), %rax
movss 0x10(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4c3f
movq 0x78(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
movss 0x64(%rsp), %xmm1
movq 0x80(%rsp), %rax
movq 0x40(%rax), %rax
movslq 0x74(%rsp), %rcx
addss (%rax,%rcx,4), %xmm1
movq 0x68(%rsp), %rsi
movq 0x80(%rsp), %rax
movq 0x20(%rax), %rdx
callq 0x5e90
cmpq $0x0, 0x20(%rsp)
je 0x4c51
movq 0x20(%rsp), %rdi
callq 0xf330
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl 0x74(%rsp), %r8d
addl $0x1, %r8d
movq 0x68(%rsp), %r9
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movss 0x64(%rsp), %xmm0
movq 0x80(%rsp), %r10
movq 0x40(%r10), %r10
movslq 0x74(%rsp), %r11
addss (%r10,%r11,4), %xmm0
movl %eax, (%rsp)
callq 0x4920
movq 0x68(%rsp), %rax
movslq 0x74(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x90(%rsp), %rax
movq (%rax), %rdi
movq 0x88(%rsp), %rsi
movq 0x30(%rsp), %rax
movq (%rax), %rdx
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x80(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x74(%rsp), %r8
subq %r8, %rax
movslq 0xa0(%rsp), %r8
addq %r8, %rax
movl %eax, %r8d
xorl %r9d, %r9d
callq 0x3b00
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, (%rax)
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl 0x74(%rsp), %r8d
addl $0x1, %r8d
movq 0x68(%rsp), %r9
movl 0xa0(%rsp), %eax
movss 0x64(%rsp), %xmm0
movl %eax, (%rsp)
callq 0x4920
addq $0x98, %rsp
retq
nopl (%rax)