#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*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wl(int);
void fblock(char *name, int blen) {
  FILE *f;
  size_t ret;
  void *b;
  f = fopen(name, "r");
  if (f == NULL) {
    perror(name);
    exit(1);
  }
  b = malloc(blen);
  if (b == NULL) {
    perror("malloc:");
    exit(1);
  }
  while (!feof(f)) {
    memset(b, 0, blen);
    ret = fread(b, blen, 1, f);
    if (ret < blen) {
      if (ferror(f)) {
        perror(name);
        exit(1);
      }
    }
    if (ret == 0)
      continue;
    wl(blen);
    fwrite(b, blen, 1, stdout);
    wl(blen);
  }
  if (fclose(f) != 0) {
    perror(name);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<fblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f1 <fblock+0x41>
mov    -0x8(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0xc(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    121e <fblock+0x6e>
lea    0xdf3(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1223 <fblock+0x73>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1241 <fblock+0x91>
jmp    12e3 <fblock+0x133>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jae    12a4 <fblock+0xf4>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     129f <fblock+0xef>
mov    -0x8(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12a4 <fblock+0xf4>
cmpq   $0x0,-0x20(%rbp)
jne    12b4 <fblock+0x104>
jmp    1223 <fblock+0x73>
mov    -0xc(%rbp),%edi
call   1090 <wl@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2d16(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    -0xc(%rbp),%edi
call   1090 <wl@plt>
jmp    1223 <fblock+0x73>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1309 <fblock+0x159>
mov    -0x8(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe39(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a9 <fblock+0xf9>
mov    %rax,%r15
mov    %rbx,(%rsp)
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12ae <fblock+0xfe>
mov    %rax,%r12
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     121b <fblock+0x6b>
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1296 <fblock+0xe6>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %ebp,%r13
mov    0x2dbb(%rip),%r14
jmp    123c <fblock+0x8c>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11fb <fblock+0x4b>
mov    %r12,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
cmp    %r13,%rax
jae    126f <fblock+0xbf>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1296 <fblock+0xe6>
test   %rbx,%rbx
je     1230 <fblock+0x80>
mov    %ebp,%edi
call   1090 <wl@plt>
mov    (%r14),%ecx
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    %ebp,%edi
call   1090 <wl@plt>
jmp    1230 <fblock+0x80>
mov    (%rsp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rbx,%rdi
jmp    129a <fblock+0xea>
lea    0xd4d(%rip),%rdi
jmp    129a <fblock+0xea>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"malloc:\00"
@stdout = global i32 0
define void @fblock(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @perror(i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %4
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
br label %25
25: ; preds = %55, %54, %24
%26 = load i32*, i32** %5
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %64
30: ; preds = %25
%31 = load i8*, i8** %7
%32 = load i32, i32* %4
%33 = call i32 @memset(i8* %31, i32 0, i32 %32)
%34 = load i8*, i8** %7
%35 = load i32, i32* %4
%36 = load i32*, i32** %5
%37 = call i64 @fread(i8* %34, i32 %35, i32 1, i32* %36)
store i64 %37, i64* %6
%38 = load i64, i64* %6
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = icmp ult i64 %38, %40
br i1 %41, label %42, label %51
42: ; preds = %30
%43 = load i32*, i32** %5
%44 = call i64 @ferror(i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8*, i8** %3
%48 = call i32 @perror(i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %42
br label %51
51: ; preds = %50, %30
%52 = load i64, i64* %6
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
br label %25
55: ; preds = %51
%56 = load i32, i32* %4
%57 = call i32 @wl(i32 %56)
%58 = load i8*, i8** %7
%59 = load i32, i32* %4
%60 = load i32, i32* @stdout
%61 = call i32 @fwrite(i8* %58, i32 %59, i32 1, i32 %60)
%62 = load i32, i32* %4
%63 = call i32 @wl(i32 %62)
br label %25
64: ; preds = %25
%65 = load i32*, i32** %5
%66 = call i64 @fclose(i32* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i8*, i8** %3
%70 = call i32 @perror(i8* %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %64
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"malloc:\00"
@stdout = global i32 0
define void @fblock(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i8* @malloc(i32 %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = tail call i32 @feof(i32* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %39
14: ; preds = %11
%15 = sext i32 %1 to i64
br label %19
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %14, %36
%20 = tail call i32 @memset(i8* %9, i32 0, i32 %1)
%21 = tail call i64 @fread(i8* %9, i32 %1, i32 1, i32* %3)
%22 = icmp ult i64 %21, %15
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = tail call i64 @ferror(i32* %3)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = tail call i32 @perror(i8* %0)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %23, %19
%30 = icmp eq i64 %21, 0
br i1 %30, label %36, label %31
31: ; preds = %29
%32 = tail call i32 @wl(i32 %1)
%33 = load i32, i32* @stdout
%34 = tail call i32 @fwrite(i8* %9, i32 %1, i32 1, i32 %33)
%35 = tail call i32 @wl(i32 %1)
br label %36
36: ; preds = %31, %29
%37 = tail call i32 @feof(i32* %3)
%38 = icmp eq i32 %37, 0
br i1 %38, label %19, label %39
39: ; preds = %36, %11
%40 = tail call i64 @fclose(i32* %3)
%41 = icmp eq i64 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = tail call i32 @perror(i8* %0)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %39
ret void
}