#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;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
int main() {
  int fd;
  size_t size;
  char string[15];
  if ((fd = open("myfile", O_RDONLY)) < 0) {
    printf("Can\'t open file\n");
    exit(-1);
  }
  size = read(fd, string, 14);
  if (size != 14) {
    printf("Can\'t read all string\n");
    exit(-1);
  }
  printf("%s\n", string);
  if (close(fd) < 0)
    printf("Can\'t close file\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1198 <main+0x48>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x1f(%rbp),%rsi
mov    $0xe,%edx
call   1050 <read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xe,-0x10(%rbp)
je     11d0 <main+0x80>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x1f(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1202 <main+0xb2>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11b1 <main+0x61>
mov    %eax,%ebx
lea    0x1(%rsp),%rsi
mov    %eax,%edi
mov    $0xe,%edx
call   1050 <read@plt>
cmp    $0xe,%rax
jne    11ba <main+0x6a>
lea    0x1(%rsp),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
jns    11a9 <main+0x59>
lea    0xe63(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe76(%rip),%rdi
jmp    11c1 <main+0x71>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"myfile\00"
@O_RDONLY = global i32 0
@.str.1 = [17 x i8] c"Can't open file\0A\00"
@.str.2 = [23 x i8] c"Can't read all string\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [18 x i8] c"Can't close file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca [15 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %2
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%14 = call i64 @read(i32 %12, i8* %13, i32 14)
store i64 %14, i64* %3
%15 = load i64, i64* %3
%16 = icmp ne i64 %15, 14
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %11
%21 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %2
%24 = call i64 @close(i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfile\00"
@O_RDONLY = global i32 0
@str = [17 x i8] c"Can't close file\00"
@str.5 = [22 x i8] c"Can't read all string\00"
@str.6 = [16 x i8] c"Can't open file\00"
define i32 @main() {
%1 = alloca [15 x i8]
%2 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = call i64 @read(i32 %4, i8* %2, i32 14)
%11 = icmp eq i64 %10, 14
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %9
%16 = call i32 @puts(i8* %2)
%17 = tail call i64 @close(i32 %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
ret i32 0
}