#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 bar();
int foo();
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ *strstr(char const *, char *);
int main() {
  const char *suffix = getenv("DYLD_IMAGE_SUFFIX");
  if (suffix == NULL)
    suffix = "";
  printf("[BEGIN] env-DYLD_IMAGE_SUFFIX-%s\n", suffix);
  const int expectedFoo = (strstr(suffix, "_other") != NULL) ? 42 : 1;
  const int expectedBar = (strstr(suffix, "_alt") != NULL) ? 42 : 1;
  ;
  int fooValue = foo();
  int barValue = bar();
  if (fooValue != expectedFoo)
    printf("[FAIL]  env-DYLD_IMAGE_SUFFIX-%s, foo()=%d expected=%d\n", suffix,
           fooValue, expectedFoo);
  else if (barValue != expectedBar)
    printf("[FAIL]  env-DYLD_IMAGE_SUFFIX-%s, bar()=%d expected=%d\n", suffix,
           barValue, expectedBar);
  else
    printf("[PASS]  env-DYLD_IMAGE_SUFFIX-%s\n", suffix);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1185 <main+0x35>
lea    0xef6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0x2a,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0x2a,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <foo@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <bar@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1222 <main+0xd2>
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1262 <main+0x112>
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     124b <main+0xfb>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125d <main+0x10d>
mov    -0x10(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1262 <main+0x112>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xf0a(%rip),%rbx
cmovne %rax,%rbx
lea    0xe9a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
mov    $0x1,%r15d
mov    $0x2a,%r14d
mov    $0x2a,%ebp
cmove  %r15d,%ebp
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
cmove  %r15d,%r14d
xor    %eax,%eax
call   1060 <foo@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <bar@plt>
cmp    %ebp,%r15d
jne    11ed <main+0x9d>
cmp    %r14d,%eax
jne    11fe <main+0xae>
lea    0xecf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1214 <main+0xc4>
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
jmp    120d <main+0xbd>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"DYLD_IMAGE_SUFFIX\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [34 x i8] c"[BEGIN] env-DYLD_IMAGE_SUFFIX-%s\0A\00"
@.str.3 = [7 x i8] c"_other\00"
@.str.4 = [5 x i8] c"_alt\00"
@.str.5 = [56 x i8] c"[FAIL] env-DYLD_IMAGE_SUFFIX-%s, foo()=%d expected=%d\0A\00"
@.str.6 = [56 x i8] c"[FAIL] env-DYLD_IMAGE_SUFFIX-%s, bar()=%d expected=%d\0A\00"
@.str.7 = [34 x i8] c"[PASS] env-DYLD_IMAGE_SUFFIX-%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %10, %0
%12 = load i8*, i8** %2
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32* @strstr(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp ne i32* %15, null
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 42, i32 1
store i32 %18, i32* %3
%19 = load i8*, i8** %2
%20 = call i32* @strstr(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp ne i32* %20, null
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 42, i32 1
store i32 %23, i32* %4
%24 = call i32 (...) @foo()
store i32 %24, i32* %5
%25 = call i32 (...) @bar()
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %11
%30 = load i8*, i8** %2
%31 = load i32, i32* %5
%32 = load i32, i32* %3
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %30, i32 %31, i32 %32)
br label %47
34: ; preds = %11
%35 = load i32, i32* %6
%36 = load i32, i32* %4
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %2
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* %39, i32 %40, i32 %41)
br label %46
43: ; preds = %34
%44 = load i8*, i8** %2
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %38
br label %47
47: ; preds = %46, %29
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"DYLD_IMAGE_SUFFIX\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [34 x i8] c"[BEGIN] env-DYLD_IMAGE_SUFFIX-%s\0A\00"
@.str.3 = [7 x i8] c"_other\00"
@.str.4 = [5 x i8] c"_alt\00"
@.str.5 = [56 x i8] c"[FAIL] env-DYLD_IMAGE_SUFFIX-%s, foo()=%d expected=%d\0A\00"
@.str.6 = [56 x i8] c"[FAIL] env-DYLD_IMAGE_SUFFIX-%s, bar()=%d expected=%d\0A\00"
@.str.7 = [34 x i8] c"[PASS] env-DYLD_IMAGE_SUFFIX-%s\0A\00"
define i32 @main() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
%3 = select i1 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %1
%4 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%5 = tail call i32* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%6 = icmp eq i32* %5, null
%7 = select i1 %6, i32 1, i32 42
%8 = tail call i32* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
%10 = select i1 %9, i32 1, i32 42
%11 = tail call i32 (...) @foo()
%12 = tail call i32 (...) @bar()
%13 = icmp eq i32 %11, %7
br i1 %13, label %16, label %14
14: ; preds = %0
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i8* %3, i32 %11, i32 %7)
br label %22
16: ; preds = %0
%17 = icmp eq i32 %12, %10
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i8* %3, i32 %12, i32 %10)
br label %22
20: ; preds = %16
%21 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %3)
br label %22
22: ; preds = %18, %20, %14
ret i32 0
}