#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 BUFSIZ;
int feof(int /*<<< orphan*/ *);
int ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *f_in;
  int itemsRead;
  char buf[BUFSIZ];
  f_in = fopen("x_data.in", "r");
  if (!f_in) {
    printf("cannot open file x_data.in\n");
  } else {
    itemsRead = fread(buf, 8, 1, f_in);
    if (itemsRead < 1) {
      printf("Cannot read from x_data.in\n");
      printf("return from fread = %d, error = %d, eof = %d\n", itemsRead,
             ferror(f_in), feof(f_in));
    } else {
      printf("read %d items from x_data.in\n", itemsRead);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe6e(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c0 <main+0x70>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123e <main+0xee>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1228 <main+0xd8>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1239 <main+0xe9>
mov    -0x14(%rbp),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    123e <main+0xee>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xed4(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ce <main+0x6e>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    11dc <main+0x7c>
lea    0xe6e(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    120f <main+0xaf>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
jmp    120f <main+0xaf>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <ferror@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1070 <feof@plt>
lea    0xe01(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [10 x i8] c"x_data.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [28 x i8] c"cannot open file x_data.in\0A\00"
@.str.3 = [28 x i8] c"Cannot read from x_data.in\0A\00"
@.str.4 = [46 x i8] c"return from fread = %d, error = %d, eof = %d\0A\00"
@.str.5 = [30 x i8] c"read %d items from x_data.in\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = load i32, i32* @BUFSIZ
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %32
15: ; preds = %0
%16 = load i32*, i32** %2
%17 = call i32 @fread(i8* %9, i32 8, i32 1, i32* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = load i32*, i32** %2
%24 = call i32 @ferror(i32* %23)
%25 = load i32*, i32** %2
%26 = call i32 @feof(i32* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %24, i32 %26)
br label %31
28: ; preds = %15
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %20
br label %32
32: ; preds = %31, %13
store i32 0, i32* %1
%33 = load i8*, i8** %4
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [10 x i8] c"x_data.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [46 x i8] c"return from fread = %d, error = %d, eof = %d\0A\00"
@.str.5 = [30 x i8] c"read %d items from x_data.in\0A\00"
@str = [27 x i8] c"cannot open file x_data.in\00"
@str.6 = [27 x i8] c"Cannot read from x_data.in\00"
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %18
8: ; preds = %0
%9 = call i32 @fread(i8* %3, i32 8, i32 1, i32* %4)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @ferror(i32* %4)
%14 = tail call i32 @feof(i32* %4)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %9, i32 %13, i32 %14)
br label %18
16: ; preds = %8
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %11, %16, %6
ret i32 0
}