#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 */

/* Variables and functions */
int /*<<< orphan*/ die(char *, int);
int next();
int read_header() {
  int c;
  int i;
  int size;
  int size_size;
  if ((c = next()) != '#') {
    die("Format error. Expected '#', got %x", c);
  }
  c = next();
  if (c < '0' || c > '9') {
    die("Format error. Expected length '0' ... '9', got %c", c);
  }
  size_size = c - '0';
  size = 0;
  for (i = 0; i < size_size; i++) {
    c = next();
    if (c < '0' || c > '9') {
      die("Format error. Expected digit '0' ... '9', got %c", c);
    }
    size = (size * 10) + c - '0';
  }
  return size;
}


x86 assembly (clang, -O0):
<read_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <next@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x23,%eax
je     114a <read_header+0x2a>
mov    -0x4(%rbp),%esi
lea    0xebb(%rip),%rdi
call   1040 <die@plt>
mov    $0x0,%al
call   1030 <next@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x30,-0x4(%rbp)
jl     1168 <read_header+0x48>
cmpl   $0x39,-0x4(%rbp)
jle    1177 <read_header+0x57>
mov    -0x4(%rbp),%esi
lea    0xeb1(%rip),%rdi
call   1040 <die@plt>
mov    -0x4(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e2 <read_header+0xc2>
mov    $0x0,%al
call   1030 <next@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x30,-0x4(%rbp)
jl     11b8 <read_header+0x98>
cmpl   $0x39,-0x4(%rbp)
jle    11c7 <read_header+0xa7>
mov    -0x4(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1040 <die@plt>
imul   $0xa,-0xc(%rbp),%eax
add    -0x4(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118e <read_header+0x6e>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_header>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <next@plt>
cmp    $0x23,%eax
je     1142 <read_header+0x22>
lea    0xec5(%rip),%rdi
mov    %eax,%esi
call   1040 <die@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <next@plt>
mov    %eax,%r12d
lea    -0x3a(%r12),%eax
cmp    $0xfffffff5,%eax
ja     1168 <read_header+0x48>
lea    0xec3(%rip),%rdi
mov    %r12d,%esi
call   1040 <die@plt>
cmp    $0x31,%r12d
jl     11af <read_header+0x8f>
add    $0xffffffd0,%r12d
lea    0xedc(%rip),%r15
xor    %r14d,%r14d
jmp    1192 <read_header+0x72>
xchg   %ax,%ax
lea    (%r14,%r14,4),%eax
lea    (%rbx,%rax,2),%r14d
add    $0xffffffd0,%r14d
add    $0xffffffff,%r12d
je     11af <read_header+0x8f>
xor    %eax,%eax
call   1030 <next@plt>
mov    %eax,%ebx
lea    -0x3a(%rbx),%eax
cmp    $0xfffffff5,%eax
ja     1180 <read_header+0x60>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <die@plt>
jmp    1180 <read_header+0x60>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Format error. Expected '#', got %x\00"
@.str.1 = [50 x i8] c"Format error. Expected length '0' ... '9', got %c\00"
@.str.2 = [49 x i8] c"Format error. Expected digit '0' ... '9', got %c\00"
define i32 @read_header() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @next()
store i32 %5, i32* %1
%6 = icmp ne i32 %5, 35
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* %1
%9 = call i32 @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %7, %0
%11 = call i32 (...) @next()
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 48
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, 57
br i1 %16, label %17, label %20
17: ; preds = %14, %10
%18 = load i32, i32* %1
%19 = call i32 @die(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %1
%22 = sub nsw i32 %21, 48
store i32 %22, i32* %4
store i32 0, i32* %3
store i32 0, i32* %2
br label %23
23: ; preds = %43, %20
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %46
27: ; preds = %23
%28 = call i32 (...) @next()
store i32 %28, i32* %1
%29 = load i32, i32* %1
%30 = icmp slt i32 %29, 48
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %1
%33 = icmp sgt i32 %32, 57
br i1 %33, label %34, label %37
34: ; preds = %31, %27
%35 = load i32, i32* %1
%36 = call i32 @die(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %3
%39 = mul nsw i32 %38, 10
%40 = load i32, i32* %1
%41 = add nsw i32 %39, %40
%42 = sub nsw i32 %41, 48
store i32 %42, i32* %3
br label %43
43: ; preds = %37
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %23
46: ; preds = %23
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [35 x i8] c"Format error. Expected '#', got %x\00"
@.str.1 = [50 x i8] c"Format error. Expected length '0' ... '9', got %c\00"
@.str.2 = [49 x i8] c"Format error. Expected digit '0' ... '9', got %c\00"
define i32 @read_header() {
%1 = tail call i32 (...) @next()
%2 = icmp eq i32 %1, 35
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %5
5: ; preds = %3, %0
%6 = tail call i32 (...) @next()
%7 = add i32 %6, -58
%8 = icmp ult i32 %7, -10
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @die(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %11
11: ; preds = %5, %9
%12 = add i32 %6, -48
%13 = icmp sgt i32 %6, 48
br i1 %13, label %14, label %28
14: ; preds = %11, %22
%15 = phi i32 [ %25, %22 ], [ 0, %11 ]
%16 = phi i32 [ %26, %22 ], [ 0, %11 ]
%17 = tail call i32 (...) @next()
%18 = add i32 %17, -58
%19 = icmp ult i32 %18, -10
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @die(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %22
22: ; preds = %14, %20
%23 = mul nsw i32 %15, 10
%24 = add i32 %23, -48
%25 = add i32 %24, %17
%26 = add nuw nsw i32 %16, 1
%27 = icmp eq i32 %26, %12
br i1 %27, label %28, label %14
28: ; preds = %22, %11
%29 = phi i32 [ 0, %11 ], [ %25, %22 ]
ret i32 %29
}