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


x86 assembly (clang, -O0):
<parse_entire_uint>:
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    -0x30(%rbp),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
ja     1184 <parse_entire_uint+0x64>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x20(%rbp),%rcx
cmp    %rcx,%rax
je     118d <parse_entire_uint+0x6d>
movb   $0x0,-0x1(%rbp)
jmp    119d <parse_entire_uint+0x7d>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_entire_uint>:
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>
mov    %rax,%rcx
mov    0x2e90(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
ja     116e <parse_entire_uint+0x4e>
add    %r15,%rbx
cmp    %rbx,0x8(%rsp)
jne    116e <parse_entire_uint+0x4e>
mov    %ecx,(%r14)
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@UINT_MAX = global i64 0
define signext i8 @parse_entire_uint(i8* %0, i32* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %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 i64, i64* %8
%15 = load i64, i64* @UINT_MAX
%16 = icmp ugt i64 %14, %15
br i1 %16, label %23, label %17
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = load i8*, i8** %4
%20 = load i64, i64* %6
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = icmp ne i8* %18, %21
br i1 %22, label %23, label %24
23: ; preds = %17, %2
store i8 0, i8* %3
br label %28
24: ; preds = %17
%25 = load i64, i64* %8
%26 = trunc i64 %25 to i32
%27 = load i32*, i32** %5
store i32 %26, i32* %27
store i8 1, i8* %3
br label %28
28: ; preds = %24, %23
%29 = load i8, i8* %3
ret i8 %29
}

LLVM IR (-O2):
@UINT_MAX = global i64 0
define signext i8 @parse_entire_uint(i8* %0, i32* 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 i64, i64* @UINT_MAX
%8 = icmp ule i64 %6, %7
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %0, i64 %4
%11 = icmp eq i8* %9, %10
%12 = select i1 %8, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = trunc i64 %6 to i32
store i32 %14, i32* %1
br label %15
15: ; preds = %2, %13
%16 = phi i8 [ 1, %13 ], [ 0, %2 ]
ret i8 %16
}