#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
scalar_t__ isdigit(char);
int /*<<< orphan*/ skip_spaces(char **);
int /*<<< orphan*/ stdout;
int read_int(char **token) {
  int value = 0;
  int neg = 0;
  skip_spaces(token);
  if (**token == '-') {
    neg = 1;
    (*token)++;
  } else if (**token == '+')
    (*token)++;
  if (!isdigit(**token)) {
    fprintf(stdout, "Parsing error. Unexpected char: %c.\n", **token);
    exit(EXIT_FAILURE);
  }
  while (isdigit(**token)) {
    value = (value * 10) + (**token - '0');
    (*token)++;
  }
  return neg ? -value : value;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <skip_spaces@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1190 <read_int+0x50>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11b6 <read_int+0x76>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11b1 <read_int+0x71>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11b6 <read_int+0x76>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11fc <read_int+0xbc>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
lea    0xe1a(%rip),%rsi
movsbl (%rax),%edx
call   1040 <fprintf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1201 <read_int+0xc1>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1243 <read_int+0x103>
imul   $0xa,-0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1201 <read_int+0xc1>
cmpl   $0x0,-0x10(%rbp)
je     125a <read_int+0x11a>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1260 <read_int+0x120>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <skip_spaces@plt>
mov    (%rbx),%rax
mov    (%rax),%cl
cmp    $0x2d,%cl
je     1163 <read_int+0x23>
mov    $0x1,%r14b
cmp    $0x2b,%cl
jne    116d <read_int+0x2d>
mov    $0x1,%r14b
jmp    1166 <read_int+0x26>
xor    %r14d,%r14d
add    $0x1,%rax
mov    %rax,(%rbx)
movsbl (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11c4 <read_int+0x84>
mov    (%rbx),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b5 <read_int+0x75>
nopl   0x0(%rax)
lea    0x0(%rbp,%rbp,4),%eax
mov    (%rbx),%rcx
movsbl (%rcx),%edx
lea    (%rdx,%rax,2),%ebp
add    $0xffffffd0,%ebp
lea    0x1(%rcx),%rax
mov    %rax,(%rbx)
movsbl 0x1(%rcx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1190 <read_int+0x50>
mov    %ebp,%eax
neg    %eax
test   %r14b,%r14b
cmovne %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rax
movsbl (%rax),%edx
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [37 x i8] c"Parsing error. Unexpected char: %c.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @read_int(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = load i8**, i8*** %2
%6 = call i32 @skip_spaces(i8** %5)
%7 = load i8**, i8*** %2
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 45
br i1 %11, label %12, label %16
12: ; preds = %1
store i32 1, i32* %4
%13 = load i8**, i8*** %2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %13
br label %27
16: ; preds = %1
%17 = load i8**, i8*** %2
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 43
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i8**, i8*** %2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %23
br label %26
26: ; preds = %22, %16
br label %27
27: ; preds = %26, %12
%28 = load i8**, i8*** %2
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
%31 = call i64 @isdigit(i8 signext %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %27
%34 = load i32, i32* @stdout
%35 = load i8**, i8*** %2
%36 = load i8*, i8** %35
%37 = load i8, i8* %36
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8 signext %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %27
br label %42
42: ; preds = %48, %41
%43 = load i8**, i8*** %2
%44 = load i8*, i8** %43
%45 = load i8, i8* %44
%46 = call i64 @isdigit(i8 signext %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %42
%49 = load i32, i32* %3
%50 = mul nsw i32 %49, 10
%51 = load i8**, i8*** %2
%52 = load i8*, i8** %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = sub nsw i32 %54, 48
%56 = add nsw i32 %50, %55
store i32 %56, i32* %3
%57 = load i8**, i8*** %2
%58 = load i8*, i8** %57
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %57
br label %42
60: ; preds = %42
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i32, i32* %3
%65 = sub nsw i32 0, %64
br label %68
66: ; preds = %60
%67 = load i32, i32* %3
br label %68
68: ; preds = %66, %63
%69 = phi i32 [ %65, %63 ], [ %67, %66 ]
ret i32 %69
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [37 x i8] c"Parsing error. Unexpected char: %c.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @read_int(i8** %0) {
%2 = tail call i32 @skip_spaces(i8** %0)
%3 = load i8*, i8** %0
%4 = load i8, i8* %3
switch i8 %4, label %9 [
i8 45, label %6
i8 43, label %5
]
5: ; preds = %1
br label %6
6: ; preds = %1, %5
%7 = phi i1 [ true, %5 ], [ false, %1 ]
%8 = getelementptr inbounds i8, i8* %3, i64 1
store i8* %8, i8** %0
br label %9
9: ; preds = %6, %1
%10 = phi i8* [ %3, %1 ], [ %8, %6 ]
%11 = phi i1 [ true, %1 ], [ %7, %6 ]
%12 = load i8, i8* %10
%13 = tail call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %9
%16 = load i8*, i8** %0
%17 = load i8, i8* %16
%18 = tail call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %39, label %27
20: ; preds = %9
%21 = load i32, i32* @stdout
%22 = load i8*, i8** %0
%23 = load i8, i8* %22
%24 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8 signext %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %15, %27
%28 = phi i32 [ %34, %27 ], [ 0, %15 ]
%29 = mul nsw i32 %28, 10
%30 = load i8*, i8** %0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = add i32 %29, -48
%34 = add i32 %33, %32
%35 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %35, i8** %0
%36 = load i8, i8* %35
%37 = tail call i64 @isdigit(i8 signext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %27
39: ; preds = %27, %15
%40 = phi i32 [ 0, %15 ], [ %34, %27 ]
%41 = sub nsw i32 0, %40
%42 = select i1 %11, i32 %40, i32 %41
ret i32 %42
}