#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 atoi(char *);
scalar_t__ isdigit(char);
void stub1();
int parseint(char **sp, void (*errorfn)(void)) {
  char *s = *sp;
  int num = atoi(s);
  while (isdigit(*s))
    s++;
  if (*sp == s)
    (*errorfn)();
  *sp = s;
  return (num);
}


x86 assembly (clang, -O0):
<parseint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116e <parseint+0x4e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1147 <parseint+0x27>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    1182 <parseint+0x62>
call   *-0x10(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,%ebp
add    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1140 <parseint+0x20>
cmp    (%r14),%rbx
jne    115a <parseint+0x3a>
call   *%r15
mov    %rbx,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parseint(i8** %0, void ()* %1) {
%3 = alloca i8**
%4 = alloca void ()*
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %3
store void ()* %1, void ()** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @atoi(i8* %9)
store i32 %10, i32* %6
br label %11
11: ; preds = %16, %2
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %5
br label %11
19: ; preds = %11
%20 = load i8**, i8*** %3
%21 = load i8*, i8** %20
%22 = load i8*, i8** %5
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = load void ()*, void ()** %4
br label %26
26: ; preds = %24, %19
%27 = load i8*, i8** %5
%28 = load i8**, i8*** %3
store i8* %27, i8** %28
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
define i32 @parseint(i8** nocapture %0, void ()* nocapture %1) {
%3 = load i8*, i8** %0
%4 = tail call i32 @atoi(i8* %3)
br label %5
5: ; preds = %5, %2
%6 = phi i8* [ %3, %2 ], [ %10, %5 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isdigit(i8 signext %7)
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = load i8*, i8** %0
%13 = icmp eq i8* %12, %6
br i1 %13, label %14, label %15
14: ; preds = %11
tail call void %1()
br label %15
15: ; preds = %14, %11
store i8* %6, i8** %0
ret i32 %4
}