#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stdout;
void hahaexploitgobrrr() {
  char buf[200];
  FILE *f = fopen("flag.txt", "r");
  fgets(buf, 200, f);
  fprintf(stdout, "%s\n", buf);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<hahaexploitgobrrr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xd8(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0xd8(%rbp),%rdx
mov    $0xc8,%esi
call   1030 <fgets@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    -0xd0(%rbp),%rdx
lea    0xe77(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hahaexploitgobrrr>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
lea    0xeaf(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
mov    0x2e69(%rip),%rbx
mov    (%rbx),%edi
lea    0xe8b(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"flag.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define void @hahaexploitgobrrr() {
%1 = alloca [200 x i8]
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%5 = load i32*, i32** %2
%6 = call i32 @fgets(i8* %4, i32 200, i32* %5)
%7 = load i32, i32* @stdout
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"flag.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define void @hahaexploitgobrrr() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @fgets(i8* %2, i32 200, i32* %3)
%5 = load i32, i32* @stdout
%6 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
ret void
}