#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 */
size_t strlen(char const *);
unsigned long strtoul(char const *, char **, int);
char parse_entire_ulong(const char *str, unsigned long *result) {
  size_t len = strlen(str);
  char *strtol_last_char_ptr = (char *)str;
  unsigned long tmp = strtoul(str, &strtol_last_char_ptr, 10);
  if (strtol_last_char_ptr == str + len) {
    *result = tmp;
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<parse_entire_ulong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x20(%rbp),%rcx
cmp    %rcx,%rax
jne    1184 <parse_entire_ulong+0x64>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x1,-0x1(%rbp)
jmp    1188 <parse_entire_ulong+0x68>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_entire_ulong>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
add    %rbx,%r15
cmp    %r15,0x8(%rsp)
je     115c <parse_entire_ulong+0x3c>
xor    %eax,%eax
jmp    1161 <parse_entire_ulong+0x41>
mov    %rax,(%r14)
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define signext i8 @parse_entire_ulong(i8* %0, i64* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i8*, i8** %4
store i8* %11, i8** %7
%12 = load i8*, i8** %4
%13 = call i64 @strtoul(i8* %12, i8** %7, i32 10)
store i64 %13, i64* %8
%14 = load i8*, i8** %7
%15 = load i8*, i8** %4
%16 = load i64, i64* %6
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = icmp eq i8* %14, %17
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i64, i64* %8
%21 = load i64*, i64** %5
store i64 %20, i64* %21
store i8 1, i8* %3
br label %23
22: ; preds = %2
store i8 0, i8* %3
br label %23
23: ; preds = %22, %19
%24 = load i8, i8* %3
ret i8 %24
}

LLVM IR (-O2):
define signext i8 @parse_entire_ulong(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%6 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %0, i64 %4
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i64 %6, i64* %1
br label %11
11: ; preds = %2, %10
%12 = phi i8 [ 1, %10 ], [ 0, %2 ]
ret i8 %12
}