#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 */
char *getenv(char const *);
int /*<<< orphan*/ printf(char *, ...);
size_t strcspn(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t const);
int main(int argc, char **argv, char **environ) {
  if (argc == 1) {
    char **env;
    for (env = environ; *env != 0; env++) {
      const size_t len = strcspn(*env, "=");
      char name[len + 1];
      strncpy(name, *env, len);
      name[len] = 0;
      const char *c = getenv(name);
      printf("getenv(\"%s\") -> ", name);
      if (!c) {
        printf("<null>\n");
      } else {
        printf("%s\n", c);
      }
    }
  } else {
    for (int i = 1; i < argc; ++i) {
      const char *name = argv[i];
      const char *c = getenv(name);
      if (!c)
        return 1;
      printf("%s\n", c);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1240 <main+0x100>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     123b <main+0xfb>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe78(%rip),%rsi
call   1060 <strcspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x60(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   1030 <getenv@plt>
mov    -0x60(%rbp),%rsi
mov    %rax,-0x40(%rbp)
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1211 <main+0xd1>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1223 <main+0xe3>
mov    -0x40(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    116c <main+0x2c>
jmp    12ac <main+0x16c>
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a7 <main+0x167>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1287 <main+0x147>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x173>
mov    -0x58(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1247 <main+0x107>
jmp    12ac <main+0x16c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    11fe <main+0xae>
mov    %rdx,%r12
mov    (%rdx),%rdi
test   %rdi,%rdi
je     1241 <main+0xf1>
add    $0x8,%r12
jmp    119c <main+0x4c>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %r15,%rsp
mov    (%r12),%rdi
add    $0x8,%r12
test   %rdi,%rdi
je     1241 <main+0xf1>
lea    0xe5d(%rip),%rsi
call   1070 <strcspn@plt>
mov    %rax,%rbx
mov    %rsp,%r15
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x8(%r12),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
movb   $0x0,(%rbx,%r14,1)
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %rax,%r13
lea    0xe1c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r13,%r13
jne    1180 <main+0x30>
lea    0xe17(%rip),%rdi
jmp    1183 <main+0x33>
xor    %r15d,%r15d
cmp    $0x2,%edi
jl     124c <main+0xfc>
mov    %rsi,%r14
mov    %edi,%r12d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1246 <main+0xf6>
mov    %rax,%rdi
call   1050 <puts@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1220 <main+0xd0>
jmp    124c <main+0xfc>
xor    %r15d,%r15d
jmp    124c <main+0xfc>
mov    $0x1,%r15d
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
@.str.1 = [17 x i8] c"getenv(\22%s\22) -> \00"
@.str.2 = [8 x i8] c"<null>\0A\00"
@.str.3 = [4 x i8] c"%s\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 i8**
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %53
18: ; preds = %3
%19 = load i8**, i8*** %7
store i8** %19, i8*** %8
br label %20
20: ; preds = %49, %18
%21 = load i8**, i8*** %8
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %52
24: ; preds = %20
%25 = load i8**, i8*** %8
%26 = load i8*, i8** %25
%27 = call i64 @strcspn(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = add i64 %28, 1
%30 = call i8* @llvm.stacksave()
store i8* %30, i8** %10
%31 = alloca i8, i64 %29
store i64 %29, i64* %11
%32 = load i8**, i8*** %8
%33 = load i8*, i8** %32
%34 = load i64, i64* %9
%35 = call i32 @strncpy(i8* %31, i8* %33, i64 %34)
%36 = load i64, i64* %9
%37 = getelementptr inbounds i8, i8* %31, i64 %36
store i8 0, i8* %37
%38 = call i8* @getenv(i8* %31)
store i8* %38, i8** %12
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%40 = load i8*, i8** %12
%41 = icmp ne i8* %40, null
br i1 %41, label %44, label %42
42: ; preds = %24
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %47
44: ; preds = %24
%45 = load i8*, i8** %12
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %42
%48 = load i8*, i8** %10
br label %49
49: ; preds = %47
%50 = load i8**, i8*** %8
%51 = getelementptr inbounds i8*, i8** %50, i32 1
store i8** %51, i8*** %8
br label %20
52: ; preds = %20
br label %76
53: ; preds = %3
store i32 1, i32* %13
br label %54
54: ; preds = %72, %53
%55 = load i32, i32* %13
%56 = load i32, i32* %5
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %75
58: ; preds = %54
%59 = load i8**, i8*** %6
%60 = load i32, i32* %13
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
store i8* %63, i8** %14
%64 = load i8*, i8** %14
%65 = call i8* @getenv(i8* %64)
store i8* %65, i8** %15
%66 = load i8*, i8** %15
%67 = icmp ne i8* %66, null
br i1 %67, label %69, label %68
68: ; preds = %58
store i32 1, i32* %4
br label %77
69: ; preds = %58
%70 = load i8*, i8** %15
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %13
%74 = add nsw i32 %73, 1
store i32 %74, i32* %13
br label %54
75: ; preds = %54
br label %76
76: ; preds = %75, %52
store i32 0, i32* %4
br label %77
77: ; preds = %76, %68
%78 = load i32, i32* %4
ret i32 %78
}

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
@.str.1 = [17 x i8] c"getenv(\22%s\22) -> \00"
@str = [7 x i8] c"<null>\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture %2) {
%4 = icmp eq i32 %0, 1
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %43
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %33
9: ; preds = %3
%10 = load i8*, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %43, label %12
12: ; preds = %9, %29
%13 = phi i8* [ %31, %29 ], [ %10, %9 ]
%14 = phi i8** [ %30, %29 ], [ %2, %9 ]
%15 = call i64 @strcspn(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = add i64 %15, 1
%17 = call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = load i8*, i8** %14
%20 = call i32 @strncpy(i8* %18, i8* %19, i64 %15)
%21 = getelementptr inbounds i8, i8* %18, i64 %15
store i8 0, i8* %21
%22 = call i8* @getenv(i8* %18)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%24 = icmp eq i8* %22, null
br i1 %24, label %25, label %27
25: ; preds = %12
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %29
27: ; preds = %12
%28 = call i32 @puts(i8* %22)
br label %29
29: ; preds = %27, %25
%30 = getelementptr inbounds i8*, i8** %14, i64 1
%31 = load i8*, i8** %30
%32 = icmp eq i8* %31, null
br i1 %32, label %43, label %12
33: ; preds = %7, %39
%34 = phi i64 [ 1, %7 ], [ %41, %39 ]
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i8* @getenv(i8* %36)
%38 = icmp eq i8* %37, null
br i1 %38, label %43, label %39
39: ; preds = %33
%40 = tail call i32 @puts(i8* %37)
%41 = add nuw nsw i64 %34, 1
%42 = icmp eq i64 %41, %8
br i1 %42, label %43, label %33
43: ; preds = %39, %33, %29, %5, %9
%44 = phi i32 [ 0, %9 ], [ 0, %5 ], [ 0, %29 ], [ 0, %39 ], [ 1, %33 ]
ret i32 %44
}