#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 func1();
int func2();
int /*<<< orphan*/ printf(char *, int, char *);
int main(void) {
  int f1, f2, expect1 = 1, expect2 = 2;
  f1 = func1();
  f2 = func2();
  printf("func1() returns %d: %s\n", f1, (f1 == expect1) ? "OK" : "FAIL");
  printf("func2() returns %d: %s\n", f2, (f2 == expect2) ? "OK" : "FAIL");
  if (f1 != expect1 || f2 != expect2)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
mov    $0x0,%al
call   1030 <func1@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <func2@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%edi
lea    0xeaa(%rip),%rdx
lea    0xea0(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%edi
lea    0xe81(%rip),%rdx
lea    0xe77(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11cb <main+0x9b>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11d7 <main+0xa7>
movl   $0x1,-0x4(%rbp)
jmp    11de <main+0xae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1030 <func1@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <func2@plt>
mov    %eax,%r14d
cmp    $0x1,%ebx
sete   %r15b
lea    0xebf(%rip),%r12
lea    0xebb(%rip),%rbp
mov    %rbp,%rdx
cmove  %r12,%rdx
lea    0xe92(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
cmp    $0x2,%r14d
sete   %bl
cmove  %r12,%rbp
lea    0xe99(%rip),%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1040 <printf@plt>
and    %r15b,%bl
xor    $0x1,%bl
movzbl %bl,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"func1() returns %d: %s\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [5 x i8] c"FAIL\00"
@.str.3 = [24 x i8] c"func2() returns %d: %s\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @func1()
%2 = tail call i32 (...) @func2()
%3 = icmp eq i32 %1, 1
%4 = select i1 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %4)
%6 = icmp eq i32 %2, 2
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %2, i8* %7)
%9 = select i1 %3, i1 %6, i1 false
%10 = xor i1 %9, true
%11 = zext i1 %10 to i32
ret i32 %11
}