#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 UINT_MAX;
scalar_t__ errno;
scalar_t__ is_digit(char);
unsigned long strtoul(char *, char **, int);
int is_uint(char *test_int, unsigned int *result) {
  unsigned long int value;
  char *end;
  if (test_int == NULL)
    return (0);
  if (is_digit(test_int[0]) == 0)
    return (0);
  value = strtoul(test_int, &end, 10);
  if ((errno == ERANGE) || (*end != '\0') || (value > UINT_MAX))
    return (0);
  *result = (unsigned int)value;
  return (1);
}


x86 assembly (clang, -O0):
<is_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <is_uint+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11dc <is_uint+0xbc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <is_digit@plt>
cmp    $0x0,%rax
jne    1169 <is_uint+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11dc <is_uint+0xbc>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
je     11bd <is_uint+0x9d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11bd <is_uint+0x9d>
mov    -0x20(%rbp),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
jbe    11c9 <is_uint+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    11dc <is_uint+0xbc>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_uint>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     1188 <is_uint+0x68>
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <is_digit@plt>
test   %rax,%rax
je     1188 <is_uint+0x68>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    0x2e75(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e7b(%rip),%rdx
cmp    (%rdx),%rcx
je     1188 <is_uint+0x68>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1188 <is_uint+0x68>
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
ja     1188 <is_uint+0x68>
mov    %eax,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@UINT_MAX = global i64 0
define i32 @is_uint(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = tail call i64 @is_digit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %24, label %15
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
%19 = load i64, i64* @UINT_MAX
%20 = icmp ugt i64 %11, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = trunc i64 %11 to i32
store i32 %23, i32* %1
br label %24
24: ; preds = %10, %15, %6, %2, %22
%25 = phi i32 [ 1, %22 ], [ 0, %2 ], [ 0, %6 ], [ 0, %15 ], [ 0, %10 ]
ret i32 %25
}