#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 INT_MAX;
scalar_t__ isdigit(unsigned char const);
int read_int(const unsigned char **pstr) {
  int retval = **pstr - '0';
  while (isdigit(*++(*pstr)))
    if (retval >= 0) {
      if (INT_MAX / 10 < retval)
        retval = -1;
      else {
        int digit = **pstr - '0';
        retval *= 10;
        if (INT_MAX - digit < retval)
          retval = -1;
        else
          retval += digit;
      }
    }
  return retval;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d0 <read_int+0xc0>
cmpl   $0x0,-0xc(%rbp)
jl     11cb <read_int+0xbb>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    -0xc(%rbp),%eax
jge    1180 <read_int+0x70>
movl   $0xffffffff,-0xc(%rbp)
jmp    11c6 <read_int+0xb6>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
sub    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <read_int+0xa8>
movl   $0xffffffff,-0xc(%rbp)
jmp    11c1 <read_int+0xb1>
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <read_int+0xb6>
jmp    11cb <read_int+0xbb>
jmp    112c <read_int+0x1c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
mov    (%rdi),%rax
movzbl (%rax),%ebx
add    $0xffffffd0,%ebx
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11af <read_int+0x9f>
mov    0x2ea8(%rip),%r14
mov    $0xffffffff,%r15d
jmp    116e <read_int+0x5e>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%ebp
mov    (%r12),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r12)
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
mov    %ebp,%ebx
test   %rax,%rax
je     11b1 <read_int+0xa1>
test   %ebx,%ebx
js     1150 <read_int+0x40>
movslq (%r14),%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
mov    $0xffffffff,%ebp
cmp    %ebx,%ecx
jl     1152 <read_int+0x42>
mov    (%r12),%rcx
movzbl (%rcx),%ecx
lea    -0x30(%rcx),%edx
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%esi
sub    %edx,%eax
cmp    %esi,%eax
lea    -0x30(%rcx,%rsi,1),%ebp
cmovl  %r15d,%ebp
jmp    1152 <read_int+0x42>
mov    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @read_int(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
store i8** %0, i8*** %2
%5 = load i8**, i8*** %2
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = sub nsw i32 %8, 48
store i32 %9, i32* %3
br label %10
10: ; preds = %46, %1
%11 = load i8**, i8*** %2
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %11
%14 = load i8, i8* %13
%15 = call i64 @isdigit(i8 zeroext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %47
17: ; preds = %10
%18 = load i32, i32* %3
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %17
%21 = load i32, i32* @INT_MAX
%22 = sdiv i32 %21, 10
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %3
br label %45
26: ; preds = %20
%27 = load i8**, i8*** %2
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = sub nsw i32 %30, 48
store i32 %31, i32* %4
%32 = load i32, i32* %3
%33 = mul nsw i32 %32, 10
store i32 %33, i32* %3
%34 = load i32, i32* @INT_MAX
%35 = load i32, i32* %4
%36 = sub nsw i32 %34, %35
%37 = load i32, i32* %3
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %26
store i32 -1, i32* %3
br label %44
40: ; preds = %26
%41 = load i32, i32* %4
%42 = load i32, i32* %3
%43 = add nsw i32 %42, %41
store i32 %43, i32* %3
br label %44
44: ; preds = %40, %39
br label %45
45: ; preds = %44, %25
br label %46
46: ; preds = %45, %17
br label %10
47: ; preds = %10
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @read_int(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = zext i8 %3 to i32
%5 = add nsw i32 %4, -48
%6 = getelementptr inbounds i8, i8* %2, i64 1
store i8* %6, i8** %0
%7 = load i8, i8* %6
%8 = tail call i64 @isdigit(i8 zeroext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %34, label %10
10: ; preds = %1, %27
%11 = phi i32 [ %28, %27 ], [ %5, %1 ]
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load i32, i32* @INT_MAX
%15 = sdiv i32 %14, 10
%16 = icmp slt i32 %15, %11
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = load i8*, i8** %0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = add nsw i32 %20, -48
%22 = mul nsw i32 %11, 10
%23 = sub nsw i32 %14, %21
%24 = icmp slt i32 %23, %22
%25 = add nsw i32 %21, %22
%26 = select i1 %24, i32 -1, i32 %25
br label %27
27: ; preds = %13, %17, %10
%28 = phi i32 [ %26, %17 ], [ %11, %10 ], [ -1, %13 ]
%29 = load i8*, i8** %0
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %0
%31 = load i8, i8* %30
%32 = tail call i64 @isdigit(i8 zeroext %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %10
34: ; preds = %27, %1
%35 = phi i32 [ %5, %1 ], [ %28, %27 ]
ret i32 %35
}