// File: /workspace/github_c_makefile_star2_O0/UCLA-StarAI[P]TrimBN/src/trim/move.c
// Function: sdd_move_var_to_pos
SddNode* sdd_move_var_to_pos(SddLiteral var, int to_left, Vtree* new_sibling,
    SddNode* node, SddManager* manager) {
  if (to_left) {
    Vtree* left = sdd_vtree_left(new_sibling);
    if (left != NULL && sdd_vtree_var(left) == var) {
      return node;
    }
  } else {
    Vtree* right = sdd_vtree_right(new_sibling);
    if (right != NULL && sdd_vtree_var(right) == var) {
      return node;
    }
  }

  // Condition the SDD node on positive and negative literals of var.
  // Resulting SDD nodes do not contain var, and now we can move it freely.
  SddNode* node1 = sdd_condition(var, node, manager);
  SddNode* node0 = sdd_condition(-var, node, manager);

  // Garbage collect node
  sdd_ref(node1, manager);
  sdd_ref(node0, manager);
  sdd_deref(node, manager);
  sdd_manager_garbage_collect(manager);

  // Move variable to left/right of new_sibling and join the SDDs
  SddNode* tmp1;
  SddNode* tmp0;
  move_var_in_vtree(var, to_left ? 'l' : 'r', new_sibling, manager);
  node1 = sdd_conjoin(sdd_manager_literal(var,manager), tmp1=node1, manager);
  node0 = sdd_conjoin(sdd_manager_literal(-var,manager), tmp0=node0, manager);
  SddNode* return_node = sdd_disjoin(node1, node0, manager);

  // Garbage collect node1 and node0
  sdd_ref(return_node, manager);
  sdd_deref(tmp1, manager);
  sdd_deref(tmp0, manager);
  sdd_manager_garbage_collect(manager);

  return return_node;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movl %esi, 0x54(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
cmpl $0x0, 0x54(%rsp)
je 0x396c
movq 0x48(%rsp), %rdi
callq 0x78e0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0x396a
movq 0x30(%rsp), %rdi
callq 0x7920
cmpq 0x58(%rsp), %rax
jne 0x396a
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x3aee
jmp 0x39a5
movq 0x48(%rsp), %rdi
callq 0x78f0
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x39a3
movq 0x28(%rsp), %rdi
callq 0x7920
cmpq 0x58(%rsp), %rax
jne 0x39a3
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x3aee
jmp 0x39a5
movq 0x58(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xeec0
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movl %eax, %edi
subq 0x58(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xeec0
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xa950
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xa950
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xaa40
movq 0x38(%rsp), %rdi
callq 0x75c0
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %edx
movl $0x72, %eax
movl $0x6c, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movq 0x48(%rsp), %rdx
movq 0x38(%rsp), %rcx
movsbl %al, %esi
callq 0xb310
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x7550
movq %rax, %rdi
movq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq 0x38(%rsp), %rdx
callq 0x75a0
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movl %eax, %edi
subq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x7550
movq %rax, %rdi
movq 0x18(%rsp), %rsi
movq %rsi, 0x8(%rsp)
movq 0x38(%rsp), %rdx
callq 0x75a0
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x75b0
movq %rax, (%rsp)
movq (%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xa950
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xaa40
movq 0x8(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xaa40
movq 0x38(%rsp), %rdi
callq 0x75c0
movq (%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopl (%rax,%rax)