#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 EOF;
int /*<<< orphan*/ exit(int);
int getchar();
int /*<<< orphan*/ printf(char *);
int __getnextint() {
  int ch;
  int result = 0;
  int seen_any_digits = 0;
  while (1) {
    ch = getchar();
    if (ch == EOF) {
      printf("EOF received. Halite engine quit?\n");
      exit(1);
    }
    if (ch >= 48 && ch <= 57) {
      seen_any_digits = 1;
      result *= 10;
      result += ch - 48;
    } else {
      if (seen_any_digits) {
        return result;
      }
    }
  }
  return 54321;
}


x86 assembly (clang, -O0):
<__getnextint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
jne    1178 <__getnextint+0x48>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x30,-0x4(%rbp)
jl     11ab <__getnextint+0x7b>
cmpl   $0x39,-0x4(%rbp)
jg     11ab <__getnextint+0x7b>
movl   $0x1,-0xc(%rbp)
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x30,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11c3 <__getnextint+0x93>
cmpl   $0x0,-0xc(%rbp)
je     11be <__getnextint+0x8e>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    11c3 <__getnextint+0x93>
jmp    1146 <__getnextint+0x16>

x86 assembly (clang, -O2):
<__getnextint>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2ea6(%rip),%r14
cmp    (%r14),%eax
je     117e <__getnextint+0x4e>
xor    %ecx,%ecx
xor    %ebx,%ebx
jmp    1169 <__getnextint+0x39>
nopl   (%rax)
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
mov    $0x1,%ebp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %ebp,%ecx
cmp    (%r14),%eax
je     117e <__getnextint+0x4e>
add    $0xffffffd0,%eax
cmp    $0x9,%eax
jbe    1150 <__getnextint+0x20>
xor    %ebp,%ebp
test   %ecx,%ecx
je     115b <__getnextint+0x2b>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [35 x i8] c"EOF received. Halite engine quit?\0A\00"
define i32 @__getnextint() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %0, %31
%5 = call i32 (...) @getchar()
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = load i32, i32* %1
%14 = icmp sge i32 %13, 48
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* %1
%17 = icmp sle i32 %16, 57
br i1 %17, label %18, label %25
18: ; preds = %15
store i32 1, i32* %3
%19 = load i32, i32* %2
%20 = mul nsw i32 %19, 10
store i32 %20, i32* %2
%21 = load i32, i32* %1
%22 = sub nsw i32 %21, 48
%23 = load i32, i32* %2
%24 = add nsw i32 %23, %22
store i32 %24, i32* %2
br label %31
25: ; preds = %15, %12
%26 = load i32, i32* %3
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* %2
ret i32 %29
30: ; preds = %25
br label %31
31: ; preds = %30, %18
br label %4
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [34 x i8] c"EOF received. Halite engine quit?\00"
define i32 @__getnextint() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %4, label %7
4: ; preds = %19, %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0, %19
%8 = phi i32 [ %22, %19 ], [ %1, %0 ]
%9 = phi i32 [ %21, %19 ], [ 0, %0 ]
%10 = phi i32 [ %20, %19 ], [ 0, %0 ]
%11 = add i32 %8, -48
%12 = icmp ult i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = mul nsw i32 %10, 10
%15 = add nsw i32 %11, %14
br label %19
16: ; preds = %7
%17 = icmp eq i32 %9, 0
br i1 %17, label %19, label %18
18: ; preds = %16
ret i32 %10
19: ; preds = %16, %13
%20 = phi i32 [ %15, %13 ], [ %10, %16 ]
%21 = phi i32 [ 1, %13 ], [ 0, %16 ]
%22 = tail call i32 (...) @getchar()
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %4, label %7
}