#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 EINVAL;
long long strtoll(char const *, char **, int /*<<< orphan*/);
int parseuint(const char *str, unsigned int *val) {
  long long ret;
  char *bad;
  if (*str == '\0')
    return EINVAL;
  ret = strtoll(str, &bad, 0);
  if (*bad != '\0')
    return EINVAL;
  if ((ret < 0) || (ret > 0xffffffffLL))
    return EINVAL;
  *val = ret;
  return 0;
}


x86 assembly (clang, -O0):
<parseuint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1141 <parseuint+0x31>
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <parseuint+0xa3>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1175 <parseuint+0x65>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <parseuint+0xa3>
cmpq   $0x0,-0x20(%rbp)
jl     118f <parseuint+0x7f>
mov    $0xffffffff,%eax
cmp    %rax,-0x20(%rbp)
jle    11a0 <parseuint+0x90>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <parseuint+0xa3>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseuint>:
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,(%rdi)
je     113c <parseuint+0x2c>
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    113c <parseuint+0x2c>
mov    %rax,%rcx
shr    $0x20,%rcx
je     114b <parseuint+0x3b>
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %eax,(%rbx)
xor    %eax,%eax
jmp    1145 <parseuint+0x35>

LLVM IR (-O0):
@EINVAL = global i32 0
define i32 @parseuint(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 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @EINVAL
store i32 %13, i32* %3
br label %35
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i64 @strtoll(i8* %15, i8** %7, i32 0)
store i64 %16, i64* %6
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = load i32, i32* @EINVAL
store i32 %22, i32* %3
br label %35
23: ; preds = %14
%24 = load i64, i64* %6
%25 = icmp slt i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i64, i64* %6
%28 = icmp sgt i64 %27, 4294967295
br i1 %28, label %29, label %31
29: ; preds = %26, %23
%30 = load i32, i32* @EINVAL
store i32 %30, i32* %3
br label %35
31: ; preds = %26
%32 = load i64, i64* %6
%33 = trunc i64 %32 to i32
%34 = load i32*, i32** %5
store i32 %33, i32* %34
store i32 0, i32* %3
br label %35
35: ; preds = %31, %29, %21, %12
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @parseuint(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = load i32, i32* @EINVAL
br label %22
9: ; preds = %2
%10 = call i64 @strtoll(i8* %0, i8** %3, i32 0)
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = load i32, i32* @EINVAL
br label %22
16: ; preds = %9
%17 = icmp ugt i64 %10, 4294967295
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = load i32, i32* @EINVAL
br label %22
20: ; preds = %16
%21 = trunc i64 %10 to i32
store i32 %21, i32* %1
br label %22
22: ; preds = %20, %18, %14, %7
%23 = phi i32 [ %8, %7 ], [ %15, %14 ], [ %19, %18 ], [ 0, %20 ]
ret i32 %23
}