#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 *, ...);
void print_envs() {
  extern char **environ;
  printf("base %p\n", environ);
  for (int i = 0; environ && environ[i] != 0; ++i) {
    printf("env[%d] = [%p]%s\n", i, environ[i], environ[i]);
  }
}


x86 assembly (clang, -O0):
<print_envs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%rsi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    0x2ea8(%rip),%rcx
cmpq   $0x0,(%rcx)
mov    %al,-0x5(%rbp)
je     1166 <print_envs+0x56>
mov    0x2e94(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    1176 <print_envs+0x66>
jmp    11b9 <print_envs+0xa9>
mov    -0x4(%rbp),%esi
mov    0x2e68(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1137 <print_envs+0x27>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_envs>:
push   %r15
push   %r14
push   %rbx
mov    0x2ecc(%rip),%r15
mov    (%r15),%rsi
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%rax
test   %rax,%rax
je     1164 <print_envs+0x54>
lea    0xecd(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
mov    (%rax,%rbx,8),%rcx
test   %rcx,%rcx
je     1164 <print_envs+0x54>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
mov    (%r15),%rax
test   %rax,%rax
jne    1140 <print_envs+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"base %p\0A\00"
@environ = external global i8**
@.str.1 = [18 x i8] c"env[%d] = [%p]%s\0A\00"
define void @print_envs() {
%1 = alloca i32
%2 = load i8**, i8*** @environ
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2)
store i32 0, i32* %1
br label %4
4: ; preds = %29, %0
%5 = load i8**, i8*** @environ
%6 = icmp ne i8** %5, null
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i8**, i8*** @environ
%9 = load i32, i32* %1
%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 label %14
14: ; preds = %7, %4
%15 = phi i1 [ false, %4 ], [ %13, %7 ]
br i1 %15, label %16, label %32
16: ; preds = %14
%17 = load i32, i32* %1
%18 = load i8**, i8*** @environ
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = load i8**, i8*** @environ
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %17, i8* %22, i8* %27)
br label %29
29: ; preds = %16
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
br label %4
32: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"base %p\0A\00"
@environ = external global i8**
@.str.1 = [18 x i8] c"env[%d] = [%p]%s\0A\00"
define void @print_envs() {
%1 = load i8**, i8*** @environ
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %1)
%3 = load i8**, i8*** @environ
%4 = icmp eq i8** %3, null
br i1 %4, label %11, label %5
5: ; preds = %0, %12
%6 = phi i64 [ %15, %12 ], [ 0, %0 ]
%7 = phi i8** [ %16, %12 ], [ %3, %0 ]
%8 = getelementptr inbounds i8*, i8** %7, i64 %6
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %5, %12, %0
ret void
12: ; preds = %5
%13 = trunc i64 %6 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %9, i8* %9)
%15 = add nuw i64 %6, 1
%16 = load i8**, i8*** @environ
%17 = icmp eq i8** %16, null
br i1 %17, label %11, label %5
}