#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 *parse_version_number(const char *s, int *number) {
  int val = 0;
  if (*s == '0' && isdigit(s[1]))
    return NULL;
  for (; isdigit(*s); s++) {
    val *= 10;
    val += *s - '0';
  }
  *number = val;
  return val < 0 ? NULL : s;
}


x86 assembly (clang, -O0):
<parse_version_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    115b <parse_version_number+0x4b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     115b <parse_version_number+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11cc <parse_version_number+0xbc>
jmp    1160 <parse_version_number+0x50>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     119e <parse_version_number+0x8e>
imul   $0xa,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1160 <parse_version_number+0x50>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x1c(%rbp)
jge    11bc <parse_version_number+0xac>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11c4 <parse_version_number+0xb4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_version_number>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x30,%al
jne    1135 <parse_version_number+0x25>
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1133 <parse_version_number+0x23>
xor    %ebx,%ebx
jmp    1186 <parse_version_number+0x76>
mov    (%rbx),%al
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     117f <parse_version_number+0x6f>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
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    1150 <parse_version_number+0x40>
mov    %r15d,(%r14)
xor    %eax,%eax
test   %r15d,%r15d
cmovs  %rax,%rbx
jmp    1186 <parse_version_number+0x76>
movl   $0x0,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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