#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  char *a_val;
};
struct TYPE_4__ {
  int a_type;
  TYPE_1__ a_un;
};
typedef TYPE_2__ Elf64_auxv_t;

/* Variables and functions */
int AT_NULL;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  long *p = (long *)argv;
  int i;
  Elf64_auxv_t *aux;
  printf("Argument count: %ld\n", *(p - 1));
  for (i = 1; i < *(p - 1); ++i) {
    printf("Argument %d : %s\n", i, (char *)*(p + i));
  }
  p += i;
  p++;
  printf("Environment:\n");
  while (*p) {
    printf("%s\n", (char *)*p++);
  }
  p++;
  printf("Auxiliary Vectors:\n");
  aux = (Elf64_auxv_t *)p;
  while (aux->a_type != AT_NULL) {
    printf("Type: %02ld Value: %16lx\n", aux->a_type, aux->a_un.a_val);
    aux++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rax),%rsi
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    -0x8(%rcx),%rax
jge    1188 <main+0x78>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <main+0x3b>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ea <main+0xda>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b7 <main+0xa7>
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%eax
je     124e <main+0x13e>
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
jmp    120c <main+0xfc>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    -0x8(%rsi),%rsi
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r15d
cmpq   $0x2,-0x8(%r14)
jl     117d <main+0x5d>
mov    $0x1,%ebx
lea    0xebf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,-0x8(%r14)
jg     1160 <main+0x40>
mov    %ebx,%r15d
lea    (%r14,%r15,8),%r12
add    $0x8,%r12
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14,%r15,8),%rdi
test   %rdi,%rdi
je     11b5 <main+0x95>
mov    %r12,%rbx
xchg   %ax,%ax
lea    0x8(%rbx),%r12
call   1030 <puts@plt>
mov    0x8(%rbx),%rdi
mov    %r12,%rbx
test   %rdi,%rdi
jne    11a0 <main+0x80>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r12),%esi
mov    0x2e0b(%rip),%r15
cmp    (%r15),%esi
je     11fc <main+0xdc>
add    $0x18,%r12
lea    0xe4a(%rip),%r14
nopl   (%rax)
mov    -0x8(%r12),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%esi
add    $0x10,%r12
cmp    (%r15),%esi
jne    11e0 <main+0xc0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i8* }
@.str = [21 x i8] c"Argument count: %ld\0A\00"
@.str.1 = [18 x i8] c"Argument %d : %s\0A\00"
@.str.2 = [14 x i8] c"Environment:\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [20 x i8] c"Auxiliary Vectors:\0A\00"
@AT_NULL = global i32 0
@.str.5 = [26 x i8] c"Type: %02ld Value: %16lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32
%8 = alloca %struct.TYPE_4__*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = bitcast i8** %9 to i64*
store i64* %10, i64** %6
%11 = load i64*, i64** %6
%12 = getelementptr inbounds i64, i64* %11, i64 -1
%13 = load i64, i64* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %13)
store i32 1, i32* %7
br label %15
15: ; preds = %31, %2
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = load i64*, i64** %6
%19 = getelementptr inbounds i64, i64* %18, i64 -1
%20 = load i64, i64* %19
%21 = icmp slt i64 %17, %20
br i1 %21, label %22, label %34
22: ; preds = %15
%23 = load i32, i32* %7
%24 = load i64*, i64** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i64, i64* %24, i64 %26
%28 = load i64, i64* %27
%29 = inttoptr i64 %28 to i8*
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %29)
br label %31
31: ; preds = %22
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %15
34: ; preds = %15
%35 = load i32, i32* %7
%36 = load i64*, i64** %6
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i64, i64* %36, i64 %37
store i64* %38, i64** %6
%39 = load i64*, i64** %6
%40 = getelementptr inbounds i64, i64* %39, i32 1
store i64* %40, i64** %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %46, %34
%43 = load i64*, i64** %6
%44 = load i64, i64* %43
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i64*, i64** %6
%48 = getelementptr inbounds i64, i64* %47, i32 1
store i64* %48, i64** %6
%49 = load i64, i64* %47
%50 = inttoptr i64 %49 to i8*
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %50)
br label %42
52: ; preds = %42
%53 = load i64*, i64** %6
%54 = getelementptr inbounds i64, i64* %53, i32 1
store i64* %54, i64** %6
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%56 = load i64*, i64** %6
%57 = bitcast i64* %56 to %struct.TYPE_4__*
store %struct.TYPE_4__* %57, %struct.TYPE_4__** %8
br label %58
58: ; preds = %64, %52
%59 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%60 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %59, i32 0, i32 0
%61 = load i32, i32* %60
%62 = load i32, i32* @AT_NULL
%63 = icmp ne i32 %61, %62
br i1 %63, label %64, label %75
64: ; preds = %58
%65 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%66 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%69 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %68, i32 0, i32 1
%70 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %69, i32 0, i32 0
%71 = load i8*, i8** %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %67, i8* %71)
%73 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%74 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %73, i32 1
store %struct.TYPE_4__* %74, %struct.TYPE_4__** %8
br label %58
75: ; preds = %58
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i8* }
@.str = [21 x i8] c"Argument count: %ld\0A\00"
@.str.1 = [18 x i8] c"Argument %d : %s\0A\00"
@AT_NULL = global i32 0
@.str.5 = [26 x i8] c"Type: %02ld Value: %16lx\0A\00"
@str = [13 x i8] c"Environment:\00"
@str.6 = [19 x i8] c"Auxiliary Vectors:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 -1
%4 = bitcast i8** %3 to i64*
%5 = load i64, i64* %4
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = load i64, i64* %4
%8 = icmp sgt i64 %7, 1
br i1 %8, label %9, label %22
9: ; preds = %2, %9
%10 = phi i64 [ %17, %9 ], [ 1, %2 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = bitcast i8** %11 to i64*
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
%15 = trunc i64 %10 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %14)
%17 = add nuw nsw i64 %10, 1
%18 = load i64, i64* %4
%19 = icmp sgt i64 %18, %17
br i1 %19, label %9, label %20
20: ; preds = %9
%21 = and i64 %17, 4294967295
br label %22
22: ; preds = %20, %2
%23 = phi i64 [ 1, %2 ], [ %21, %20 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = bitcast i8** %25 to i64*
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%28 = load i64, i64* %26
%29 = icmp eq i64 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %22, %30
%31 = phi i64 [ %36, %30 ], [ %28, %22 ]
%32 = phi i64* [ %33, %30 ], [ %26, %22 ]
%33 = getelementptr inbounds i64, i64* %32, i64 1
%34 = inttoptr i64 %31 to i8*
%35 = tail call i32 @puts(i8* %34)
%36 = load i64, i64* %33
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %30
38: ; preds = %30, %22
%39 = phi i64* [ %26, %22 ], [ %33, %30 ]
%40 = getelementptr inbounds i64, i64* %39, i64 1
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%42 = bitcast i64* %40 to i32*
%43 = load i32, i32* %42
%44 = load i32, i32* @AT_NULL
%45 = icmp eq i32 %43, %44
br i1 %45, label %59, label %46
46: ; preds = %38
%47 = bitcast i64* %40 to %struct.TYPE_4__*
br label %48
48: ; preds = %46, %48
%49 = phi i32 [ %56, %48 ], [ %43, %46 ]
%50 = phi %struct.TYPE_4__* [ %54, %48 ], [ %47, %46 ]
%51 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %50, i64 0, i32 1, i32 0
%52 = load i8*, i8** %51
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %49, i8* %52)
%54 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %50, i64 1
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i64 0, i32 0
%56 = load i32, i32* %55
%57 = load i32, i32* @AT_NULL
%58 = icmp eq i32 %56, %57
br i1 %58, label %59, label %48
59: ; preds = %48, %38
ret i32 0
}