#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);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int readentry(FILE *fp, int format, int depth) {
  int ch, i = 0;
  if (format == '3') {
    while ((ch = getc(fp)) == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
      ;
    if (ch < '0' || ch > '9') {
    error:
      fprintf(stderr, "Format error in input file\n");
      exit(1);
    }
    for (; ch >= '0' && ch <= '9'; ch = getc(fp))
      i = 10 * i + ch - '0';
  } else {
    if ((i = getc(fp)) > depth || i < 0)
      goto error;
  }
  return ((i * 256) / (depth + 1));
}


x86 assembly (clang, -O0):
<readentry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x33,-0xc(%rbp)
jne    123a <readentry+0x10a>
jmp    1158 <readentry+0x28>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
je     119c <readentry+0x6c>
mov    $0x1,%al
cmpl   $0x9,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     119c <readentry+0x6c>
mov    $0x1,%al
cmpl   $0xd,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     119c <readentry+0x6c>
cmpl   $0xa,-0x14(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ac <readentry+0x7c>
jmp    11b1 <readentry+0x81>
jmp    1158 <readentry+0x28>
cmpl   $0x30,-0x14(%rbp)
jl     11c5 <readentry+0x95>
cmpl   $0x39,-0x14(%rbp)
jle    11e9 <readentry+0xb9>
jmp    11ca <readentry+0x9a>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11ee <readentry+0xbe>
xor    %eax,%eax
cmpl   $0x30,-0x14(%rbp)
mov    %al,-0x1a(%rbp)
jl     1207 <readentry+0xd7>
cmpl   $0x39,-0x14(%rbp)
setle  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    1217 <readentry+0xe7>
jmp    1235 <readentry+0x105>
imul   $0xa,-0x18(%rbp),%eax
add    -0x14(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
jmp    11ee <readentry+0xbe>
jmp    1263 <readentry+0x133>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x18(%rbp)
cmp    -0x10(%rbp),%eax
jg     1259 <readentry+0x129>
cmpl   $0x0,-0x18(%rbp)
jge    125e <readentry+0x12e>
jmp    11ca <readentry+0x9a>
jmp    1263 <readentry+0x133>
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readentry>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbx
cmp    $0x33,%esi
jne    118e <readentry+0x5e>
movabs $0x100002600,%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    $0x20,%eax
ja     1165 <readentry+0x35>
mov    %eax,%ecx
bt     %rcx,%rbp
jb     1150 <readentry+0x20>
lea    -0x3a(%rax),%ecx
cmp    $0xfffffff6,%ecx
jb     11b3 <readentry+0x83>
xor    %ebp,%ebp
nop
lea    0x0(%rbp,%rbp,4),%ecx
lea    (%rax,%rcx,2),%ebp
add    $0xffffffd0,%ebp
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    %eax,%ecx
add    $0xffffffd0,%ecx
cmp    $0xa,%ecx
jb     1170 <readentry+0x40>
jmp    11a1 <readentry+0x71>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    %r14d,%eax
jg     11b3 <readentry+0x83>
mov    %eax,%ebp
test   %eax,%eax
js     11b3 <readentry+0x83>
shl    $0x8,%ebp
add    $0x1,%r14d
mov    %ebp,%eax
cltd
idiv   %r14d
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Format error in input file\0A\00"
define i32 @readentry(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 51
br i1 %10, label %11, label %58
11: ; preds = %3
br label %12
12: ; preds = %27, %11
%13 = load i32*, i32** %4
%14 = call i32 @getc(i32* %13)
store i32 %14, i32* %7
%15 = icmp eq i32 %14, 32
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 9
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 13
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 10
br label %25
25: ; preds = %22, %19, %16, %12
%26 = phi i1 [ true, %19 ], [ true, %16 ], [ true, %12 ], [ %24, %22 ]
br i1 %26, label %27, label %28
27: ; preds = %25
br label %12
28: ; preds = %25
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 48
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* %7
%33 = icmp sgt i32 %32, 57
br i1 %33, label %34, label %39
34: ; preds = %31, %28
br label %35
35: ; preds = %66, %34
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
br label %40
40: ; preds = %54, %39
%41 = load i32, i32* %7
%42 = icmp sge i32 %41, 48
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %7
%45 = icmp sle i32 %44, 57
br label %46
46: ; preds = %43, %40
%47 = phi i1 [ false, %40 ], [ %45, %43 ]
br i1 %47, label %48, label %57
48: ; preds = %46
%49 = load i32, i32* %8
%50 = mul nsw i32 10, %49
%51 = load i32, i32* %7
%52 = add nsw i32 %50, %51
%53 = sub nsw i32 %52, 48
store i32 %53, i32* %8
br label %54
54: ; preds = %48
%55 = load i32*, i32** %4
%56 = call i32 @getc(i32* %55)
store i32 %56, i32* %7
br label %40
57: ; preds = %46
br label %68
58: ; preds = %3
%59 = load i32*, i32** %4
%60 = call i32 @getc(i32* %59)
store i32 %60, i32* %8
%61 = load i32, i32* %6
%62 = icmp sgt i32 %60, %61
br i1 %62, label %66, label %63
63: ; preds = %58
%64 = load i32, i32* %8
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %63, %58
br label %35
67: ; preds = %63
br label %68
68: ; preds = %67, %57
%69 = load i32, i32* %8
%70 = mul nsw i32 %69, 256
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
%73 = sdiv i32 %70, %72
ret i32 %73
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Format error in input file\0A\00"
define i32 @readentry(i32* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 51
br i1 %4, label %5, label %24
5: ; preds = %3, %7
%6 = tail call i32 @getc(i32* %0)
switch i32 %6, label %8 [
i32 32, label %7
i32 13, label %7
i32 10, label %7
i32 9, label %7
]
7: ; preds = %5, %5, %5, %5
br label %5
8: ; preds = %5
%9 = add i32 %6, -58
%10 = icmp ult i32 %9, -10
br i1 %10, label %11, label %15
11: ; preds = %24, %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8, %15
%16 = phi i32 [ %20, %15 ], [ 0, %8 ]
%17 = phi i32 [ %21, %15 ], [ %6, %8 ]
%18 = mul nsw i32 %16, 10
%19 = add nsw i32 %17, -48
%20 = add i32 %19, %18
%21 = tail call i32 @getc(i32* %0)
%22 = add i32 %21, -48
%23 = icmp ult i32 %22, 10
br i1 %23, label %15, label %29
24: ; preds = %3
%25 = tail call i32 @getc(i32* %0)
%26 = icmp sgt i32 %25, %2
%27 = icmp slt i32 %25, 0
%28 = or i1 %26, %27
br i1 %28, label %11, label %29
29: ; preds = %15, %24
%30 = phi i32 [ %25, %24 ], [ %20, %15 ]
%31 = shl nsw i32 %30, 8
%32 = add nsw i32 %2, 1
%33 = sdiv i32 %31, %32
ret i32 %33
}