#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*/ printBuffer(char *, size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void bufferOverReadUsingStack(char *input, size_t length) {
  {
    char buf[] =
        "This is a very secret message which should not be exposed to public. "
        "This is a very secret message which should not be exposed to public. "
        "This is a very secret message which should not be exposed to public. "
        "This is a very secret message which should not be exposed to public.";
    char buf2[strlen(buf)];
    strcpy(buf2, buf);
  }
  char buffer[length];
  strcpy(buffer, input);
  printf("Buffer on Stack:\n");
  printBuffer(buffer, length);
}


x86 assembly (clang, -O0):
<bufferOverReadUsingStack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe96(%rip),%rsi
lea    -0x130(%rbp),%rdi
mov    %rdi,-0x160(%rbp)
mov    $0x114,%edx
call   1060 <memcpy@plt>
mov    -0x160(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x160(%rbp),%rsi
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x138(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x140(%rbp)
call   1030 <strcpy@plt>
mov    -0x138(%rbp),%rax
mov    %rax,%rsp
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x148(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x158(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x150(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    0xf09(%rip),%rdi
call   1050 <printf@plt>
mov    -0x158(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <printBuffer@plt>
mov    -0x148(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferOverReadUsingStack>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe91(%rip),%rsi
lea    -0x140(%rbp),%r12
mov    $0x114,%edx
mov    %r12,%rdi
call   1060 <memcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rsp,%rbx
mov    %eax,%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rsp
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xf45(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <printBuffer@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.bufferOverReadUsingStack.buf = [276 x i8] c"This is a very secret message which should not be exposed to public. This is a very secret message which should not be exposed to public. This is a very secret message which should not be exposed to public. This is a very secret message which should not be exposed to public.\00"
@.str = [18 x i8] c"Buffer on Stack:\0A\00"
define void @bufferOverReadUsingStack(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [276 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%10 = bitcast [276 x i8]* %5 to i8*
%11 = getelementptr inbounds [276 x i8], [276 x i8]* %5, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = getelementptr inbounds [276 x i8], [276 x i8]* %5, i64 0, i64 0
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %6
%19 = load i64, i64* %4
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %8
%21 = alloca i8, i64 %19
store i64 %19, i64* %9
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%25 = load i64, i64* %4
%26 = call i32 @printBuffer(i8* %21, i64 %25)
%27 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@__const.bufferOverReadUsingStack.buf = [276 x i8] c"This is a very secret message which should not be exposed to public. This is a very secret message which should not be exposed to public. This is a very secret message which should not be exposed to public. This is a very secret message which should not be exposed to public.\00"
@str = [17 x i8] c"Buffer on Stack:\00"
define void @bufferOverReadUsingStack(i8* %0, i64 %1) {
%3 = alloca [276 x i8]
%4 = getelementptr inbounds [276 x i8], [276 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @strcpy(i8* %8, i8* %4)
%10 = alloca i8, i64 %1
%11 = call i32 @strcpy(i8* %10, i8* %0)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%13 = call i32 @printBuffer(i8* %10, i64 %1)
ret void
}