#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int /*<<< orphan*/);
int parse_ulong(char const *str) {
  unsigned long value;
  char *end;
  value = strtoul(str, &end, 0);
  if (end && *end) {
    fprintf(stderr, "Invalid event part %s\n", str);
    exit(EXIT_FAILURE);
  }
  return value;
}


x86 assembly (clang, -O0):
<parse_ulong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1191 <parse_ulong+0x61>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1191 <parse_ulong+0x61>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ulong>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    0x8(%rsp),%rcx
test   %rcx,%rcx
je     1153 <parse_ulong+0x23>
cmpb   $0x0,(%rcx)
jne    1159 <parse_ulong+0x29>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Invalid event part %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @parse_ulong(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtoul(i8* %5, i8** %4, i32 0)
store i64 %6, i64* %3
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %9, %1
%21 = load i64, i64* %3
%22 = trunc i64 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Invalid event part %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @parse_ulong(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7, %1
%16 = trunc i64 %4 to i32
ret i32 %16
}