#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*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ms_log(int, char *);
int ms_fread(char *buf, int size, int num, FILE *stream) {
  int read = 0;
  read = (int)fread(buf, size, num, stream);
  if (read <= 0 && size && num) {
    if (ferror(stream))
      ms_log(2, "ms_fread(): Cannot read input file\n");
    else if (!feof(stream))
      ms_log(2, "ms_fread(): Unknown return from fread()\n");
  }
  return read;
}


x86 assembly (clang, -O0):
<ms_fread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11e7 <ms_fread+0xa7>
cmpl   $0x0,-0xc(%rbp)
je     11e7 <ms_fread+0xa7>
cmpl   $0x0,-0x10(%rbp)
je     11e7 <ms_fread+0xa7>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ba <ms_fread+0x7a>
mov    $0x2,%edi
lea    0xe50(%rip),%rsi
call   1060 <ms_log@plt>
jmp    11e2 <ms_fread+0xa2>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
jne    11dd <ms_fread+0x9d>
mov    $0x2,%edi
lea    0xe4c(%rip),%rsi
call   1060 <ms_log@plt>
jmp    11e2 <ms_fread+0xa2>
jmp    11e7 <ms_fread+0xa7>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ms_fread>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%ebx
mov    %esi,%ebp
call   1040 <fread@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     118f <ms_fread+0x4f>
test   %ebp,%ebp
je     118f <ms_fread+0x4f>
test   %r14d,%r14d
jg     118f <ms_fread+0x4f>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1183 <ms_fread+0x43>
lea    0xe89(%rip),%rsi
mov    $0x2,%edi
call   1060 <ms_log@plt>
jmp    118f <ms_fread+0x4f>
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     119d <ms_fread+0x5d>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe80(%rip),%rsi
jmp    1177 <ms_fread+0x37>

LLVM IR (-O0):
@.str = [36 x i8] c"ms_fread(): Cannot read input file\0A\00"
@.str.1 = [41 x i8] c"ms_fread(): Unknown return from fread()\0A\00"
define i32 @ms_fread(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load i32*, i32** %8
%14 = call i64 @fread(i8* %10, i32 %11, i32 %12, i32* %13)
%15 = trunc i64 %14 to i32
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %4
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = load i32, i32* %7
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = load i32*, i32** %8
%26 = call i64 @ferror(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @ms_log(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %37
30: ; preds = %24
%31 = load i32*, i32** %8
%32 = call i32 @feof(i32* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %30
%35 = call i32 @ms_log(i32 2, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
br label %37
37: ; preds = %36, %28
br label %38
38: ; preds = %37, %21, %18, %4
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
@.str = [36 x i8] c"ms_fread(): Cannot read input file\0A\00"
@.str.1 = [41 x i8] c"ms_fread(): Unknown return from fread()\0A\00"
define i32 @ms_fread(i8* nocapture %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = tail call i64 @fread(i8* %0, i32 %1, i32 %2, i32* %3)
%6 = trunc i64 %5 to i32
%7 = icmp slt i32 %6, 1
%8 = icmp ne i32 %1, 0
%9 = and i1 %8, %7
%10 = icmp ne i32 %2, 0
%11 = and i1 %10, %9
br i1 %11, label %12, label %21
12: ; preds = %4
%13 = tail call i64 @ferror(i32* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @feof(i32* %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15, %12
%19 = phi i8* [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), %12 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), %15 ]
%20 = tail call i32 @ms_log(i32 2, i8* %19)
br label %21
21: ; preds = %18, %15, %4
ret i32 %6
}