#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct BoolExpr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ BX_DecRef(struct BoolExpr *);
int /*<<< orphan*/ _bx_mark_flags(struct BoolExpr *, int);
struct BoolExpr *_bx_to_nnf(struct BoolExpr *);
struct BoolExpr *_to_dnf(struct BoolExpr *);
struct BoolExpr *BX_ToDNF(struct BoolExpr *ex) {
  struct BoolExpr *nnf;
  struct BoolExpr *dnf;
  do {
    if ((nnf = _bx_to_nnf(ex)) == NULL)
      return NULL;
  } while (0);
  do {
    if ((dnf = _to_dnf(nnf)) == NULL) {
      BX_DecRef(nnf);
      return NULL;
    }
  } while (0);
  BX_DecRef(nnf);
  _bx_mark_flags(dnf, 0x02 | 0x01);
  return dnf;
}


x86 assembly (clang, -O0):
<BX_ToDNF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <_bx_to_nnf@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1170 <BX_ToDNF+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11cb <BX_ToDNF+0x8b>
jmp    1175 <BX_ToDNF+0x35>
jmp    117a <BX_ToDNF+0x3a>
mov    -0x18(%rbp),%rdi
call   1040 <_to_dnf@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a7 <BX_ToDNF+0x67>
mov    -0x18(%rbp),%rdi
call   1050 <BX_DecRef@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cb <BX_ToDNF+0x8b>
jmp    11ac <BX_ToDNF+0x6c>
mov    -0x18(%rbp),%rdi
call   1050 <BX_DecRef@plt>
mov    -0x20(%rbp),%rdi
mov    $0x3,%esi
call   1030 <_bx_mark_flags@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BX_ToDNF>:
push   %r14
push   %rbx
push   %rax
call   1060 <_bx_to_nnf@plt>
test   %rax,%rax
je     1178 <BX_ToDNF+0x38>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <_to_dnf@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <BX_DecRef@plt>
test   %r14,%r14
je     1178 <BX_ToDNF+0x38>
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <_bx_mark_flags@plt>
jmp    117b <BX_ToDNF+0x3b>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.BoolExpr = type { i32 }
define %struct.BoolExpr* @BX_ToDNF(%struct.BoolExpr* %0) {
%2 = alloca %struct.BoolExpr*
%3 = alloca %struct.BoolExpr*
%4 = alloca %struct.BoolExpr*
%5 = alloca %struct.BoolExpr*
store %struct.BoolExpr* %0, %struct.BoolExpr** %3
br label %6
6: ; preds = %1
%7 = load %struct.BoolExpr*, %struct.BoolExpr** %3
%8 = call %struct.BoolExpr* @_bx_to_nnf(%struct.BoolExpr* %7)
store %struct.BoolExpr* %8, %struct.BoolExpr** %4
%9 = icmp eq %struct.BoolExpr* %8, null
br i1 %9, label %10, label %11
10: ; preds = %6
store %struct.BoolExpr* null, %struct.BoolExpr** %2
br label %27
11: ; preds = %6
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
%14 = load %struct.BoolExpr*, %struct.BoolExpr** %4
%15 = call %struct.BoolExpr* @_to_dnf(%struct.BoolExpr* %14)
store %struct.BoolExpr* %15, %struct.BoolExpr** %5
%16 = icmp eq %struct.BoolExpr* %15, null
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load %struct.BoolExpr*, %struct.BoolExpr** %4
%19 = call i32 @BX_DecRef(%struct.BoolExpr* %18)
store %struct.BoolExpr* null, %struct.BoolExpr** %2
br label %27
20: ; preds = %13
br label %21
21: ; preds = %20
%22 = load %struct.BoolExpr*, %struct.BoolExpr** %4
%23 = call i32 @BX_DecRef(%struct.BoolExpr* %22)
%24 = load %struct.BoolExpr*, %struct.BoolExpr** %5
%25 = call i32 @_bx_mark_flags(%struct.BoolExpr* %24, i32 3)
%26 = load %struct.BoolExpr*, %struct.BoolExpr** %5
store %struct.BoolExpr* %26, %struct.BoolExpr** %2
br label %27
27: ; preds = %21, %17, %10
%28 = load %struct.BoolExpr*, %struct.BoolExpr** %2
ret %struct.BoolExpr* %28
}

LLVM IR (-O2):
%struct.BoolExpr = type { i32 }
define %struct.BoolExpr* @BX_ToDNF(%struct.BoolExpr* %0) {
%2 = tail call %struct.BoolExpr* @_bx_to_nnf(%struct.BoolExpr* %0)
%3 = icmp eq %struct.BoolExpr* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call %struct.BoolExpr* @_to_dnf(%struct.BoolExpr* %2)
%6 = icmp eq %struct.BoolExpr* %5, null
%7 = tail call i32 @BX_DecRef(%struct.BoolExpr* %2)
br i1 %6, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @_bx_mark_flags(%struct.BoolExpr* %5, i32 3)
br label %10
10: ; preds = %4, %1, %8
%11 = phi %struct.BoolExpr* [ %5, %8 ], [ null, %1 ], [ null, %4 ]
ret %struct.BoolExpr* %11
}