#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int blockio_read(FILE *f, char *b, int l) {
  int i, c;
  for (i = 0; i < l; i++) {
    do {
      c = getc(f);
      if (c == EOF) {
        if (i > 0) {
          fprintf(
              stderr,
              "Warning: Short block (%d long) at end of input file ignored\n",
              i);
        }
        return EOF;
      }
    } while (c == ' ' || c == '\t' || c == '\n' || c == '\r');
    if (c != '0' && c != '1') {
      fprintf(stderr, "Bad character in binary file (not '0' or '1')\n");
      exit(1);
    }
    b[i] = c == '1';
  }
  return 0;
}


x86 assembly (clang, -O0):
<blockio_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1251 <blockio_read+0x121>
jmp    115b <blockio_read+0x2b>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%eax
jne    11ae <blockio_read+0x7e>
cmpl   $0x0,-0x20(%rbp)
jle    119d <blockio_read+0x6d>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <blockio_read+0x128>
jmp    11b3 <blockio_read+0x83>
mov    $0x1,%al
cmpl   $0x20,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     11ea <blockio_read+0xba>
mov    $0x1,%al
cmpl   $0x9,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     11ea <blockio_read+0xba>
mov    $0x1,%al
cmpl   $0xa,-0x24(%rbp)
mov    %al,-0x25(%rbp)
je     11ea <blockio_read+0xba>
cmpl   $0xd,-0x24(%rbp)
sete   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    115b <blockio_read+0x2b>
cmpl   $0x30,-0x24(%rbp)
je     122a <blockio_read+0xfa>
cmpl   $0x31,-0x24(%rbp)
je     122a <blockio_read+0xfa>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
cmpl   $0x31,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114a <blockio_read+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blockio_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11bf <blockio_read+0x8f>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%r13d
xor    %r15d,%r15d
mov    0x2e92(%rip),%r12
movabs $0x100002600,%rbp
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r12),%eax
je     119a <blockio_read+0x6a>
cmp    $0x20,%eax
ja     117b <blockio_read+0x4b>
mov    %eax,%ecx
bt     %rcx,%rbp
jb     1160 <blockio_read+0x30>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
cmp    $0x30,%ecx
jne    11d0 <blockio_read+0xa0>
cmp    $0x31,%eax
sete   (%r14,%r15,1)
add    $0x1,%r15
xor    %eax,%eax
cmp    %r13,%r15
jne    1160 <blockio_read+0x30>
jmp    11c1 <blockio_read+0x91>
test   %r15d,%r15d
je     11c1 <blockio_read+0x91>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r12),%eax
jmp    11c1 <blockio_read+0x91>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [61 x i8] c"Warning: Short block (%d long) at end of input file ignored\0A\00"
@.str.1 = [47 x i8] c"Bad character in binary file (not '0' or '1')\0A\00"
define i32 @blockio_read(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %64, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %67
14: ; preds = %10
br label %15
15: ; preds = %43, %14
%16 = load i32*, i32** %5
%17 = call i32 @getc(i32* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %30
21: ; preds = %15
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i32, i32* %8
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %21
%29 = load i32, i32* @EOF
store i32 %29, i32* %4
br label %68
30: ; preds = %15
br label %31
31: ; preds = %30
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, 32
br i1 %33, label %43, label %34
34: ; preds = %31
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, 9
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, 10
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, 13
br label %43
43: ; preds = %40, %37, %34, %31
%44 = phi i1 [ true, %37 ], [ true, %34 ], [ true, %31 ], [ %42, %40 ]
br i1 %44, label %15, label %45
45: ; preds = %43
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 48
br i1 %47, label %48, label %55
48: ; preds = %45
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 49
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48, %45
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, 49
%58 = zext i1 %57 to i32
%59 = trunc i32 %58 to i8
%60 = load i8*, i8** %6
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 %59, i8* %63
br label %64
64: ; preds = %55
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %10
67: ; preds = %10
store i32 0, i32* %4
br label %68
68: ; preds = %67, %28
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [61 x i8] c"Warning: Short block (%d long) at end of input file ignored\0A\00"
@.str.1 = [47 x i8] c"Bad character in binary file (not '0' or '1')\0A\00"
define i32 @blockio_read(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %39
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %33
%8 = phi i64 [ 0, %5 ], [ %37, %33 ]
%9 = tail call i32 @getc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %7, %22
%13 = phi i32 [ %23, %22 ], [ %9, %7 ]
%14 = trunc i64 %8 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %39, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i32 %14)
%19 = load i32, i32* @EOF
br label %39
20: ; preds = %7, %22
%21 = phi i32 [ %23, %22 ], [ %9, %7 ]
switch i32 %21, label %26 [
i32 32, label %22
i32 13, label %22
i32 10, label %22
i32 9, label %22
]
22: ; preds = %20, %20, %20, %20
%23 = tail call i32 @getc(i32* %0)
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %12, label %20
26: ; preds = %20
%27 = and i32 %21, -2
%28 = icmp eq i32 %27, 48
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = icmp eq i32 %21, 49
%35 = zext i1 %34 to i8
%36 = getelementptr inbounds i8, i8* %1, i64 %8
store i8 %35, i8* %36
%37 = add nuw nsw i64 %8, 1
%38 = icmp eq i64 %37, %6
br i1 %38, label %39, label %7
39: ; preds = %33, %12, %16, %3
%40 = phi i32 [ 0, %3 ], [ %19, %16 ], [ %13, %12 ], [ 0, %33 ]
ret i32 %40
}