#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);
int str2int(const char *str, const char **p) {
  int r = 0;
  while (isdigit(*str)) {
    r = r * 10 + *str - '0';
    ++str;
  }
  *p = str;
  return r;
}


x86 assembly (clang, -O0):
<str2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1161 <str2int+0x51>
imul   $0xa,-0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <str2int+0x17>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2int>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1151 <str2int+0x41>
nopl   0x0(%rax,%rax,1)
lea    (%r15,%r15,4),%eax
movsbl (%rbx),%ecx
lea    (%rcx,%rax,2),%r15d
add    $0xffffffd0,%r15d
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1130 <str2int+0x20>
mov    %rbx,(%r14)
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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