#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__ strcmp(char const *, char *);
scalar_t__ strlen(char const *);
unsigned long strtoul(char const *, char **, int /*<<< orphan*/);
bool check_parse_ulong(const char *number, unsigned long *result) {
  char *endptr;
  if (strlen(number) == 0)
    return false;
  if (strcmp(number, "(nil)") == 0 || strcmp(number, "(null)") == 0) {
    *result = 0;
    return true;
  }
  *result = strtoul(number, &endptr, 0);
  return *endptr == '\0';
}


x86 assembly (clang, -O0):
<check_parse_ulong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    115f <check_parse_ulong+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <check_parse_ulong+0xa8>
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1193 <check_parse_ulong+0x63>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11aa <check_parse_ulong+0x7a>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11d8 <check_parse_ulong+0xa8>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_parse_ulong>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1172 <check_parse_ulong+0x52>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeca(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1176 <check_parse_ulong+0x56>
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1176 <check_parse_ulong+0x56>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,(%r14)
mov    (%rsp),%rcx
xor    %eax,%eax
cmpb   $0x0,(%rcx)
sete   %al
jmp    1182 <check_parse_ulong+0x62>
xor    %eax,%eax
jmp    1182 <check_parse_ulong+0x62>
movq   $0x0,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"(nil)\00"
@.str.1 = [7 x i8] c"(null)\00"
define i32 @check_parse_ulong(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %30
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15, %11
%20 = load i64*, i64** %5
store i64 0, i64* %20
store i32 1, i32* %3
br label %30
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = call i64 @strtoul(i8* %22, i8** %6, i32 0)
%24 = load i64*, i64** %5
store i64 %23, i64* %24
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
store i32 %29, i32* %3
br label %30
30: ; preds = %21, %19, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [6 x i8] c"(nil)\00"
@.str.1 = [7 x i8] c"(null)\00"
define i32 @check_parse_ulong(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %7
store i64 0, i64* %1
br label %20
14: ; preds = %10
%15 = call i64 @strtoul(i8* %0, i8** %3, i32 0)
store i64 %15, i64* %1
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %2, %14, %13
%21 = phi i32 [ 1, %13 ], [ %19, %14 ], [ 0, %2 ]
ret i32 %21
}