#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__ ERANGE;
unsigned long ULONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ isdigit(unsigned char);
unsigned long strtoul(char const *, char **, int);
int parsenum(const char *word, unsigned long *result) {
  unsigned long num;
  char *ep;
  if (!isdigit((unsigned char)word[0]))
    return 0;
  errno = 0;
  num = strtoul(word, &ep, 10);
  if (num == ULONG_MAX && errno == ERANGE)
    return 0;
  if (*ep != '\0')
    return 0;
  *result = num;
  return 1;
}


x86 assembly (clang, -O0):
<parsenum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1151 <parsenum+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11dd <parsenum+0xbd>
mov    0x2e80(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <parsenum+0x8f>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    11af <parsenum+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    11dd <parsenum+0xbd>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cb <parsenum+0xab>
movl   $0x0,-0x4(%rbp)
jmp    11dd <parsenum+0xbd>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsenum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <isdigit@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1185 <parsenum+0x65>
mov    0x2e96(%rip),%r15
movq   $0x0,(%r15)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <parsenum+0x54>
mov    (%r15),%rcx
mov    0x2e79(%rip),%rdx
cmp    (%rdx),%rcx
je     1185 <parsenum+0x65>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1185 <parsenum+0x65>
mov    %rax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ULONG_MAX = global i64 0
@ERANGE = global i64 0
define i32 @parsenum(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = call i32 @isdigit(i8 zeroext %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 0, i32* %3
br label %34
14: ; preds = %2
store i64 0, i64* @errno
%15 = load i8*, i8** %4
%16 = call i64 @strtoul(i8* %15, i8** %7, i32 10)
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = load i64, i64* @ULONG_MAX
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i64, i64* @errno
%22 = load i64, i64* @ERANGE
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %3
br label %34
25: ; preds = %20, %14
%26 = load i8*, i8** %7
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %3
br label %34
31: ; preds = %25
%32 = load i64, i64* %6
%33 = load i64*, i64** %5
store i64 %32, i64* %33
store i32 1, i32* %3
br label %34
34: ; preds = %31, %30, %24, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@errno = global i64 0
@ULONG_MAX = global i64 0
@ERANGE = global i64 0
define i32 @parsenum(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = tail call i32 @isdigit(i8 zeroext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %2
store i64 0, i64* @errno
%9 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%10 = load i64, i64* @ULONG_MAX
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %13, %14
br i1 %15, label %21, label %16
16: ; preds = %12, %8
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i64 %9, i64* %1
br label %21
21: ; preds = %16, %12, %2, %20
%22 = phi i32 [ 1, %20 ], [ 0, %2 ], [ 0, %12 ], [ 0, %16 ]
ret i32 %22
}