#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 */
scalar_t__ isdigit(char const);
long int __read_string_int(const char *sp, const char **end, long int *val) {
  *val = 0;
  if (!isdigit(*sp))
    return 0;
  do {
    *val *= 10;
    *val += *sp - '0';
    sp++;
  } while (isdigit(*sp));
  *end = sp;
  return 1;
}


x86 assembly (clang, -O0):
<__read_string_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1152 <__read_string_int+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11ae <__read_string_int+0x9e>
jmp    1157 <__read_string_int+0x47>
mov    -0x20(%rbp),%rax
imul   $0xa,(%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
movslq %eax,%rcx
mov    -0x20(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1157 <__read_string_int+0x47>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__read_string_int>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rdx)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1177 <__read_string_int+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%rax
add    %rax,%rax
lea    (%rax,%rax,4),%rax
mov    %rax,(%r15)
movsbq (%rbx),%rcx
add    %rcx,%rax
add    $0xffffffffffffffd0,%rax
mov    %rax,(%r15)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <__read_string_int+0x30>
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    1179 <__read_string_int+0x69>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @__read_string_int(i8* %0, i8** %1, i64* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%8 = load i64*, i64** %7
store i64 0, i64* %8
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = call i64 @isdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %3
store i64 0, i64* %4
br label %37
14: ; preds = %3
br label %15
15: ; preds = %29, %14
%16 = load i64*, i64** %7
%17 = load i64, i64* %16
%18 = mul nsw i64 %17, 10
store i64 %18, i64* %16
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 48
%23 = sext i32 %22 to i64
%24 = load i64*, i64** %7
%25 = load i64, i64* %24
%26 = add nsw i64 %25, %23
store i64 %26, i64* %24
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %29
29: ; preds = %15
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %15, label %34
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = load i8**, i8*** %6
store i8* %35, i8** %36
store i64 1, i64* %4
br label %37
37: ; preds = %34, %13
%38 = load i64, i64* %4
ret i64 %38
}

LLVM IR (-O2):
define i64 @__read_string_int(i8* %0, i8** nocapture writeonly %1, i64* nocapture %2) {
store i64 0, i64* %2
%4 = load i8, i8* %0
%5 = tail call i64 @isdigit(i8 signext %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %15, %7 ], [ %0, %3 ]
%9 = load i64, i64* %2
%10 = mul nsw i64 %9, 10
store i64 %10, i64* %2
%11 = load i8, i8* %8
%12 = sext i8 %11 to i64
%13 = add i64 %10, -48
%14 = add i64 %13, %12
store i64 %14, i64* %2
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = load i8, i8* %15
%17 = tail call i64 @isdigit(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %7
19: ; preds = %7
store i8* %15, i8** %1
br label %20
20: ; preds = %3, %19
%21 = phi i64 [ 1, %19 ], [ 0, %3 ]
ret i64 %21
}