#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 */
typedef unsigned long uint32_t;

/* Variables and functions */
scalar_t__ ERANGE;
unsigned long ULONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int);
int parse_uint32(const char *str, uint32_t *value) {
  char *endptr = NULL;
  unsigned long val = strtoul(str, &endptr, 10);
  if (endptr == NULL || *endptr != '\0')
    fprintf(stderr, "Could not convert \"%s\" to number.\n", str);
  else if (val == ULONG_MAX && errno == ERANGE)
    fprintf(stderr, "Converted value \"%s\" too large.\n", str);
  else {
    *value = val;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1169 <parse_uint32+0x49>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1187 <parse_uint32+0x67>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe83(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ef <parse_uint32+0xcf>
mov    -0x28(%rbp),%rax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
jne    11d3 <parse_uint32+0xb3>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
jne    11d3 <parse_uint32+0xb3>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ea <parse_uint32+0xca>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f6 <parse_uint32+0xd6>
jmp    11ef <parse_uint32+0xcf>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uint32>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     114d <parse_uint32+0x2d>
cmpb   $0x0,(%rcx)
je     1172 <parse_uint32+0x52>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
jne    11a6 <parse_uint32+0x86>
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e59(%rip),%rdx
cmp    (%rdx),%rcx
jne    11a6 <parse_uint32+0x86>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
jmp    115d <parse_uint32+0x3d>
mov    %rax,(%r14)
xor    %eax,%eax
jmp    116a <parse_uint32+0x4a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Could not convert \22%s\22 to number.\0A\00"
@ULONG_MAX = global i64 0
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [33 x i8] c"Converted value \22%s\22 too large.\0A\00"
define i32 @parse_uint32(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i8* null, i8** %6
%8 = load i8*, i8** %4
%9 = call i64 @strtoul(i8* %8, i8** %6, i32 10)
store i64 %9, i64* %7
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12, %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %37
21: ; preds = %12
%22 = load i64, i64* %7
%23 = load i64, i64* @ULONG_MAX
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i64, i64* @errno
%27 = load i64, i64* @ERANGE
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %36
33: ; preds = %25, %21
%34 = load i64, i64* %7
%35 = load i64*, i64** %5
store i64 %34, i64* %35
store i32 0, i32* %3
br label %38
36: ; preds = %29
br label %37
37: ; preds = %36, %17
store i32 -1, i32* %3
br label %38
38: ; preds = %37, %33
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Could not convert \22%s\22 to number.\0A\00"
@ULONG_MAX = global i64 0
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [33 x i8] c"Converted value \22%s\22 too large.\0A\00"
define i32 @parse_uint32(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8, %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
14: ; preds = %8
%15 = load i64, i64* @ULONG_MAX
%16 = icmp eq i64 %5, %15
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i64, i64* @errno
%19 = load i64, i64* @ERANGE
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %25
24: ; preds = %17, %14
store i64 %5, i64* %1
br label %25
25: ; preds = %11, %21, %24
%26 = phi i32 [ 0, %24 ], [ -1, %21 ], [ -1, %11 ]
ret i32 %26
}