#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  char buffer[80];
  memset(buffer, 0x90, sizeof(buffer));
  if (argc >= 2) {
    printf("argc: %d\n", argc);
    strcpy(buffer, argv[1]);
  }
  printf("Address of buffer: %010p\n", &buffer);
  printf("I haven't been hacked yet. Going to exit program normally.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x90,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jl     1185 <main+0x55>
mov    -0x8(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    0xe7e(%rip),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x90,%esi
mov    $0x50,%edx
call   1060 <memset@plt>
cmp    $0x2,%ebp
jl     117e <main+0x3e>
lea    0xe97(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
lea    0xe85(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"argc: %d\0A\00"
@.str.1 = [26 x i8] c"Address of buffer: %010p\0A\00"
@.str.2 = [60 x i8] c"I haven't been hacked yet. Going to exit program normally.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 144, i32 80)
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [80 x i8], [80 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 = %11, %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), [80 x i8]* %6)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"argc: %d\0A\00"
@.str.1 = [26 x i8] c"Address of buffer: %010p\0A\00"
@str = [59 x i8] c"I haven't been hacked yet. Going to exit program normally.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 144, i32 80)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @strcpy(i8* %4, i8* %10)
br label %12
12: ; preds = %7, %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), [80 x i8]* %3)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
ret i32 0
}