#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 uint64_t;

/* Variables and functions */
int is_uint_n_range(char const *, size_t, int *, int, int, int);
int /*<<< orphan*/ *strchr(char const *, char const);
size_t strlen(char const *);
int suffix2factor(char const);
int str2uint64(const char *str, const char *suffixes, uint64_t *value) {
  uint64_t factor = 1;
  const char *p;
  size_t sz;
  int ret;
  sz = strlen(str);
  p = str + sz - 1;
  if (NULL != strchr(suffixes, *p)) {
    factor = suffix2factor(*p);
    sz--;
  }
  if (0 ==
      (ret = is_uint_n_range(str, sz, value, 8, 0x0, 0xFFFFFFFFFFFFFFFFUL)))
    *value *= factor;
  return ret;
}


x86 assembly (clang, -O0):
<str2uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
add    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11b1 <str2uint64+0x71>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <suffix2factor@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x8,%ecx
xor    %r8d,%r8d
mov    $0xffffffff,%r9d
call   1060 <is_uint_n_range@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jne    11eb <str2uint64+0xab>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
imul   (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2uint64>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
movsbl -0x1(%r15,%rax,1),%esi
mov    %rbp,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     117e <str2uint64+0x3e>
movsbl -0x1(%r15,%rbx,1),%edi
call   1030 <suffix2factor@plt>
mov    %eax,%ebp
add    $0xffffffffffffffff,%rbx
jmp    1183 <str2uint64+0x43>
mov    $0x1,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    $0x8,%ecx
xor    %r8d,%r8d
mov    $0xffffffff,%r9d
call   1060 <is_uint_n_range@plt>
test   %eax,%eax
jne    11aa <str2uint64+0x6a>
imul   (%r14),%ebp
mov    %ebp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str2uint64(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 1, i32* %7
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %9
%13 = load i8*, i8** %4
%14 = load i64, i64* %9
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %8
%17 = load i8*, i8** %5
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = call i32* @strchr(i8* %17, i8 signext %19)
%21 = icmp ne i32* null, %20
br i1 %21, label %22, label %28
22: ; preds = %3
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = call i32 @suffix2factor(i8 signext %24)
store i32 %25, i32* %7
%26 = load i64, i64* %9
%27 = add i64 %26, -1
store i64 %27, i64* %9
br label %28
28: ; preds = %22, %3
%29 = load i8*, i8** %4
%30 = load i64, i64* %9
%31 = load i32*, i32** %6
%32 = call i32 @is_uint_n_range(i8* %29, i64 %30, i32* %31, i32 8, i32 0, i32 -1)
store i32 %32, i32* %10
%33 = icmp eq i32 0, %32
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load i32, i32* %7
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = mul nsw i32 %37, %35
store i32 %38, i32* %36
br label %39
39: ; preds = %34, %28
%40 = load i32, i32* %10
ret i32 %40
}

LLVM IR (-O2):
define i32 @str2uint64(i8* %0, i8* %1, i32* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = load i8, i8* %6
%8 = tail call i32* @strchr(i8* %1, i8 signext %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = load i8, i8* %6
%12 = tail call i32 @suffix2factor(i8 signext %11)
%13 = add i64 %4, -1
br label %14
14: ; preds = %10, %3
%15 = phi i64 [ %13, %10 ], [ %4, %3 ]
%16 = phi i32 [ %12, %10 ], [ 1, %3 ]
%17 = tail call i32 @is_uint_n_range(i8* %0, i64 %15, i32* %2, i32 8, i32 0, i32 -1)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %2
%21 = mul nsw i32 %20, %16
store i32 %21, i32* %2
br label %22
22: ; preds = %19, %14
ret i32 %17
}