#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 *);
struct BoolExpr *BX_PushDownNot(struct BoolExpr *);
struct BoolExpr *_bx_simplify(struct BoolExpr *);
struct BoolExpr *_nnfify(struct BoolExpr *);
struct BoolExpr *_bx_to_nnf(struct BoolExpr *ex) {
  struct BoolExpr *t0, *t1;
  struct BoolExpr *nnf;
  do {
    if ((t0 = _nnfify(ex)) == NULL)
      return NULL;
  } while (0);
  do {
    if ((t1 = BX_PushDownNot(t0)) == NULL) {
      BX_DecRef(t0);
      return NULL;
    }
  } while (0);
  BX_DecRef(t0);
  do {
    if ((nnf = _bx_simplify(t1)) == NULL) {
      BX_DecRef(t1);
      return NULL;
    }
  } while (0);
  BX_DecRef(t1);
  return nnf;
}


x86 assembly (clang, -O0):
<_bx_to_nnf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <_nnfify@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1170 <_bx_to_nnf+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <_bx_to_nnf+0xb8>
jmp    1175 <_bx_to_nnf+0x35>
jmp    117a <_bx_to_nnf+0x3a>
mov    -0x18(%rbp),%rdi
call   1050 <BX_PushDownNot@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a7 <_bx_to_nnf+0x67>
mov    -0x18(%rbp),%rdi
call   1060 <BX_DecRef@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <_bx_to_nnf+0xb8>
jmp    11ac <_bx_to_nnf+0x6c>
mov    -0x18(%rbp),%rdi
call   1060 <BX_DecRef@plt>
mov    -0x20(%rbp),%rdi
call   1030 <_bx_simplify@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e2 <_bx_to_nnf+0xa2>
mov    -0x20(%rbp),%rdi
call   1060 <BX_DecRef@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <_bx_to_nnf+0xb8>
jmp    11e7 <_bx_to_nnf+0xa7>
mov    -0x20(%rbp),%rdi
call   1060 <BX_DecRef@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_bx_to_nnf>:
push   %r14
push   %rbx
push   %rax
call   1040 <_nnfify@plt>
test   %rax,%rax
je     1181 <_bx_to_nnf+0x41>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <BX_PushDownNot@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <BX_DecRef@plt>
test   %r14,%r14
je     1181 <_bx_to_nnf+0x41>
mov    %r14,%rdi
call   1030 <_bx_simplify@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <BX_DecRef@plt>
mov    %rbx,%rax
jmp    1183 <_bx_to_nnf+0x43>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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