#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fs;
  char buf[10];
  size_t sz;
  fs = fopen("mytext.txt", "r");
  if (fs == NULL) {
    perror("fopen error");
    exit(1);
  }
  while (!feof(fs)) {
    sz - fread((void *)buf, 9, 1, fs);
    printf("%s", buf);
  }
  fclose(fs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <main+0x4e>
lea    0xe5c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11c3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e1 <main+0x71>
jmp    120d <main+0x9d>
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x9,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
lea    -0x22(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1050 <printf@plt>
jmp    11c3 <main+0x53>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe80(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f0 <main+0x80>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11dc <main+0x6c>
lea    0x6(%rsp),%r14
lea    0xe6b(%rip),%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11b0 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe14(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"mytext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"fopen error\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [10 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %21, %15
%17 = load i32*, i32** %6
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i64, i64* %8
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%24 = load i32*, i32** %6
%25 = call i64 @fread(i8* %23, i32 9, i32 1, i32* %24)
%26 = sub i64 %22, %25
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %16
29: ; preds = %16
%30 = load i32*, i32** %6
%31 = call i32 @fclose(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"mytext.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"fopen error\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %18
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %13
%14 = call i64 @fread(i8* %4, i32 9, i32 1, i32* %5)
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%16 = call i32 @feof(i32* %5)
%17 = icmp eq i32 %16, 0
br i1 %17, label %13, label %18
18: ; preds = %13, %7
%19 = call i32 @fclose(i32* %5)
ret i32 0
}