#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 */
scalar_t__ close(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv, char **envp) {
  int i;
  printf("argc: %d\n", argc);
  for (i = 0; i < argc; i++)
    printf("str: %s\n", argv[i]);
  printf("envp: %p\n", envp);
  while (*envp) {
    printf("ENV: %s\n", *envp);
    envp++;
  }
  for (i = 3; i < 32; i++)
    if (close(i) == 0)
      printf("FD %d valid\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1186 <main+0x66>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1152 <main+0x32>
mov    -0x18(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11cc <main+0xac>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    1198 <main+0x78>
movl   $0x3,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    1213 <main+0xf3>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jne    1200 <main+0xe0>
mov    -0x1c(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <main+0xe5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d3 <main+0xb3>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xec9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
jle    1167 <main+0x47>
mov    %ebp,%r12d
lea    0xebc(%rip),%r15
xor    %ebp,%ebp
mov    (%r14,%rbp,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1150 <main+0x30>
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     11a6 <main+0x86>
add    $0x8,%rbx
lea    0xe92(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1190 <main+0x70>
mov    $0x3,%ebx
lea    0xe74(%rip),%r14
jmp    11c8 <main+0xa8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
cmp    $0x20,%ebx
je     11e2 <main+0xc2>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
jne    11c0 <main+0xa0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11c0 <main+0xa0>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"argc: %d\0A\00"
@.str.1 = [9 x i8] c"str: %s\0A\00"
@.str.2 = [10 x i8] c"envp: %p\0A\00"
@.str.3 = [9 x i8] c"ENV: %s\0A\00"
@.str.4 = [13 x i8] c"FD %d valid\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 i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = load i32, i32* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %8
br label %11
11: ; preds = %22, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i8**, i8*** %6
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
br label %11
25: ; preds = %11
%26 = load i8**, i8*** %7
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %26)
br label %28
28: ; preds = %32, %25
%29 = load i8**, i8*** %7
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i8**, i8*** %7
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i8**, i8*** %7
%37 = getelementptr inbounds i8*, i8** %36, i32 1
store i8** %37, i8*** %7
br label %28
38: ; preds = %28
store i32 3, i32* %8
br label %39
39: ; preds = %50, %38
%40 = load i32, i32* %8
%41 = icmp slt i32 %40, 32
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i32, i32* %8
%44 = call i64 @close(i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* %8
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %42
br label %50
50: ; preds = %49
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %39
53: ; preds = %39
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"argc: %d\0A\00"
@.str.1 = [9 x i8] c"str: %s\0A\00"
@.str.2 = [10 x i8] c"envp: %p\0A\00"
@.str.3 = [9 x i8] c"ENV: %s\0A\00"
@.str.4 = [13 x i8] c"FD %d valid\0A\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %3
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %2)
%17 = load i8*, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %15, %19
%20 = phi i8* [ %24, %19 ], [ %17, %15 ]
%21 = phi i8** [ %23, %19 ], [ %2, %15 ]
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%23 = getelementptr inbounds i8*, i8** %21, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %19
26: ; preds = %19, %15
br label %27
27: ; preds = %26, %33
%28 = phi i32 [ %34, %33 ], [ 3, %26 ]
%29 = tail call i64 @close(i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %33
33: ; preds = %27, %31
%34 = add nuw nsw i32 %28, 1
%35 = icmp eq i32 %34, 32
br i1 %35, label %36, label %27
36: ; preds = %33
ret i32 0
}