#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*/ O_RDONLY;
scalar_t__ getenv(char *);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main() {
  if (getenv("LD_PRELOAD"))
    printf("LD_PRELOAD detected through getenv()\n");
  else
    printf("Environment is clean\n");
  if (open("/etc/ld.so.preload", O_RDONLY) > 0)
    printf("/etc/ld.so.preload detected through open()\n");
  else
    printf("/etc/ld.so.preload is not present\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>
cmp    $0x0,%rax
je     1166 <main+0x36>
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
jmp    1172 <main+0x42>
lea    0xec4(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xec5(%rip),%rdi
call   1050 <open@plt>
cmp    $0x0,%rax
jle    11a2 <main+0x72>
lea    0xec2(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <main+0x7e>
lea    0xedd(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xed7(%rip),%rax
lea    0xf32(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1050 <open@plt>
test   %rax,%rax
lea    0xedf(%rip),%rax
lea    0xeb6(%rip),%rdi
cmovg  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [38 x i8] c"LD_PRELOAD detected through getenv()\0A\00"
@.str.2 = [22 x i8] c"Environment is clean\0A\00"
@.str.3 = [19 x i8] c"/etc/ld.so.preload\00"
@O_RDONLY = global i32 0
@.str.4 = [44 x i8] c"/etc/ld.so.preload detected through open()\0A\00"
@.str.5 = [35 x i8] c"/etc/ld.so.preload is not present\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = load i32, i32* @O_RDONLY
%10 = call i64 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %16
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.3 = [19 x i8] c"/etc/ld.so.preload\00"
@O_RDONLY = global i32 0
@str = [21 x i8] c"Environment is clean\00"
@str.6 = [34 x i8] c"/etc/ld.so.preload is not present\00"
@str.7 = [43 x i8] c"/etc/ld.so.preload detected through open()\00"
@str.8 = [37 x i8] c"LD_PRELOAD detected through getenv()\00"
define i32 @main() {
%1 = tail call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0)
%4 = tail call i32 @puts(i8* dereferenceable(1) %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i64 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %5)
%7 = icmp sgt i64 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0)
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
ret i32 0
}