#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int bc_read_block_from_file(char *file_name, char *block, int num_bytes) {
  FILE *fp;
  int nread;
  int rv = 0;
  fp = fopen(file_name, "rb");
  if (fp == 0) {
    fprintf(stderr, "Couldn't open file \"%s\" for read.\n", file_name);
    return 0;
  }
  nread = fread(block, sizeof(char), num_bytes, fp);
  if (nread == num_bytes) {
    rv = 1;
  } else {
    fprintf(stderr, "Couldn't read %d bytes from file \"%s\".\n", num_bytes,
            file_name);
  }
  fclose(fp);
  return rv;
}


x86 assembly (clang, -O0):
<bc_read_block_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a0 <bc_read_block_from_file+0x60>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fd <bc_read_block_from_file+0xbd>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11d0 <bc_read_block_from_file+0x90>
movl   $0x1,-0x30(%rbp)
jmp    11ee <bc_read_block_from_file+0xae>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bc_read_block_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a9 <bc_read_block_from_file+0x69>
mov    %rax,%rbx
mov    $0x1,%r14d
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    %ebp,%eax
je     119f <bc_read_block_from_file+0x5f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
xor    %r14d,%r14d
mov    %ebp,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11c6 <bc_read_block_from_file+0x86>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
xor    %r14d,%r14d
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Couldn't open file \22%s\22 for read.\0A\00"
@.str.2 = [40 x i8] c"Couldn't read %d bytes from file \22%s\22.\0A\00"
define i32 @bc_read_block_from_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 0, i32* %4
br label %37
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = load i32*, i32** %8
%23 = call i32 @fread(i8* %20, i32 1, i32 %21, i32* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 1, i32* %10
br label %33
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = load i32, i32* %7
%31 = load i8*, i8** %5
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %30, i8* %31)
br label %33
33: ; preds = %28, %27
%34 = load i32*, i32** %8
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %10
store i32 %36, i32* %4
br label %37
37: ; preds = %33, %15
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Couldn't open file \22%s\22 for read.\0A\00"
@.str.2 = [40 x i8] c"Couldn't read %d bytes from file \22%s\22.\0A\00"
define i32 @bc_read_block_from_file(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
9: ; preds = %3
%10 = tail call i32 @fread(i8* %1, i32 1, i32 %2, i32* %4)
%11 = icmp eq i32 %10, %2
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %2, i8* %0)
br label %15
15: ; preds = %9, %12
%16 = phi i32 [ 0, %12 ], [ 1, %9 ]
%17 = tail call i32 @fclose(i32* %4)
br label %18
18: ; preds = %15, %6
%19 = phi i32 [ 0, %6 ], [ %16, %15 ]
ret i32 %19
}