#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char buffer[12];
  int secret_number = 42;
  static char secret_message[12] = "COVFEFE";
  printf("***** BEFORE ATTACK *****\n");
  printf("VAR secret_number  : %p %d\n", &secret_number, secret_number);
  printf("VAR secret_message : %p %s\n", &secret_message, secret_message);
  printf("VAR buffer         : %p %s\n", &buffer, buffer);
  fgets(buffer, 12, stdin);
  printf("\nbuffer : ");
  printf(buffer);
  printf("\n");
  printf("***** AFTER ATTACK *****\n");
  printf("VAR secret_number  : %p %d\n", &secret_number, secret_number);
  printf("VAR secret_message : %p %s\n", &secret_message, secret_message);
  printf("VAR buffer         : %p %s\n", &buffer, buffer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2a,-0x20(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%edx
lea    0xecd(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    0x2ec9(%rip),%rdx
mov    %rdx,%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1c(%rbp),%rdx
lea    0xed7(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1c(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    $0xc,%esi
call   1040 <fgets@plt>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1c(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%edx
lea    0xe3e(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe48(%rip),%rdi
lea    0x2e3a(%rip),%rdx
mov    %rdx,%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1c(%rbp),%rdx
lea    0xe48(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x2a,0x8(%rsp)
lea    0xf02(%rip),%rdi
call   1040 <puts@plt>
lea    0xe97(%rip),%r14
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x2a,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe95(%rip),%r12
lea    0x2eb2(%rip),%r13
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe93(%rip),%rbp
lea    0xc(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1060 <fgets@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.secret_message = internal global [12 x i8] c"COVFEFE\00\00\00\00\00"
@.str = [27 x i8] c"***** BEFORE ATTACK *****\0A\00"
@.str.1 = [28 x i8] c"VAR secret_number : %p %d\0A\00"
@.str.2 = [28 x i8] c"VAR secret_message : %p %s\0A\00"
@.str.3 = [28 x i8] c"VAR buffer : %p %s\0A\00"
@stdin = global i32 0
@.str.4 = [11 x i8] c"\0Abuffer : \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [26 x i8] c"***** AFTER ATTACK *****\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [12 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 42, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.secret_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.secret_message, i64 0, i64 0))
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), [12 x i8]* %5, i8* %11)
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 12, i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%17 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.secret_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.secret_message, i64 0, i64 0))
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), [12 x i8]* %5, i8* %24)
ret i32 0
}

LLVM IR (-O2):
@main.secret_message = internal global [12 x i8] c"COVFEFE\00\00\00\00\00"
@.str.1 = [28 x i8] c"VAR secret_number : %p %d\0A\00"
@.str.2 = [28 x i8] c"VAR secret_message : %p %s\0A\00"
@.str.3 = [28 x i8] c"VAR buffer : %p %s\0A\00"
@stdin = global i32 0
@.str.4 = [11 x i8] c"\0Abuffer : \00"
@str = [26 x i8] c"***** BEFORE ATTACK *****\00"
@str.7 = [25 x i8] c"***** AFTER ATTACK *****\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [12 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 42, i32* %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32 42)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.secret_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.secret_message, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), [12 x i8]* %3, i8* %5)
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %5, i32 12, i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* %5)
%15 = call i32 @putchar(i32 10)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.secret_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.secret_message, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), [12 x i8]* %3, i8* %5)
ret i32 0
}