#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;
struct htrace_log {
  int dummy;
};

/* Variables and functions */
int errno;
int /*<<< orphan*/ htrace_log(struct htrace_log *, char *, char const *,
                              char const *, ...);
int /*<<< orphan*/ strtoull(char const *, char **, int);
int /*<<< orphan*/ terror(int);
int convert_u64(struct htrace_log *log, const char *key, const char *in,
                uint64_t *out) {
  char *endptr = NULL;
  int err;
  uint64_t ret;
  errno = 0;
  ret = strtoull(in, &endptr, 10);
  if (errno) {
    err = errno;
    htrace_log(log, "error parsing %s for %s: %d (%s)\n", in, key, err,
               terror(err));
    return 0;
  }
  while (1) {
    char c = *endptr;
    if (c == '\0') {
      break;
    }
    if (!((c == ' ') || (c == '\t'))) {
      htrace_log(log,
                 "error parsing %s for %s: garbage at end "
                 "of string.\n",
                 in, key);
      return 0;
    }
    endptr++;
  }
  *out = ret;
  return 1;
}


x86 assembly (clang, -O0):
<convert_u64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e89(%rip),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    %eax,-0x38(%rbp)
mov    0x2e67(%rip),%rax
cmpl   $0x0,(%rax)
je     11e1 <convert_u64+0xb1>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <terror@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8d
mov    %eax,%r9d
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <htrace_log@plt>
movl   $0x0,-0x4(%rbp)
jmp    1262 <convert_u64+0x132>
jmp    11e6 <convert_u64+0xb6>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
cmp    $0x0,%eax
jne    1201 <convert_u64+0xd1>
jmp    1252 <convert_u64+0x122>
movsbl -0x39(%rbp),%eax
cmp    $0x20,%eax
je     1241 <convert_u64+0x111>
movsbl -0x39(%rbp),%eax
cmp    $0x9,%eax
je     1241 <convert_u64+0x111>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1050 <htrace_log@plt>
movl   $0x0,-0x4(%rbp)
jmp    1262 <convert_u64+0x132>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11e6 <convert_u64+0xb6>
mov    -0x38(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_u64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,(%rsp)
mov    0x2e8a(%rip),%rbx
movl   $0x0,(%rbx)
mov    %rsp,%rsi
mov    %rdx,%rdi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    (%rbx),%ebx
test   %ebx,%ebx
je     119a <convert_u64+0x6a>
mov    %ebx,%edi
call   1040 <terror@plt>
lea    0xe80(%rip),%rsi
xor    %ebp,%ebp
mov    %r15,%rdi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %ebx,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <htrace_log@plt>
jmp    11d9 <convert_u64+0xa9>
mov    (%rsp),%rcx
jmp    11a4 <convert_u64+0x74>
add    $0x1,%rcx
movzbl (%rcx),%edx
cmp    $0x9,%dl
je     11a0 <convert_u64+0x70>
cmp    $0x20,%dl
je     11a0 <convert_u64+0x70>
test   %dl,%dl
jne    11c0 <convert_u64+0x90>
mov    %eax,(%r12)
mov    $0x1,%ebp
jmp    11d9 <convert_u64+0xa9>
lea    0xe5b(%rip),%rsi
xor    %ebp,%ebp
mov    %r15,%rdi
mov    %r13,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <htrace_log@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.htrace_log = type { i32 }
@errno = global i32 0
@.str = [34 x i8] c"error parsing %s for %s: %d (%s)\0A\00"
@.str.1 = [52 x i8] c"error parsing %s for %s: garbage at end of string.\0A\00"
define i32 @convert_u64(%struct.htrace_log* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca %struct.htrace_log*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
store %struct.htrace_log* %0, %struct.htrace_log** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i8* null, i8** %10
store i32 0, i32* @errno
%14 = load i8*, i8** %8
%15 = call i32 @strtoull(i8* %14, i8** %10, i32 10)
store i32 %15, i32* %12
%16 = load i32, i32* @errno
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %4
%19 = load i32, i32* @errno
store i32 %19, i32* %11
%20 = load %struct.htrace_log*, %struct.htrace_log** %6
%21 = load i8*, i8** %8
%22 = load i8*, i8** %7
%23 = load i32, i32* %11
%24 = load i32, i32* %11
%25 = call i32 @terror(i32 %24)
%26 = call i32 (%struct.htrace_log*, i8*, i8*, i8*, ...) @htrace_log(%struct.htrace_log* %20, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i32 %23, i32 %25)
store i32 0, i32* %5
br label %54
27: ; preds = %4
br label %28
28: ; preds = %27, %48
%29 = load i8*, i8** %10
%30 = load i8, i8* %29
store i8 %30, i8* %13
%31 = load i8, i8* %13
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
br label %51
35: ; preds = %28
%36 = load i8, i8* %13
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 32
br i1 %38, label %48, label %39
39: ; preds = %35
%40 = load i8, i8* %13
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 9
br i1 %42, label %48, label %43
43: ; preds = %39
%44 = load %struct.htrace_log*, %struct.htrace_log** %6
%45 = load i8*, i8** %8
%46 = load i8*, i8** %7
%47 = call i32 (%struct.htrace_log*, i8*, i8*, i8*, ...) @htrace_log(%struct.htrace_log* %44, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %45, i8* %46)
store i32 0, i32* %5
br label %54
48: ; preds = %39, %35
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %10
br label %28
51: ; preds = %34
%52 = load i32, i32* %12
%53 = load i32*, i32** %9
store i32 %52, i32* %53
store i32 1, i32* %5
br label %54
54: ; preds = %51, %43, %18
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
%struct.htrace_log = type { i32 }
@errno = global i32 0
@.str = [34 x i8] c"error parsing %s for %s: %d (%s)\0A\00"
@.str.1 = [52 x i8] c"error parsing %s for %s: garbage at end of string.\0A\00"
define i32 @convert_u64(%struct.htrace_log* %0, i8* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* null, i8** %5
store i32 0, i32* @errno
%7 = call i32 @strtoull(i8* %2, i8** %5, i32 10)
%8 = load i32, i32* @errno
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = load i8*, i8** %5
br label %15
12: ; preds = %4
%13 = tail call i32 @terror(i32 %8)
%14 = tail call i32 (%struct.htrace_log*, i8*, i8*, i8*, ...) @htrace_log(%struct.htrace_log* %0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %1, i32 %8, i32 %13)
br label %23
15: ; preds = %10, %20
%16 = phi i8* [ %11, %10 ], [ %21, %20 ]
%17 = load i8, i8* %16
switch i8 %17, label %18 [
i8 0, label %22
i8 32, label %20
i8 9, label %20
]
18: ; preds = %15
%19 = tail call i32 (%struct.htrace_log*, i8*, i8*, i8*, ...) @htrace_log(%struct.htrace_log* %0, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %1)
br label %23
20: ; preds = %15, %15
%21 = getelementptr inbounds i8, i8* %16, i64 1
br label %15
22: ; preds = %15
store i32 %7, i32* %3
br label %23
23: ; preds = %18, %22, %12
%24 = phi i32 [ 0, %12 ], [ 1, %22 ], [ 0, %18 ]
ret i32 %24
}