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


x86 assembly (clang, -O0):
<match_unsigned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <match_unsigned+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11bf <match_unsigned+0xaf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    115b <match_unsigned+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11bf <match_unsigned+0xaf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%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
je     11b7 <match_unsigned+0xa7>
mov    -0x18(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    %eax,%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1177 <match_unsigned+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_unsigned>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1166 <match_unsigned+0x56>
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1166 <match_unsigned+0x56>
movsbl (%rbx),%eax
add    $0xffffffd0,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,(%r14)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
je     1168 <match_unsigned+0x58>
mov    (%r14),%eax
lea    (%rax,%rax,4),%eax
movsbl (%rbx),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
jmp    1140 <match_unsigned+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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