#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 scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ ERANGE;
scalar_t__ LONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ strtoul(char const *, char **, int);
uint32_t getptr(const char *s) {
  int radix = 16;
  uint32_t r;
  char *b;
  if (*s == '_') {
    radix = 10;
    s++;
  }
  r = strtoul(s, &b, radix);
  if ((r == 0 || r == LONG_MAX) && errno == ERANGE) {
    printf("Error: %s is not a valid number\n", s);
    r = 0;
  }
  return r;
}


x86 assembly (clang, -O0):
<getptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x10,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    1156 <getptr+0x36>
movl   $0xa,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1189 <getptr+0x69>
mov    -0x18(%rbp),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    11bb <getptr+0x9b>
mov    0x2e40(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    11bb <getptr+0x9b>
mov    -0x8(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getptr>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
cmpb   $0x5f,(%rdi)
sete   %bl
mov    $0xa,%eax
mov    $0x10,%edx
cmove  %eax,%edx
add    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <strtoul@plt>
test   %rax,%rax
je     115b <getptr+0x3b>
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
jne    1182 <getptr+0x62>
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e7c(%rip),%rdx
cmp    (%rdx),%rcx
jne    1182 <getptr+0x62>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
@errno = global i64 0
@ERANGE = global i64 0
@.str = [33 x i8] c"Error: %s is not a valid number\0A\00"
define i64 @getptr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
store i32 16, i32* %3
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 95
br i1 %9, label %10, label %13
10: ; preds = %1
store i32 10, i32* %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
br label %13
13: ; preds = %10, %1
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = call i64 @strtoul(i8* %14, i8** %5, i32 %15)
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i64, i64* %4
%21 = load i64, i64* @LONG_MAX
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %19, %13
%24 = load i64, i64* @errno
%25 = load i64, i64* @ERANGE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %28)
store i64 0, i64* %4
br label %30
30: ; preds = %27, %23, %19
%31 = load i64, i64* %4
ret i64 %31
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@errno = global i64 0
@ERANGE = global i64 0
@.str = [33 x i8] c"Error: %s is not a valid number\0A\00"
define i64 @getptr(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 95
%6 = zext i1 %5 to i64
%7 = getelementptr i8, i8* %0, i64 %6
%8 = select i1 %5, i32 10, i32 16
%9 = call i64 @strtoul(i8* %7, i8** %2, i32 %8)
%10 = icmp eq i64 %9, 0
%11 = load i64, i64* @LONG_MAX
%12 = icmp eq i64 %9, %11
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i64, i64* @errno
%16 = load i64, i64* @ERANGE
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %20
20: ; preds = %1, %18, %14
%21 = phi i64 [ 0, %18 ], [ %9, %14 ], [ %9, %1 ]
ret i64 %21
}