#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 const UINT_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ str_is_maybe_integer(char const *);
unsigned long strtoul(char const *, char **, int);
bool str_try_parse_as_uint(const char *s, unsigned int *i_handle) {
  assert(s != NULL && i_handle != NULL);
  if (!str_is_maybe_integer(s) || s[0] == '-' || s[0] == '+')
    return false;
  char *end;
  const long unsigned int i = strtoul(s, &end, 10);
  if (*end != '\0')
    return false;
  if (i > UINT_MAX)
    return false;
  *i_handle = i;
  return true;
}


x86 assembly (clang, -O0):
<str_try_parse_as_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
je     115b <str_try_parse_as_uint+0x2b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1050 <str_is_maybe_integer@plt>
cmp    $0x0,%eax
je     119a <str_try_parse_as_uint+0x6a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     119a <str_try_parse_as_uint+0x6a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11a6 <str_try_parse_as_uint+0x76>
movl   $0x0,-0x4(%rbp)
jmp    120b <str_try_parse_as_uint+0xdb>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d8 <str_try_parse_as_uint+0xa8>
movl   $0x0,-0x4(%rbp)
jmp    120b <str_try_parse_as_uint+0xdb>
mov    -0x28(%rbp),%rax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%rax
jbe    11f8 <str_try_parse_as_uint+0xc8>
movl   $0x0,-0x4(%rbp)
jmp    120b <str_try_parse_as_uint+0xdb>
mov    -0x28(%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):
<str_try_parse_as_uint>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1050 <str_is_maybe_integer@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     119b <str_try_parse_as_uint+0x6b>
mov    (%rbx),%cl
cmp    $0x2b,%cl
je     119b <str_try_parse_as_uint+0x6b>
cmp    $0x2d,%cl
je     119b <str_try_parse_as_uint+0x6b>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    (%rsp),%rdx
xor    %eax,%eax
cmpb   $0x0,(%rdx)
jne    119b <str_try_parse_as_uint+0x6b>
test   %rcx,%rcx
jne    119b <str_try_parse_as_uint+0x6b>
movl   $0x0,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@UINT_MAX = constant i64 0
define i32 @str_try_parse_as_uint(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br label %13
13: ; preds = %10, %2
%14 = phi i1 [ false, %2 ], [ %12, %10 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %4
%18 = call i32 @str_is_maybe_integer(i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 45
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 43
br i1 %31, label %32, label %33
32: ; preds = %26, %20, %13
store i32 0, i32* %3
br label %50
33: ; preds = %26
%34 = load i8*, i8** %4
%35 = call i64 @strtoul(i8* %34, i8** %6, i32 10)
store i64 %35, i64* %7
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %33
store i32 0, i32* %3
br label %50
41: ; preds = %33
%42 = load i64, i64* %7
%43 = load i64, i64* @UINT_MAX
%44 = icmp ugt i64 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 0, i32* %3
br label %50
46: ; preds = %41
%47 = load i64, i64* %7
%48 = trunc i64 %47 to i32
%49 = load i32*, i32** %5
store i32 %48, i32* %49
store i32 1, i32* %3
br label %50
50: ; preds = %46, %45, %40, %32
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@UINT_MAX = constant i64 0
define i32 @str_try_parse_as_uint(i8* %0, i32* writeonly %1) {
%3 = alloca i8*
%4 = icmp ne i8* %0, null
%5 = icmp ne i32* %1, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @str_is_maybe_integer(i8* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %2
%12 = load i8, i8* %0
switch i8 %12, label %13 [
i8 45, label %24
i8 43, label %24
]
13: ; preds = %11
%14 = bitcast i8** %3 to i8*
%15 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
%19 = icmp eq i64 %15, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %22
21: ; preds = %13
store i32 0, i32* %1
br label %22
22: ; preds = %13, %21
%23 = phi i32 [ 1, %21 ], [ 0, %13 ]
br label %24
24: ; preds = %2, %11, %11, %22
%25 = phi i32 [ %23, %22 ], [ 0, %11 ], [ 0, %11 ], [ 0, %2 ]
ret i32 %25
}