#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 foo();
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int expected = (getenv("DYLD_FRAMEWORK_PATH") != NULL) ? 42 : 1;
  printf("[BEGIN] env-DYLD_FRAMEWORK_PATH, expect %d\n", expected);
  if (foo() == expected)
    printf("[PASS] env-DYLD_FRAMEWORK_PATH\n");
  else
    printf("[FAIL] env-DYLD_FRAMEWORK_PATH\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0x2a,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <foo@plt>
cmp    -0x8(%rbp),%eax
jne    1196 <main+0x66>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a4 <main+0x74>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeef(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
mov    $0x1,%eax
mov    $0x2a,%ebx
cmove  %eax,%ebx
lea    0xe9c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <foo@plt>
cmp    %ebx,%eax
lea    0xece(%rip),%rax
lea    0xea8(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"DYLD_FRAMEWORK_PATH\00"
@.str.1 = [44 x i8] c"[BEGIN] env-DYLD_FRAMEWORK_PATH, expect %d\0A\00"
@.str.2 = [32 x i8] c"[PASS] env-DYLD_FRAMEWORK_PATH\0A\00"
@.str.3 = [32 x i8] c"[FAIL] env-DYLD_FRAMEWORK_PATH\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i32* %3, null
%5 = zext i1 %4 to i64
%6 = select i1 %4, i32 42, i32 1
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @foo()
%10 = load i32, i32* %2
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"DYLD_FRAMEWORK_PATH\00"
@.str.1 = [44 x i8] c"[BEGIN] env-DYLD_FRAMEWORK_PATH, expect %d\0A\00"
@str = [31 x i8] c"[FAIL] env-DYLD_FRAMEWORK_PATH\00"
@str.4 = [31 x i8] c"[PASS] env-DYLD_FRAMEWORK_PATH\00"
define i32 @main() {
%1 = tail call i32* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
%3 = select i1 %2, i32 1, i32 42
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32 (...) @foo()
%6 = icmp eq i32 %5, %3
%7 = select i1 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) %7)
ret i32 0
}