#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[128];
  int integrity_number = 42;
  static char integrity_message[12] = "COVFEFE";
  printf("***** BEFORE ATTACK *****\n");
  printf("VAR integrity_number  : %p %d\n", &integrity_number,
         integrity_number);
  printf("VAR integrity_message : %p %s\n", &integrity_message,
         integrity_message);
  printf("VAR buffer            : %p %s\n", &buffer, buffer);
  fgets(buffer, 128, stdin);
  printf("\nbuffer : ");
  printf(buffer);
  printf("\n");
  printf("***** AFTER ATTACK *****\n");
  printf("VAR integrity_number  : %p %d\n", &integrity_number,
         integrity_number);
  printf("VAR integrity_message : %p %s\n", &integrity_message,
         integrity_message);
  printf("VAR buffer            : %p %s\n", &buffer, buffer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2a,-0x94(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x94(%rbp),%edx
lea    0xec4(%rip),%rdi
lea    -0x94(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    0x2ebd(%rip),%rdx
mov    %rdx,%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdx
lea    0xece(%rip),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x94(%rbp),%edx
lea    0xe23(%rip),%rdi
lea    -0x94(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2d(%rip),%rdi
lea    0x2e1c(%rip),%rdx
mov    %rdx,%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdx
lea    0xe2d(%rip),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
movl   $0x2a,0xc(%rsp)
lea    0xf08(%rip),%rdi
call   1040 <puts@plt>
lea    0xe94(%rip),%r14
lea    0xc(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x2a,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe95(%rip),%r12
lea    0x2eaf(%rip),%r13
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rbp
lea    0x10(%rsp),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1060 <fgets@plt>
lea    0xe83(%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    0xe86(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%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    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.integrity_message = internal global [12 x i8] c"COVFEFE\00\00\00\00\00"
@.str = [27 x i8] c"***** BEFORE ATTACK *****\0A\00"
@.str.1 = [31 x i8] c"VAR integrity_number : %p %d\0A\00"
@.str.2 = [31 x i8] c"VAR integrity_message : %p %s\0A\00"
@.str.3 = [31 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 [128 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 ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32 %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.integrity_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.integrity_message, i64 0, i64 0))
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), [128 x i8]* %5, i8* %11)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 128, 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 [128 x i8], [128 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 ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.integrity_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.integrity_message, i64 0, i64 0))
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), [128 x i8]* %5, i8* %24)
ret i32 0
}

LLVM IR (-O2):
@main.integrity_message = internal global [12 x i8] c"COVFEFE\00\00\00\00\00"
@.str.1 = [31 x i8] c"VAR integrity_number : %p %d\0A\00"
@.str.2 = [31 x i8] c"VAR integrity_message : %p %s\0A\00"
@.str.3 = [31 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 [128 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [128 x i8], [128 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 ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32 42)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.integrity_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.integrity_message, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), [128 x i8]* %3, i8* %5)
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %5, i32 128, 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 ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), [12 x i8]* @main.integrity_message, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @main.integrity_message, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), [128 x i8]* %3, i8* %5)
ret i32 0
}