#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);
const char *_parsenum(const char *s, int *num) {
  int n = 0;
  while (isdigit(*s)) {
    n = n * 10 + *s++ - '0';
    *num = n;
  }
  return s;
}


x86 assembly (clang, -O0):
<_parsenum>:
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     1169 <_parsenum+0x59>
imul   $0xa,-0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1127 <_parsenum+0x17>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parsenum>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1159 <_parsenum+0x49>
xor    %r12d,%r12d
xchg   %ax,%ax
lea    (%r12,%r12,4),%eax
lea    0x1(%rbx),%r15
movsbl (%rbx),%ecx
lea    (%rcx,%rax,2),%r12d
add    $0xffffffd0,%r12d
mov    %r12d,(%r14)
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
mov    %r15,%rbx
test   %rax,%rax
jne    1130 <_parsenum+0x20>
jmp    115c <_parsenum+0x4c>
mov    %rbx,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @_parsenum(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %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 %22
11: ; preds = %6
%12 = load i32, i32* %5
%13 = mul nsw i32 %12, 10
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = add nsw i32 %13, %17
%19 = sub nsw i32 %18, 48
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32*, i32** %4
store i32 %20, i32* %21
br label %6
22: ; preds = %6
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
define i8* @_parsenum(i8* %0, i32* 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 [ %14, %6 ], [ 0, %2 ]
%8 = phi i8* [ %10, %6 ], [ %0, %2 ]
%9 = mul nsw i32 %7, 10
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = load i8, i8* %8
%12 = sext i8 %11 to i32
%13 = add i32 %9, -48
%14 = add i32 %13, %12
store i32 %14, i32* %1
%15 = load i8, i8* %10
%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 ], [ %10, %6 ]
ret i8* %19
}