#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 */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void mdv_read(FILE *fp, char *buf, int len) {
  if (fread(buf, len, 1, fp) != 1) {
    if (errno)
      perror("fread");
    else
      fprintf(stderr, "Unexpected EOF\n");
  }
}


x86 assembly (clang, -O0):
<mdv_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     119d <mdv_read+0x6d>
mov    0x2e70(%rip),%rax
cmpq   $0x0,(%rax)
je     1183 <mdv_read+0x53>
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
jmp    1198 <mdv_read+0x68>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
jmp    119d <mdv_read+0x6d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdv_read>:
push   %rax
mov    %rdi,%rcx
mov    %rsi,%rdi
mov    %edx,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    114a <mdv_read+0x1a>
pop    %rax
ret
mov    0x2e87(%rip),%rax
cmpq   $0x0,(%rax)
jne    116d <mdv_read+0x3d>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
pop    %rax
jmp    1040 <fprintf@plt>
lea    0xe8c(%rip),%rdi
pop    %rax
jmp    1050 <perror@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [6 x i8] c"fread\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Unexpected EOF\0A\00"
define void @mdv_read(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = load i32, i32* %6
%9 = load i32*, i32** %4
%10 = call i32 @fread(i8* %7, i32 %8, i32 1, i32* %9)
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i64, i64* @errno
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %15
br label %21
21: ; preds = %20, %3
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [6 x i8] c"fread\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Unexpected EOF\0A\00"
define void @mdv_read(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @fread(i8* %1, i32 %2, i32 1, i32* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %14
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %9, %11, %3
ret void
}