#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*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fromhex(char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int strlen(char *);
int read_page(FILE *in, char *buf, unsigned char *page) {
  int l, len, num = 0;
  memset(page, 0, 256);
  while ((!feof(in)) && (num < 256)) {
    buf[0] = 0;
    if (!fgets(buf, 512, in))
      buf[0] = 0;
    if (buf[0] == '#')
      continue;
    len = strlen(buf);
    for (l = 0; l + 1 < len; l += 2) {
      if (num < 256)
        page[num++] = (unsigned char)fromhex(buf + l);
      else {
        num = -1;
        break;
      }
    }
  }
  return (num == 256);
}


x86 assembly (clang, -O0):
<read_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
jne    11a1 <read_page+0x51>
cmpl   $0x100,-0x24(%rbp)
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b1 <read_page+0x61>
jmp    126e <read_page+0x11e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    11da <read_page+0x8a>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11ef <read_page+0x9f>
jmp    117b <read_page+0x2b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x20(%rbp),%eax
jge    1269 <read_page+0x119>
cmpl   $0x100,-0x24(%rbp)
jge    124a <read_page+0xfa>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1050 <fromhex@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1256 <read_page+0x106>
movl   $0xffffffff,-0x24(%rbp)
jmp    1269 <read_page+0x119>
jmp    125b <read_page+0x10b>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    1202 <read_page+0xb2>
jmp    117b <read_page+0x2b>
cmpl   $0x100,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_page>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %ebp,%ebp
mov    %rdx,(%rsp)
mov    %rdx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1218 <read_page+0xc8>
cmp    $0xff,%ebp
jg     1218 <read_page+0xc8>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     11ba <read_page+0x6a>
cmpb   $0x23,(%rbx)
je     1180 <read_page+0x30>
jmp    11bd <read_page+0x6d>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     1180 <read_page+0x30>
mov    %eax,%r13d
movslq %ebp,%rbp
mov    $0x1,%r14d
mov    %rbx,%r12
nopl   0x0(%rax)
cmp    $0x100,%rbp
je     120e <read_page+0xbe>
mov    %r12,%rdi
call   1050 <fromhex@plt>
mov    (%rsp),%rcx
mov    %al,(%rcx,%rbp,1)
add    $0x1,%rbp
add    $0x2,%r12
add    $0x2,%r14d
cmp    %r13d,%r14d
jl     11e0 <read_page+0x90>
jmp    1180 <read_page+0x30>
mov    $0xffffffff,%ebp
jmp    1180 <read_page+0x30>
xor    %eax,%eax
cmp    $0x100,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_page(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %9
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i32 0, i32 256)
br label %12
12: ; preds = %66, %37, %3
%13 = load i32*, i32** %4
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 256
br label %19
19: ; preds = %16, %12
%20 = phi i1 [ false, %12 ], [ %18, %16 ]
br i1 %20, label %21, label %67
21: ; preds = %19
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 0, i8* %23
%24 = load i8*, i8** %5
%25 = load i32*, i32** %4
%26 = call i32 @fgets(i8* %24, i32 512, i32* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 0, i8* %30
br label %31
31: ; preds = %28, %21
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 35
br i1 %36, label %37, label %38
37: ; preds = %31
br label %12
38: ; preds = %31
%39 = load i8*, i8** %5
%40 = call i32 @strlen(i8* %39)
store i32 %40, i32* %8
store i32 0, i32* %7
br label %41
41: ; preds = %63, %38
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %66
46: ; preds = %41
%47 = load i32, i32* %9
%48 = icmp slt i32 %47, 256
br i1 %48, label %49, label %61
49: ; preds = %46
%50 = load i8*, i8** %5
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = call i64 @fromhex(i8* %53)
%55 = trunc i64 %54 to i8
%56 = load i8*, i8** %6
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 %55, i8* %60
br label %62
61: ; preds = %46
store i32 -1, i32* %9
br label %66
62: ; preds = %49
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 2
store i32 %65, i32* %7
br label %41
66: ; preds = %61, %41
br label %12
67: ; preds = %19
%68 = load i32, i32* %9
%69 = icmp eq i32 %68, 256
%70 = zext i1 %69 to i32
ret i32 %70
}

LLVM IR (-O2):
define i32 @read_page(i32* nocapture %0, i8* %1, i8* %2) {
%4 = tail call i32 @memset(i8* %2, i32 0, i32 256)
br label %5
5: ; preds = %41, %3
%6 = phi i32 [ 0, %3 ], [ %42, %41 ]
%7 = icmp slt i32 %6, 256
br label %8
8: ; preds = %5, %20
br label %9
9: ; preds = %8, %17
%10 = tail call i32 @feof(i32* %0)
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i1 %7, i1 false
br i1 %12, label %13, label %43
13: ; preds = %9
store i8 0, i8* %1
%14 = tail call i32 @fgets(i8* %1, i32 512, i32* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i8 0, i8* %1
br label %20
17: ; preds = %13
%18 = load i8, i8* %1
%19 = icmp eq i8 %18, 35
br i1 %19, label %9, label %20
20: ; preds = %17, %16
%21 = tail call i32 @strlen(i8* %1)
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %8
23: ; preds = %20
%24 = sext i32 %6 to i64
br label %25
25: ; preds = %23, %29
%26 = phi i64 [ 0, %23 ], [ %35, %29 ]
%27 = phi i64 [ %24, %23 ], [ %33, %29 ]
%28 = icmp eq i64 %27, 256
br i1 %28, label %41, label %29
29: ; preds = %25
%30 = getelementptr inbounds i8, i8* %1, i64 %26
%31 = tail call i64 @fromhex(i8* %30)
%32 = trunc i64 %31 to i8
%33 = add nsw i64 %27, 1
%34 = getelementptr inbounds i8, i8* %2, i64 %27
store i8 %32, i8* %34
%35 = add nuw nsw i64 %26, 2
%36 = trunc i64 %35 to i32
%37 = or i32 %36, 1
%38 = icmp slt i32 %37, %21
br i1 %38, label %25, label %39
39: ; preds = %29
%40 = trunc i64 %33 to i32
br label %41
41: ; preds = %25, %39
%42 = phi i32 [ %40, %39 ], [ -1, %25 ]
br label %5
43: ; preds = %9
%44 = icmp eq i32 %6, 256
%45 = zext i1 %44 to i32
ret i32 %45
}