#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 int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ strtoull(char const *, int /*<<< orphan*/ *, int);
uint64_t str_to_uint64(const char *str) {
  if (!str || !*str)
    return 0;
  if (str[0] == '0' && str[1] == 'x')
    return strtoull(str + 2, NULL, 16);
  else
    return strtoull(str, NULL, 10);
}


x86 assembly (clang, -O0):
<str_to_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1134 <str_to_uint64+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1140 <str_to_uint64+0x30>
movl   $0x0,-0x4(%rbp)
jmp    1194 <str_to_uint64+0x84>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    117f <str_to_uint64+0x6f>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    117f <str_to_uint64+0x6f>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtoull@plt>
mov    %eax,-0x4(%rbp)
jmp    1194 <str_to_uint64+0x84>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_uint64>:
test   %rdi,%rdi
je     1135 <str_to_uint64+0x25>
mov    (%rdi),%al
test   %al,%al
je     1135 <str_to_uint64+0x25>
cmp    $0x30,%al
jne    1138 <str_to_uint64+0x28>
cmpb   $0x78,0x1(%rdi)
jne    1138 <str_to_uint64+0x28>
add    $0x2,%rdi
xor    %esi,%esi
mov    $0x10,%edx
jmp    1030 <strtoull@plt>
xor    %eax,%eax
ret
xor    %esi,%esi
mov    $0xa,%edx
jmp    1030 <strtoull@plt>

LLVM IR (-O0):
define i32 @str_to_uint64(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %6, %1
store i32 0, i32* %2
br label %30
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 48
br i1 %16, label %17, label %27
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 120
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = call i32 @strtoull(i8* %25, i32* null, i32 16)
store i32 %26, i32* %2
br label %30
27: ; preds = %17, %11
%28 = load i8*, i8** %3
%29 = call i32 @strtoull(i8* %28, i32* null, i32 10)
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %23, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @str_to_uint64(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = load i8, i8* %0
switch i8 %4, label %12 [
i8 0, label %14
i8 48, label %5
]
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 120
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = tail call i32 @strtoull(i8* nocapture %10, i32* null, i32 16)
br label %14
12: ; preds = %3, %5
%13 = tail call i32 @strtoull(i8* nocapture %0, i32* null, i32 10)
br label %14
14: ; preds = %3, %1, %12, %9
%15 = phi i32 [ %11, %9 ], [ %13, %12 ], [ 0, %3 ], [ 0, %1 ]
ret i32 %15
}