#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*/ re_match(char const *, char *);
unsigned long strtoul(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int validate_u32(const char *str) {
  if (!str)
    return 0;
  if (!re_match(str, "^[0-9]+$"))
    return 0;
  unsigned long int val = strtoul(str, NULL, 0);
  unsigned long int max = 4294967296;
  if (val > max)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<validate_u32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <validate_u32+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11aa <validate_u32+0x8a>
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <re_match@plt>
cmp    $0x0,%eax
jne    1168 <validate_u32+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11aa <validate_u32+0x8a>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
movabs $0x100000000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11a3 <validate_u32+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11aa <validate_u32+0x8a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_u32>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     115c <validate_u32+0x3c>
mov    %rdi,%rbx
lea    0xecc(%rip),%rsi
call   1030 <re_match@plt>
test   %eax,%eax
je     115c <validate_u32+0x3c>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
movabs $0x100000001,%rcx
xor    %ebp,%ebp
cmp    %rcx,%rax
setb   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"^[0-9]+$\00"
define i32 @validate_u32(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 0, i32* %2
br label %22
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @re_match(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 0, i32* %2
br label %22
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @strtoul(i8* %15, i32* null, i32 0)
store i64 %16, i64* %4
store i64 4294967296, i64* %5
%17 = load i64, i64* %4
%18 = load i64, i64* %5
%19 = icmp ugt i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 0, i32* %2
br label %22
21: ; preds = %14
store i32 1, i32* %2
br label %22
22: ; preds = %21, %20, %13, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [9 x i8] c"^[0-9]+$\00"
define i32 @validate_u32(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = tail call i32 @re_match(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i64 @strtoul(i8* nocapture %0, i32* null, i32 0)
%8 = icmp ult i64 %7, 4294967297
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %3, %1, %6
%11 = phi i32 [ %9, %6 ], [ 0, %1 ], [ 0, %3 ]
ret i32 %11
}