#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[], char *envp[]) {
  char buf[256];
  FILE *fp;
  if (envp && *envp) {
    sprintf(buf, "/tmp/%s", *envp);
    if (fp = fopen(buf, "r")) {
      while (fgets(buf, sizeof buf, fp)) {
        fputs(buf, stdout);
      }
    }
  } else
    fputs("No environment\n", stdout);
  do {
    fprintf(stdout, "\"%s\" 0x%08lx\n", *envp, *envp);
  } while (*++envp);
  sleep(5);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121f <main+0xbf>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     121f <main+0xbf>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
je     121a <main+0xba>
jmp    11d9 <main+0x79>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1215 <main+0xb5>
lea    -0x120(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    11d9 <main+0x79>
jmp    121a <main+0xba>
jmp    1234 <main+0xd4>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    0xddb(%rip),%rdi
call   1030 <fputs@plt>
jmp    1239 <main+0xd9>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xdc3(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
cmpq   $0x0,0x8(%rax)
jne    1239 <main+0xd9>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%rbx
test   %rdx,%rdx
je     11f3 <main+0x93>
mov    (%rbx),%rdx
test   %rdx,%rdx
je     11f3 <main+0x93>
lea    0xe7b(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1070 <sprintf@plt>
lea    0xe71(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1208 <main+0xa8>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1208 <main+0xa8>
mov    0x2e1d(%rip),%r12
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    %r15,%rdi
call   1030 <fputs@plt>
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11d0 <main+0x70>
jmp    1208 <main+0xa8>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
call   1030 <fputs@plt>
mov    (%rbx),%rcx
add    $0x8,%rbx
mov    0x2dca(%rip),%r15
lea    0xdfd(%rip),%r14
nopl   (%rax)
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rcx,%rdx
call   1050 <fprintf@plt>
mov    (%rbx),%rcx
add    $0x8,%rbx
test   %rcx,%rcx
jne    1220 <main+0xc0>
mov    $0x5,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/tmp/%s\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [16 x i8] c"No environment\0A\00"
@.str.3 = [14 x i8] c"\22%s\22 0x%08lx\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [256 x i8]
%9 = alloca i32*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i8**, i8*** %7
%11 = icmp ne i8** %10, null
br i1 %11, label %12, label %36
12: ; preds = %3
%13 = load i8**, i8*** %7
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%18 = load i8**, i8*** %7
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %35
24: ; preds = %16
br label %25
25: ; preds = %30, %24
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%27 = load i32*, i32** %9
%28 = call i64 @fgets(i8* %26, i32 256, i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* @stdout
%33 = call i32 @fputs(i8* %31, i32 %32)
br label %25
34: ; preds = %25
br label %35
35: ; preds = %34, %16
br label %39
36: ; preds = %12, %3
%37 = load i32, i32* @stdout
%38 = call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %35
br label %40
40: ; preds = %47, %39
%41 = load i32, i32* @stdout
%42 = load i8**, i8*** %7
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %7
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %43, i8* %45)
br label %47
47: ; preds = %40
%48 = load i8**, i8*** %7
%49 = getelementptr inbounds i8*, i8** %48, i32 1
store i8** %49, i8*** %7
%50 = load i8*, i8** %49
%51 = icmp ne i8* %50, null
br i1 %51, label %40, label %52
52: ; preds = %47
%53 = call i32 @sleep(i32 5)
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [8 x i8] c"/tmp/%s\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [16 x i8] c"No environment\0A\00"
@.str.3 = [14 x i8] c"\22%s\22 0x%08lx\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8** %2, null
br i1 %6, label %22, label %7
7: ; preds = %3
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %22, label %10
10: ; preds = %7
%11 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %8)
%12 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %25, label %14
14: ; preds = %10
%15 = call i64 @fgets(i8* %5, i32 256, i32* %12)
%16 = icmp eq i64 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %14, %17
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* %5, i32 %18)
%20 = call i64 @fgets(i8* %5, i32 256, i32* %12)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %17
22: ; preds = %7, %3
%23 = load i32, i32* @stdout
%24 = tail call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %17, %14, %10, %22
%26 = load i8*, i8** %2
br label %27
27: ; preds = %27, %25
%28 = phi i8* [ %26, %25 ], [ %33, %27 ]
%29 = phi i8** [ %2, %25 ], [ %32, %27 ]
%30 = load i32, i32* @stdout
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %28)
%32 = getelementptr inbounds i8*, i8** %29, i64 1
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %27
35: ; preds = %27
%36 = call i32 @sleep(i32 5)
ret i32 0
}