#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 expression {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ constant_integer_int(int /*<<< orphan*/);
struct expression *expr_constant(int /*<<< orphan*/);
int /*<<< orphan*/ expr_is_test(struct expression const *);
struct expression *expr_neq(struct expression const *,
                            struct expression const *);
const struct expression *to_boolean(const struct expression *cond) {
  if (!expr_is_test(cond)) {
    const struct expression *zero = expr_constant(constant_integer_int(0));
    cond = expr_neq(cond, zero);
  }
  return cond;
}


x86 assembly (clang, -O0):
<to_boolean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <expr_is_test@plt>
cmp    $0x0,%eax
jne    1181 <to_boolean+0x41>
xor    %edi,%edi
call   1030 <constant_integer_int@plt>
mov    %eax,%edi
call   1050 <expr_constant@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <expr_neq@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_boolean>:
push   %rbx
mov    %rdi,%rbx
call   1040 <expr_is_test@plt>
test   %eax,%eax
je     1152 <to_boolean+0x12>
mov    %rbx,%rax
pop    %rbx
ret
xor    %edi,%edi
call   1030 <constant_integer_int@plt>
mov    %eax,%edi
call   1050 <expr_constant@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
jmp    1060 <expr_neq@plt>

LLVM IR (-O0):
%struct.expression = type { i32 }
define %struct.expression* @to_boolean(%struct.expression* %0) {
%2 = alloca %struct.expression*
%3 = alloca %struct.expression*
store %struct.expression* %0, %struct.expression** %2
%4 = load %struct.expression*, %struct.expression** %2
%5 = call i32 @expr_is_test(%struct.expression* %4)
%6 = icmp ne i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = call i32 @constant_integer_int(i32 0)
%9 = call %struct.expression* @expr_constant(i32 %8)
store %struct.expression* %9, %struct.expression** %3
%10 = load %struct.expression*, %struct.expression** %2
%11 = load %struct.expression*, %struct.expression** %3
%12 = call %struct.expression* @expr_neq(%struct.expression* %10, %struct.expression* %11)
store %struct.expression* %12, %struct.expression** %2
br label %13
13: ; preds = %7, %1
%14 = load %struct.expression*, %struct.expression** %2
ret %struct.expression* %14
}

LLVM IR (-O2):
%struct.expression = type { i32 }
define %struct.expression* @to_boolean(%struct.expression* %0) {
%2 = tail call i32 @expr_is_test(%struct.expression* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @constant_integer_int(i32 0)
%6 = tail call %struct.expression* @expr_constant(i32 %5)
%7 = tail call %struct.expression* @expr_neq(%struct.expression* %0, %struct.expression* %6)
br label %8
8: ; preds = %4, %1
%9 = phi %struct.expression* [ %0, %1 ], [ %7, %4 ]
ret %struct.expression* %9
}