#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 /*<<< orphan*/ printf(char *, int, char *);
int main(int argc, char *argv[]) {
  extern char **environ;
  int i;
  for (i = 0; environ[i] != NULL; i++)
    printf("environ[%d] = %s\n", i, environ[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)
movl   $0x0,-0x14(%rbp)
mov    0x2eb4(%rip),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1175 <main+0x65>
mov    -0x14(%rbp),%esi
mov    0x2e98(%rip),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2ecc(%rip),%r15
mov    (%r15),%rax
mov    (%rax),%rdx
test   %rdx,%rdx
je     114b <main+0x3b>
xor    %ebx,%ebx
lea    0xed0(%rip),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    (%r15),%rax
mov    0x8(%rax,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1130 <main+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@environ = external global i8**
@.str = [18 x i8] c"environ[%d] = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i8**, i8*** @environ
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %11, %6 ], [ 0, %2 ]
%8 = phi i8* [ %14, %6 ], [ %4, %2 ]
%9 = trunc i64 %7 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %8)
%11 = add nuw i64 %7, 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 %16, label %6
16: ; preds = %6, %2
ret i32 0
}