#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 **getenv(char *);
int /*<<< orphan*/ printf(char *, char **);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char buffer[512];
  printf("Address of Buffer: %p\n", &buffer);
  printf("EGG address: %p\n", getenv("EGG"));
  if (argc > 1)
    strcpy(buffer, argv[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xea5(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1195 <main+0x65>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xebb(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
lea    0xed4(%rip),%rdi
call   1030 <getenv@plt>
lea    0xeb7(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
cmp    $0x2,%ebp
jl     1179 <main+0x49>
mov    0x8(%rbx),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Address of Buffer: %p\0A\00"
@.str.1 = [17 x i8] c"EGG address: %p\0A\00"
@.str.2 = [4 x i8] c"EGG\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [512 x i8]* %6 to i8**
%8 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %7)
%9 = call i8** @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %9)
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %14, i8* %17)
br label %19
19: ; preds = %13, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Address of Buffer: %p\0A\00"
@.str.1 = [17 x i8] c"EGG address: %p\0A\00"
@.str.2 = [4 x i8] c"EGG\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = bitcast [512 x i8]* %3 to i8**
%6 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %5)
%7 = call i8** @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %7)
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcpy(i8* %4, i8* %12)
br label %14
14: ; preds = %10, %2
ret i32 0
}