#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 */

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, char *);
int expect_ptr(int expected, void *result) {
  printf("\tPTR Expected %s, Got %s\n", expected == 0 ? "NON-NULL" : "NULL",
         result == NULL ? "NULL" : "NON-NULL");
  fflush(NULL);
  if (expected == 0) {
    if (result == NULL) {
      return -1;
    }
    return 0;
  }
  if (expected == -1) {
    if (result == NULL) {
      return 0;
    }
    return -1;
  }
}


x86 assembly (clang, -O0):
<expect_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
lea    0xee5(%rip),%rsi
lea    0xeda(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
mov    -0x10(%rbp),%rcx
lea    0xec8(%rip),%rdx
lea    0xec5(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rdx
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11a3 <expect_ptr+0x83>
cmpq   $0x0,-0x10(%rbp)
jne    1197 <expect_ptr+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <expect_ptr+0xab>
movl   $0x0,-0x4(%rbp)
jmp    11cb <expect_ptr+0xab>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11cb <expect_ptr+0xab>
cmpq   $0x0,-0x10(%rbp)
jne    11c4 <expect_ptr+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    11cb <expect_ptr+0xab>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect_ptr>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
sete   %bpl
lea    0xeea(%rip),%rdx
lea    0xee7(%rip),%rcx
mov    %rcx,%rax
cmove  %rdx,%rax
test   %rsi,%rsi
sete   %bl
cmove  %rcx,%rdx
lea    0xeb1(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
xor    %bpl,%bl
movzbl %bl,%eax
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\09PTR Expected %s, Got %s\0A\00"
@.str.1 = [9 x i8] c"NON-NULL\00"
@.str.2 = [5 x i8] c"NULL\00"
define i32 @expect_ptr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i64
%9 = select i1 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %13)
%15 = call i32 @fflush(i32* null)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %3
br label %31
22: ; preds = %18
store i32 0, i32* %3
br label %31
23: ; preds = %2
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 0, i32* %3
br label %31
30: ; preds = %26
store i32 -1, i32* %3
br label %31
31: ; preds = %21, %22, %29, %30, %23
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [26 x i8] c"\09PTR Expected %s, Got %s\0A\00"
@.str.1 = [9 x i8] c"NON-NULL\00"
@.str.2 = [5 x i8] c"NULL\00"
define i32 @expect_ptr(i32 %0, i8* readnone %1) {
%3 = icmp eq i32 %0, 0
%4 = select i1 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%5 = icmp eq i8* %1, null
%6 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %6)
%8 = tail call i32 @fflush(i32* null)
%9 = xor i1 %3, %5
%10 = xor i1 %9, true
%11 = sext i1 %10 to i32
ret i32 %11
}