#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*/ UINT_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ log_debug(char *, char const *, char const *);
scalar_t__ strtonum_OBSD(char const *, int /*<<< orphan*/, int /*<<< orphan*/,
                         char const **, int);
unsigned int strtouint(const char *nptr, int base, int *error) {
  assert(base == 10 || base == 16);
  unsigned int num;
  const char *errstr;
  *error = 0;
  num = (unsigned int)strtonum_OBSD(nptr, 0, UINT_MAX, &errstr, base);
  if (errstr != NULL) {
    log_debug("can't convert to uint: nptr is %s: %s\n", errstr, nptr);
    *error = 1;
    return 0;
  }
  return num;
}


x86 assembly (clang, -O0):
<strtouint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x1,%al
cmpl   $0xa,-0x14(%rbp)
mov    %al,-0x31(%rbp)
je     115c <strtouint+0x2c>
cmpl   $0x10,-0x14(%rbp)
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%r8d
xor    %esi,%esi
lea    -0x30(%rbp),%rcx
call   1050 <strtonum_OBSD@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c7 <strtouint+0x97>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe54(%rip),%rdi
call   1030 <log_debug@plt>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11cd <strtouint+0x9d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtouint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
cmp    $0xa,%esi
sete   %al
cmp    $0x10,%esi
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
movl   $0x0,(%r14)
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rsp,%rcx
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%r8d
call   1050 <strtonum_OBSD@plt>
mov    (%rsp),%rsi
test   %rsi,%rsi
je     1198 <strtouint+0x68>
lea    0xe79(%rip),%rdi
mov    %r15,%rdx
call   1030 <log_debug@plt>
movl   $0x1,(%r14)
jmp    119a <strtouint+0x6a>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@UINT_MAX = global i32 0
@.str = [39 x i8] c"can't convert to uint: nptr is %s: %s\0A\00"
define i32 @strtouint(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 10
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 16
br label %15
15: ; preds = %12, %3
%16 = phi i1 [ true, %3 ], [ %14, %12 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32*, i32** %7
store i32 0, i32* %19
%20 = load i8*, i8** %5
%21 = load i32, i32* @UINT_MAX
%22 = load i32, i32* %6
%23 = call i64 @strtonum_OBSD(i8* %20, i32 0, i32 %21, i8** %9, i32 %22)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %8
%25 = load i8*, i8** %9
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %15
%28 = load i8*, i8** %9
%29 = load i8*, i8** %5
%30 = call i32 @log_debug(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
%31 = load i32*, i32** %7
store i32 1, i32* %31
store i32 0, i32* %4
br label %34
32: ; preds = %15
%33 = load i32, i32* %8
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@UINT_MAX = global i32 0
@.str = [39 x i8] c"can't convert to uint: nptr is %s: %s\0A\00"
define i32 @strtouint(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = icmp eq i32 %1, 10
%6 = icmp eq i32 %1, 16
%7 = or i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = bitcast i8** %4 to i8*
store i32 0, i32* %2
%11 = load i32, i32* @UINT_MAX
%12 = call i64 @strtonum_OBSD(i8* %0, i32 0, i32 %11, i8** %4, i32 %1)
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = call i32 @log_debug(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %0)
store i32 1, i32* %2
br label %19
17: ; preds = %3
%18 = trunc i64 %12 to i32
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ 0, %15 ], [ %18, %17 ]
ret i32 %20
}