#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 */
struct nb_reader {
  int dummy;
};

/* Variables and functions */
scalar_t__ isdigit(int);
int nb_reader_getc(struct nb_reader *);
int nb_reader_parse_int(struct nb_reader *I, int *x, int *c) {
  int sgn = 0, r = 0;
  *c = nb_reader_getc(I);
  if (*c == '-') {
    sgn = 1;
    *c = nb_reader_getc(I);
  }
  if (*c < 0 || !isdigit(*c)) {
    return 0;
  }
  do {
    if (r > 0x7fffffff / 10) {
      return 0;
    }
    r = r * 10 + (*c - '0');
    if (r < 0) {
      return 0;
    }
    *c = nb_reader_getc(I);
  } while (*c >= 0 && isdigit(*c));
  if (sgn) {
    r = -r;
  }
  *x = r;
  return 1;
}


x86 assembly (clang, -O0):
<nb_reader_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <nb_reader_getc@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x2d,(%rax)
jne    1178 <nb_reader_parse_int+0x58>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <nb_reader_getc@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jl     119a <nb_reader_parse_int+0x7a>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11a6 <nb_reader_parse_int+0x86>
movl   $0x0,-0x4(%rbp)
jmp    1251 <nb_reader_parse_int+0x131>
jmp    11ab <nb_reader_parse_int+0x8b>
cmpl   $0xccccccc,-0x28(%rbp)
jle    11c4 <nb_reader_parse_int+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    1251 <nb_reader_parse_int+0x131>
imul   $0xa,-0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11ec <nb_reader_parse_int+0xcc>
movl   $0x0,-0x4(%rbp)
jmp    1251 <nb_reader_parse_int+0x131>
mov    -0x10(%rbp),%rdi
call   1040 <nb_reader_getc@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,(%rcx)
mov    %al,-0x29(%rbp)
jl     1224 <nb_reader_parse_int+0x104>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11ab <nb_reader_parse_int+0x8b>
cmpl   $0x0,-0x24(%rbp)
je     1241 <nb_reader_parse_int+0x121>
xor    %eax,%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nb_reader_parse_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <nb_reader_getc@plt>
mov    %eax,%r13d
mov    %eax,(%rbx)
mov    %eax,%edi
cmp    $0x2d,%eax
jne    1151 <nb_reader_parse_int+0x31>
mov    %r15,%rdi
call   1040 <nb_reader_getc@plt>
mov    %eax,%edi
mov    %eax,(%rbx)
xor    %r12d,%r12d
test   %edi,%edi
js     11b3 <nb_reader_parse_int+0x93>
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b3 <nb_reader_parse_int+0x93>
xor    %r12d,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmp    $0xccccccc,%ebp
jg     11b3 <nb_reader_parse_int+0x93>
lea    0x0(%rbp,%rbp,4),%ebp
add    %ebp,%ebp
add    (%rbx),%ebp
add    $0xffffffd0,%ebp
js     11b3 <nb_reader_parse_int+0x93>
mov    %r15,%rdi
call   1040 <nb_reader_getc@plt>
mov    %eax,(%rbx)
test   %eax,%eax
js     119f <nb_reader_parse_int+0x7f>
mov    %eax,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <nb_reader_parse_int+0x50>
mov    %ebp,%eax
neg    %eax
cmp    $0x2d,%r13d
cmovne %ebp,%eax
mov    %eax,(%r14)
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.nb_reader = type { i32 }
define i32 @nb_reader_parse_int(%struct.nb_reader* %0, i32* nocapture writeonly %1, i32* nocapture %2) {
%4 = tail call i32 @nb_reader_getc(%struct.nb_reader* %0)
store i32 %4, i32* %2
%5 = icmp eq i32 %4, 45
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @nb_reader_getc(%struct.nb_reader* %0)
store i32 %7, i32* %2
br label %8
8: ; preds = %6, %3
%9 = phi i32 [ %7, %6 ], [ %4, %3 ]
%10 = icmp slt i32 %9, 0
br i1 %10, label %32, label %11
11: ; preds = %8
%12 = tail call i64 @isdigit(i32 %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %32, label %14
14: ; preds = %11, %26
%15 = phi i32 [ %21, %26 ], [ 0, %11 ]
%16 = icmp sgt i32 %15, 214748364
br i1 %16, label %32, label %17
17: ; preds = %14
%18 = mul nsw i32 %15, 10
%19 = load i32, i32* %2
%20 = add i32 %18, -48
%21 = add i32 %20, %19
%22 = icmp slt i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %17
%24 = tail call i32 @nb_reader_getc(%struct.nb_reader* %0)
store i32 %24, i32* %2
%25 = icmp sgt i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i64 @isdigit(i32 %24)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %14
29: ; preds = %23, %26
%30 = sub nsw i32 0, %21
%31 = select i1 %5, i32 %30, i32 %21
store i32 %31, i32* %1
br label %32
32: ; preds = %17, %14, %8, %11, %29
%33 = phi i32 [ 1, %29 ], [ 0, %11 ], [ 0, %8 ], [ 0, %14 ], [ 0, %17 ]
ret i32 %33
}