#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 *, ...);
int /*<<< orphan*/ strcpy(char *, char const *);
void foo(const char *input) {
  char buf[10];
  printf("My stack looks "
         "like:\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
  strcpy(buf, input);
  printf("Buffer address: %p\n", buf);
  printf("Address for point of execution: %p\n", (buf + 602));
  printf("Now the stack looks "
         "like:\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n%p\n\n");
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x12(%rbp),%rsi
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x12(%rbp),%rsi
add    $0x25a,%rsi
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xef2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x268(%rsp),%rsi
lea    0xeed(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf03(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [65 x i8] c"My stack looks like:\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A\0A\00"
@.str.1 = [20 x i8] c"Buffer address: %p\0A\00"
@.str.2 = [36 x i8] c"Address for point of execution: %p\0A\00"
@.str.3 = [70 x i8] c"Now the stack looks like:\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A\0A\00"
define void @foo(i8* %0) {
%2 = alloca i8*
%3 = alloca [10 x i8]
store i8* %0, i8** %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @strcpy(i8* %5, i8* %6)
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %10, i64 602
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [65 x i8] c"My stack looks like:\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A\0A\00"
@.str.1 = [20 x i8] c"Buffer address: %p\0A\00"
@.str.2 = [36 x i8] c"Address for point of execution: %p\0A\00"
@.str.3 = [70 x i8] c"Now the stack looks like:\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A%p\0A\0A\00"
define void @foo(i8* %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strcpy(i8* %3, i8* %0)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 602
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
ret void
}