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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
void secretFunc() {
  puts("You did it :))");
  int fd = open("flag.txt", O_RDONLY), cnt;
  char buf[128];
  printf("Flag is: ");
  while ((cnt = read(fd, buf, sizeof(buf))) > 0) {
    buf[cnt] = 0;
    printf("%s", buf);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<secretFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11d3 <secretFunc+0x83>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118d <secretFunc+0x3d>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<secretFunc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x80,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11d6 <secretFunc+0x86>
lea    0xe7c(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11b0 <secretFunc+0x60>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"You did it :))\00"
@.str.1 = [9 x i8] c"flag.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [10 x i8] c"Flag is: \00"
@.str.3 = [3 x i8] c"%s\00"
define void @secretFunc() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %13, %0
%9 = load i32, i32* %1
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 128)
store i32 %11, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %8
19: ; preds = %8
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [15 x i8] c"You did it :))\00"
@.str.1 = [9 x i8] c"flag.txt\00"
@O_RDONLY = global i32 0
@.str.2 = [10 x i8] c"Flag is: \00"
@.str.3 = [3 x i8] c"%s\00"
define void @secretFunc() {
%1 = alloca [128 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @read(i32 %4, i8* %5, i32 128)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %0, %9
%10 = phi i32 [ %14, %9 ], [ %7, %0 ]
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%14 = call i32 @read(i32 %4, i8* %5, i32 128)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %9, label %16
16: ; preds = %9, %0
%17 = call i32 @exit(i32 0)
unreachable
}