#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 strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  extern char **environ;
  unsigned int i = 0;
  while (environ[i]) {
    write(1, environ[i], strlen(environ[i]));
    write(1, "\n", 1);
    ++i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     11aa <main+0x8a>
mov    0x2e93(%rip),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edx
lea    0xe6b(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eba(%rip),%r15
mov    (%r15),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
je     118a <main+0x6a>
mov    $0x1,%ebp
lea    0xebb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    (%r15),%rax
mov    %ebp,%ecx
mov    (%rax,%rcx,8),%rbx
add    $0x1,%ebp
test   %rbx,%rbx
jne    1150 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@environ = external global i8**
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %10, %0
%4 = load i8**, i8*** @environ
%5 = load i32, i32* %2
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8*, i8** %4, i64 %6
%8 = load i8*, i8** %7
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %26
10: ; preds = %3
%11 = load i8**, i8*** @environ
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = load i8**, i8*** @environ
%17 = load i32, i32* %2
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 1, i8* %15, i32 %21)
%23 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%24 = load i32, i32* %2
%25 = add i32 %24, 1
store i32 %25, i32* %2
br label %3
26: ; preds = %3
ret i32 0
}

LLVM IR (-O2):
@environ = external global i8**
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = load i8**, i8*** @environ
%2 = load i8*, i8** %1
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %0, %4
%5 = phi i8* [ %14, %4 ], [ %2, %0 ]
%6 = phi i32 [ %10, %4 ], [ 0, %0 ]
%7 = tail call i32 @strlen(i8* %5)
%8 = tail call i32 @write(i32 1, i8* %5, i32 %7)
%9 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = add i32 %6, 1
%11 = load i8**, i8*** @environ
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i8*, i8** %11, i64 %12
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %4
16: ; preds = %4, %0
ret i32 0
}