#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 **__environ;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char **argv) {
  int i = 0;
  char **index = __environ;
  printf("argc=%d\n", argc);
  for (i = 0; i < argc; i++) {
    printf("argv[%d]='%s'\n", i, argv[i]);
  }
  i = 0;
  while (*index) {
    printf("environ[%d]='%s'\n", i++, *index++);
  }
  exit(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
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119a <main+0x7a>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <main+0x43>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11df <main+0xbf>
mov    -0x14(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%rdx
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a1 <main+0x81>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2ec3(%rip),%rax
mov    (%rax),%r12
lea    0xec1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1179 <main+0x59>
mov    %ebx,%r13d
lea    0xeb3(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <main+0x40>
mov    (%r12),%rdx
test   %rdx,%rdx
je     11aa <main+0x8a>
lea    0xe8f(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%r12,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1190 <main+0x70>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@__environ = global i8** null
@.str = [9 x i8] c"argc=%d\0A\00"
@.str.1 = [15 x i8] c"argv[%d]='%s'\0A\00"
@.str.2 = [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
%7 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i8**, i8*** @__environ
store i8** %8, i8*** %7
%9 = load i32, i32* %4
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %6
br label %11
11: ; preds = %23, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32, i32* %6
%17 = load i8**, i8*** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
store i32 0, i32* %6
br label %27
27: ; preds = %31, %26
%28 = load i8**, i8*** %7
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
%34 = load i8**, i8*** %7
%35 = getelementptr inbounds i8*, i8** %34, i32 1
store i8** %35, i8*** %7
%36 = load i8*, i8** %34
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %32, i8* %36)
br label %27
38: ; preds = %27
%39 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__environ = global i8** null
@.str = [9 x i8] c"argc=%d\0A\00"
@.str.1 = [15 x i8] c"argv[%d]='%s'\0A\00"
@.str.2 = [18 x i8] c"environ[%d]='%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8**, i8*** @__environ
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %11
8: ; preds = %11, %2
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %28, label %19
11: ; preds = %6, %11
%12 = phi i64 [ 0, %6 ], [ %17, %11 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = trunc i64 %12 to i32
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %14)
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %8, label %11
19: ; preds = %8, %19
%20 = phi i8* [ %26, %19 ], [ %9, %8 ]
%21 = phi i8** [ %24, %19 ], [ %3, %8 ]
%22 = phi i32 [ %23, %19 ], [ 0, %8 ]
%23 = add nuw nsw i32 %22, 1
%24 = getelementptr inbounds i8*, i8** %21, i64 1
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %20)
%26 = load i8*, i8** %24
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %19
28: ; preds = %19, %8
%29 = tail call i32 @exit(i32 0)
unreachable
}