#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 */
scalar_t__ errno;
int /*<<< orphan*/ isdigit(unsigned char);
unsigned long strtoul(char const *, char **, int);
int parse_threshold(const char *str, unsigned long *threshold) {
  int base;
  char *end_ptr;
  if (!isdigit((unsigned char)*str))
    return 1;
  if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
    base = 16;
  else
    base = 10;
  errno = 0;
  *threshold = strtoul(str, &end_ptr, base);
  if (errno != 0 || *threshold == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<parse_threshold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1151 <parse_threshold+0x31>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <parse_threshold+0xd0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    118f <parse_threshold+0x6f>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     1183 <parse_threshold+0x63>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    118f <parse_threshold+0x6f>
movl   $0x10,-0x1c(%rbp)
jmp    1196 <parse_threshold+0x76>
movl   $0xa,-0x1c(%rbp)
mov    0x2e43(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e1b(%rip),%rax
cmpq   $0x0,(%rax)
jne    11dd <parse_threshold+0xbd>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11e9 <parse_threshold+0xc9>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <parse_threshold+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_threshold>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movzbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     118b <parse_threshold+0x6b>
mov    $0xa,%edx
cmpb   $0x30,(%rbx)
jne    1159 <parse_threshold+0x39>
mov    0x1(%rbx),%al
and    $0xdf,%al
cmp    $0x58,%al
mov    $0x10,%eax
mov    $0xa,%edx
cmove  %eax,%edx
mov    0x2e80(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <strtoul@plt>
mov    %rax,(%r14)
cmpq   $0x0,(%r15)
setne  %cl
test   %rax,%rax
sete   %al
or     %cl,%al
movzbl %al,%eax
jmp    1190 <parse_threshold+0x70>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @parse_threshold(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = call i32 @isdigit(i8 zeroext %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 1, i32* %3
br label %46
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 48
br i1 %18, label %19, label %32
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 120
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 88
br i1 %30, label %31, label %32
31: ; preds = %25, %19
store i32 16, i32* %6
br label %33
32: ; preds = %25, %13
store i32 10, i32* %6
br label %33
33: ; preds = %32, %31
store i64 0, i64* @errno
%34 = load i8*, i8** %4
%35 = load i32, i32* %6
%36 = call i64 @strtoul(i8* %34, i8** %7, i32 %35)
%37 = load i64*, i64** %5
store i64 %36, i64* %37
%38 = load i64, i64* @errno
%39 = icmp ne i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %33
%41 = load i64*, i64** %5
%42 = load i64, i64* %41
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40, %33
store i32 1, i32* %3
br label %46
45: ; preds = %40
store i32 0, i32* %3
br label %46
46: ; preds = %45, %44, %12
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @parse_threshold(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = tail call i32 @isdigit(i8 zeroext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %2
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 48
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = and i8 %13, -33
%15 = icmp eq i8 %14, 88
%16 = select i1 %15, i32 16, i32 10
br label %17
17: ; preds = %8, %11
%18 = phi i32 [ %16, %11 ], [ 10, %8 ]
store i64 0, i64* @errno
%19 = call i64 @strtoul(i8* %0, i8** %3, i32 %18)
store i64 %19, i64* %1
%20 = load i64, i64* @errno
%21 = icmp ne i64 %20, 0
%22 = icmp eq i64 %19, 0
%23 = select i1 %21, i1 true, i1 %22
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %17, %2
%26 = phi i32 [ 1, %2 ], [ %24, %17 ]
ret i32 %26
}