#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void print_file(const char *file) {
  int fd = open(file, O_RDONLY);
  if (fd == -1) {
    puts("could not open flag");
    exit(1);
  }
  char c;
  while (read(fd, &c, 1) == 1) {
    write(1, &c, 1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a1 <print_file+0x41>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11a6 <print_file+0x46>
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    11d5 <print_file+0x75>
mov    $0x1,%edx
lea    -0xd(%rbp),%rsi
mov    %edx,%edi
call   1040 <write@plt>
jmp    11a6 <print_file+0x46>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d3 <print_file+0x73>
mov    %eax,%ebp
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    11c6 <print_file+0x66>
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
je     11a0 <print_file+0x40>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <close@plt>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [20 x i8] c"could not open flag\00"
define void @print_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
br label %14
14: ; preds = %18, %13
%15 = load i32, i32* %3
%16 = call i32 @read(i32 %15, i8* %4, i32 1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @write(i32 1, i8* %4, i32 1)
br label %14
20: ; preds = %14
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [20 x i8] c"could not open flag\00"
define void @print_file(i8* nocapture %0) {
%2 = alloca i8
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = call i32 @read(i32 %4, i8* %2, i32 1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %16
12: ; preds = %9, %12
%13 = call i32 @write(i32 1, i8* %2, i32 1)
%14 = call i32 @read(i32 %4, i8* %2, i32 1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %12, label %16
16: ; preds = %12, %9
%17 = tail call i32 @close(i32 %4)
ret void
}