#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;
long LONG_MAX;
long LONG_MIN;
scalar_t__ errno;
long strtoul(char const *, char **, int /*<<< orphan*/);
int parse_uint32(unsigned int *number, const char *str) {
  long value;
  char *endptr = NULL;
  errno = 0;
  value = strtoul(str, &endptr, 0);
  if ((errno == ERANGE) && (value == LONG_MAX || value == LONG_MIN))
    return -1;
  else if (errno != 0 && value == 0)
    return -1;
  if (endptr == str) {
    return -1;
  }
  if (*endptr != '\0') {
    return -1;
  }
  *number = value;
  return 0;
}


x86 assembly (clang, -O0):
<parse_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e99(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <parse_uint32+0x87>
mov    -0x20(%rbp),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
je     118b <parse_uint32+0x7b>
mov    -0x20(%rbp),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <parse_uint32+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_uint32+0xfd>
mov    0x2e2a(%rip),%rax
cmpq   $0x0,(%rax)
je     11bf <parse_uint32+0xaf>
cmpq   $0x0,-0x20(%rbp)
jne    11bf <parse_uint32+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_uint32+0xfd>
jmp    11c4 <parse_uint32+0xb4>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11de <parse_uint32+0xce>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_uint32+0xfd>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fa <parse_uint32+0xea>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <parse_uint32+0xfd>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uint32>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
mov    0x2e99(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1030 <strtoul@plt>
mov    (%rbx),%rdx
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%rdx
jne    1171 <parse_uint32+0x61>
mov    0x2e75(%rip),%rsi
mov    $0xffffffff,%ecx
cmp    (%rsi),%rax
je     1194 <parse_uint32+0x84>
mov    0x2e7c(%rip),%rsi
cmp    (%rsi),%rax
je     1194 <parse_uint32+0x84>
mov    $0xffffffff,%ecx
test   %rdx,%rdx
je     1180 <parse_uint32+0x70>
test   %rax,%rax
je     1194 <parse_uint32+0x84>
mov    0x8(%rsp),%rdx
cmp    %r15,%rdx
je     1194 <parse_uint32+0x84>
cmpb   $0x0,(%rdx)
jne    1194 <parse_uint32+0x84>
mov    %eax,(%r14)
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
define i32 @parse_uint32(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* null, i8** %7
store i64 0, i64* @errno
%8 = load i8*, i8** %5
%9 = call i64 @strtoul(i8* %8, i8** %7, i32 0)
store i64 %9, i64* %6
%10 = load i64, i64* @errno
%11 = load i64, i64* @ERANGE
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i64, i64* %6
%15 = load i64, i64* @LONG_MAX
%16 = icmp eq i64 %14, %15
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i64, i64* %6
%19 = load i64, i64* @LONG_MIN
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %13
store i32 -1, i32* %3
br label %45
22: ; preds = %17, %2
%23 = load i64, i64* @errno
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i64, i64* %6
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 -1, i32* %3
br label %45
29: ; preds = %25, %22
br label %30
30: ; preds = %29
%31 = load i8*, i8** %7
%32 = load i8*, i8** %5
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30
store i32 -1, i32* %3
br label %45
35: ; preds = %30
%36 = load i8*, i8** %7
%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 = %35
store i32 -1, i32* %3
br label %45
41: ; preds = %35
%42 = load i64, i64* %6
%43 = trunc i64 %42 to i32
%44 = load i32*, i32** %4
store i32 %43, i32* %44
store i32 0, i32* %3
br label %45
45: ; preds = %41, %40, %34, %28, %21
%46 = load i32, i32* %3
ret i32 %46
}

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