#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*/ ERANGE;
unsigned long UINT_MAX;
int /*<<< orphan*/ errno;
unsigned long strtoul(char const *, char **, int);
int /*<<< orphan*/ xerror(char const *);
unsigned int xatoui(const char *s) {
  if (*s == '\0') {
    errno = ERANGE;
    xerror(s);
  }
  char *end;
  unsigned long n = strtoul(s, &end, 10);
  if (*end != '\0')
    xerror(s);
  if (n >= UINT_MAX) {
    errno = ERANGE;
    xerror(s);
  }
  return n;
}


x86 assembly (clang, -O0):
<xatoui>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1157 <xatoui+0x37>
mov    0x2e9d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e84(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <xerror@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1186 <xatoui+0x66>
mov    -0x8(%rbp),%rdi
call   1030 <xerror@plt>
mov    -0x18(%rbp),%rax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
jb     11b5 <xatoui+0x95>
mov    0x2e3f(%rip),%rax
mov    (%rax),%ecx
mov    0x2e26(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <xerror@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xatoui>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
jne    1146 <xatoui+0x26>
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    0x2e94(%rip),%rcx
mov    %eax,(%rcx)
mov    %rbx,%rdi
call   1030 <xerror@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     116a <xatoui+0x4a>
mov    %rbx,%rdi
call   1030 <xerror@plt>
mov    0x2e77(%rip),%rax
cmp    (%rax),%r14
jb     1190 <xatoui+0x70>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    0x2e4a(%rip),%rcx
mov    %eax,(%rcx)
mov    %rbx,%rdi
call   1030 <xerror@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
@UINT_MAX = global i64 0
define i32 @xatoui(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @ERANGE
store i32 %10, i32* @errno
%11 = load i8*, i8** %2
%12 = call i32 @xerror(i8* %11)
br label %13
13: ; preds = %9, %1
%14 = load i8*, i8** %2
%15 = call i64 @strtoul(i8* %14, i8** %3, i32 10)
store i64 %15, i64* %4
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i8*, i8** %2
%22 = call i32 @xerror(i8* %21)
br label %23
23: ; preds = %20, %13
%24 = load i64, i64* %4
%25 = load i64, i64* @UINT_MAX
%26 = icmp uge i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @ERANGE
store i32 %28, i32* @errno
%29 = load i8*, i8** %2
%30 = call i32 @xerror(i8* %29)
br label %31
31: ; preds = %27, %23
%32 = load i64, i64* %4
%33 = trunc i64 %32 to i32
ret i32 %33
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
@UINT_MAX = global i64 0
define i32 @xatoui(i8* %0) {
%2 = alloca i8*
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @ERANGE
store i32 %6, i32* @errno
%7 = tail call i32 @xerror(i8* %0)
br label %8
8: ; preds = %5, %1
%9 = bitcast i8** %2 to i8*
%10 = call i64 @strtoul(i8* %0, i8** %2, i32 10)
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 @xerror(i8* %0)
br label %16
16: ; preds = %14, %8
%17 = load i64, i64* @UINT_MAX
%18 = icmp ult i64 %10, %17
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* @ERANGE
store i32 %20, i32* @errno
%21 = tail call i32 @xerror(i8* %0)
br label %22
22: ; preds = %19, %16
%23 = trunc i64 %10 to i32
ret i32 %23
}