#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 EXIT_SUCCESS;
int /*<<< orphan*/ FAIL(char *);
int /*<<< orphan*/ PASS(char *);
int foo();
int /*<<< orphan*/ *getenv(char *);
int main(int argc, const char *argv[]) {
  if (getenv("DYLD_INSERT_LIBRARIES") == NULL) {
    if (foo() != 0) {
      FAIL("symbol-resolver-interposed: foo() != 0");
      return EXIT_SUCCESS;
    }
  } else {
    if (foo() != 20) {
      FAIL("symbol-resolver-interposed: foo() != 20");
      return EXIT_SUCCESS;
    }
  }
  PASS("symbol-resolver-interposed");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    119e <main+0x5e>
mov    $0x0,%al
call   1040 <foo@plt>
cmp    $0x0,%eax
je     1199 <main+0x59>
lea    0xe93(%rip),%rdi
call   1060 <FAIL@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <main+0xa8>
jmp    11d0 <main+0x90>
mov    $0x0,%al
call   1040 <foo@plt>
cmp    $0x14,%eax
je     11cb <main+0x8b>
lea    0xe88(%rip),%rdi
call   1060 <FAIL@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e8 <main+0xa8>
jmp    11d0 <main+0x90>
lea    0xe8e(%rip),%rdi
call   1050 <PASS@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <foo@plt>
test   %rbx,%rbx
je     116f <main+0x2f>
cmp    $0x14,%eax
je     1181 <main+0x41>
lea    0xed5(%rip),%rdi
call   1060 <FAIL@plt>
jmp    118d <main+0x4d>
test   %eax,%eax
je     1181 <main+0x41>
lea    0xe9c(%rip),%rdi
call   1060 <FAIL@plt>
jmp    118d <main+0x4d>
lea    0xedd(%rip),%rdi
call   1050 <PASS@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"DYLD_INSERT_LIBRARIES\00"
@.str.1 = [39 x i8] c"symbol-resolver-interposed: foo() != 0\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [40 x i8] c"symbol-resolver-interposed: foo() != 20\00"
@.str.3 = [27 x i8] c"symbol-resolver-interposed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32* @getenv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = call i32 (...) @foo()
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @FAIL(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_SUCCESS
store i32 %13, i32* %3
br label %25
14: ; preds = %8
br label %22
15: ; preds = %2
%16 = call i32 (...) @foo()
%17 = icmp ne i32 %16, 20
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @FAIL(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_SUCCESS
store i32 %20, i32* %3
br label %25
21: ; preds = %15
br label %22
22: ; preds = %21, %14
%23 = call i32 @PASS(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %18, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [22 x i8] c"DYLD_INSERT_LIBRARIES\00"
@.str.1 = [39 x i8] c"symbol-resolver-interposed: foo() != 0\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [40 x i8] c"symbol-resolver-interposed: foo() != 20\00"
@.str.3 = [27 x i8] c"symbol-resolver-interposed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @getenv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
%5 = tail call i32 (...) @foo()
br i1 %4, label %6, label %10
6: ; preds = %2
%7 = icmp eq i32 %5, 0
br i1 %7, label %14, label %8
8: ; preds = %6
%9 = tail call i32 @FAIL(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %16
10: ; preds = %2
%11 = icmp eq i32 %5, 20
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = tail call i32 @FAIL(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %10, %6
%15 = tail call i32 @PASS(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12, %8
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}