#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 EXIT_FAILURE;
int EXIT_SUCCESS;
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  extern char **environ;
  char *env_value;
  int i = 0;
  if (argc == 1) {
    while (environ[i] != NULL) {
      printf("%s\n", environ[i]);
      i++;
    }
    return EXIT_SUCCESS;
  } else if (argc == 2) {
    env_value = getenv(argv[1]);
    if (env_value == NULL) {
      printf("variable %s inexistante\n", argv[1]);
      return EXIT_FAILURE;
    }
    printf("%s\n", env_value);
    return EXIT_SUCCESS;
  } else {
    printf("Bad usage : %s [environment_value]\n", argv[0]);
    return EXIT_FAILURE;
  }
}


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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a2 <main+0x82>
jmp    114c <main+0x2c>
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1191 <main+0x71>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <main+0x2c>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122d <main+0x10d>
cmpl   $0x2,-0x8(%rbp)
jne    120e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122d <main+0x10d>
mov    -0x18(%rbp),%rsi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    122d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
je     117a <main+0x5a>
cmp    $0x1,%edi
jne    11a3 <main+0x83>
mov    0x2eaf(%rip),%r15
mov    (%r15),%rax
mov    (%rax),%rsi
mov    0x2e8a(%rip),%r14
test   %rsi,%rsi
je     11c5 <main+0xa5>
mov    $0x8,%ebx
lea    0xea9(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <printf@plt>
mov    (%r15),%rax
mov    (%rax,%rbx,1),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1160 <main+0x40>
jmp    11c5 <main+0xa5>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11af <main+0x8f>
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2e2f(%rip),%r14
jmp    11c5 <main+0xa5>
mov    (%rsi),%rsi
lea    0xe70(%rip),%rdi
jmp    11b9 <main+0x99>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e13(%rip),%r14
mov    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@environ = external global i8**
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [25 x i8] c"variable %s inexistante\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [36 x i8] c"Bad usage : %s [environment_value]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %29
10: ; preds = %2
br label %11
11: ; preds = %18, %10
%12 = load i8**, i8*** @environ
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %11
%19 = load i8**, i8*** @environ
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %11
27: ; preds = %11
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %3
br label %55
29: ; preds = %2
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 2
br i1 %31, label %32, label %49
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i8* @getenv(i8* %35)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %45
39: ; preds = %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %55
45: ; preds = %32
%46 = load i8*, i8** %6
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_SUCCESS
store i32 %48, i32* %3
br label %55
49: ; preds = %29
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %3
br label %55
55: ; preds = %49, %45, %39, %27
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@environ = external global i8**
@.str = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [25 x i8] c"variable %s inexistante\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [36 x i8] c"Bad usage : %s [environment_value]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %25 [
i32 1, label %3
i32 2, label %16
]
3: ; preds = %2
%4 = load i8**, i8*** @environ
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %28, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %11, %7 ], [ 0, %3 ]
%9 = phi i8* [ %14, %7 ], [ %5, %3 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = add nuw i64 %8, 1
%12 = load i8**, i8*** @environ
%13 = getelementptr inbounds i8*, i8** %12, i64 %11
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %28, label %7
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i8* @getenv(i8* %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %28
23: ; preds = %16
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %28
25: ; preds = %2
%26 = load i8*, i8** %1
%27 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %7, %3, %25, %23, %21
%29 = phi i32* [ @EXIT_FAILURE, %21 ], [ @EXIT_SUCCESS, %23 ], [ @EXIT_FAILURE, %25 ], [ @EXIT_SUCCESS, %3 ], [ @EXIT_SUCCESS, %7 ]
%30 = load i32, i32* %29
ret i32 %30
}