#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*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fread(char *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_error(char *, char *);
int id3_read_file(char *dest, unsigned long size, FILE *fp, char *fn) {
  if (fread(dest, size, 1, fp) != 1) {
    print_error("id3_read_file: Error reading %s", fn);
    fclose(fp);
    return 0;
  }
  if (ferror(fp) != 0) {
    print_error("id3_read_file: Error reading %s", fn);
    clearerr(fp);
    fclose(fp);
    return 0;
  }
  if (feof(fp)) {
    print_error("id3_read_file: Premature end of file in %s", fn);
    fclose(fp);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<id3_read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11bc <id3_read_file+0x5c>
mov    -0x28(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1050 <print_error@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <id3_read_file+0xdc>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11fd <id3_read_file+0x9d>
mov    -0x28(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1050 <print_error@plt>
mov    -0x20(%rbp),%rdi
call   1080 <clearerr@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <id3_read_file+0xdc>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1235 <id3_read_file+0xd5>
mov    -0x28(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1050 <print_error@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <id3_read_file+0xdc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3_read_file>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11a2 <id3_read_file+0x42>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11c3 <id3_read_file+0x63>
lea    0xe70(%rip),%rdi
mov    %r14,%rsi
call   1050 <print_error@plt>
mov    %rbx,%rdi
call   1080 <clearerr@plt>
jmp    11b1 <id3_read_file+0x51>
lea    0xe57(%rip),%rdi
mov    %r14,%rsi
call   1050 <print_error@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11d9 <id3_read_file+0x79>
lea    0xe49(%rip),%rdi
jmp    11a9 <id3_read_file+0x49>
mov    $0x1,%eax
jmp    11bb <id3_read_file+0x5b>

LLVM IR (-O0):
@.str = [32 x i8] c"id3_read_file: Error reading %s\00"
@.str.1 = [43 x i8] c"id3_read_file: Premature end of file in %s\00"
define i32 @id3_read_file(i8* %0, i64 %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%10 = load i8*, i8** %6
%11 = load i64, i64* %7
%12 = load i32*, i32** %8
%13 = call i32 @fread(i8* %10, i64 %11, i32 1, i32* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %9
%17 = call i32 @print_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %8
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %5
br label %41
20: ; preds = %4
%21 = load i32*, i32** %8
%22 = call i64 @ferror(i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i8*, i8** %9
%26 = call i32 @print_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %8
%28 = call i32 @clearerr(i32* %27)
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %5
br label %41
31: ; preds = %20
%32 = load i32*, i32** %8
%33 = call i64 @feof(i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8*, i8** %9
%37 = call i32 @print_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %5
br label %41
40: ; preds = %31
store i32 1, i32* %5
br label %41
41: ; preds = %40, %35, %24, %15
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [32 x i8] c"id3_read_file: Error reading %s\00"
@.str.1 = [43 x i8] c"id3_read_file: Premature end of file in %s\00"
define i32 @id3_read_file(i8* nocapture %0, i64 %1, i32* nocapture %2, i8* %3) {
%5 = tail call i32 @fread(i8* %0, i64 %1, i32 1, i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @print_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %20
9: ; preds = %4
%10 = tail call i64 @ferror(i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @print_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %3)
%14 = tail call i32 @clearerr(i32* %2)
br label %20
15: ; preds = %9
%16 = tail call i64 @feof(i32* %2)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = tail call i32 @print_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %20
20: ; preds = %7, %12, %18
%21 = tail call i32 @fclose(i32* %2)
br label %22
22: ; preds = %20, %15
%23 = phi i32 [ 1, %15 ], [ 0, %20 ]
ret i32 %23
}