#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*/ ulong;

/* Variables and functions */
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ strrm(char *, char const *, char);
int /*<<< orphan*/ strtoll(char *, char **, int);
const char *string_to_number(const char *str, ulong *dest) {
  if (str) {
    char *wrongchar;
    int base = 0;
    if (*str == '$') {
      base = 16;
      str++;
    } else if (*str == '%') {
      base = 2;
      str++;
    }
    char copy[strlen(str) + 1];
    strrm(copy, str, '_');
    *dest = strtoll(copy, &wrongchar, base);
    if (*wrongchar)
      return "cant' parse this number";
    return 0;
  } else
    return "no number found";
}


x86 assembly (clang, -O0):
<string_to_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1236 <string_to_number+0x106>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    117a <string_to_number+0x4a>
movl   $0x10,-0x24(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a2 <string_to_number+0x72>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    119d <string_to_number+0x6d>
movl   $0x2,-0x24(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a2 <string_to_number+0x72>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x5f,%edx
call   1040 <strrm@plt>
mov    -0x48(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1050 <strtoll@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     121b <string_to_number+0xeb>
lea    0xdf5(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    122a <string_to_number+0xfa>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    1241 <string_to_number+0x111>
lea    0xddb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_number>:
test   %rdi,%rdi
je     1162 <string_to_number+0x32>
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%al
cmp    $0x25,%al
je     116a <string_to_number+0x3a>
xor    %r15d,%r15d
cmp    $0x24,%al
jne    1174 <string_to_number+0x44>
add    $0x1,%r12
mov    $0x10,%r15d
jmp    1174 <string_to_number+0x44>
lea    0xeaf(%rip),%rax
ret
add    $0x1,%r12
mov    $0x2,%r15d
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r13
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x5f,%edx
call   1040 <strrm@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1050 <strtoll@plt>
mov    %eax,(%r14)
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmpb   $0x0,(%rcx)
lea    0xe3b(%rip),%rcx
cmovne %rcx,%rax
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"cant' parse this number\00"
@.str.1 = [16 x i8] c"no number found\00"
define i8* @string_to_number(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %49
13: ; preds = %2
store i32 0, i32* %7
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 36
br i1 %17, label %18, label %21
18: ; preds = %13
store i32 16, i32* %7
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
br label %30
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 37
br i1 %25, label %26, label %29
26: ; preds = %21
store i32 2, i32* %7
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
br label %29
29: ; preds = %26, %21
br label %30
30: ; preds = %29, %18
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 1
%34 = zext i32 %33 to i64
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %8
%36 = alloca i8, i64 %34
store i64 %34, i64* %9
%37 = load i8*, i8** %4
%38 = call i32 @strrm(i8* %36, i8* %37, i8 signext 95)
%39 = load i32, i32* %7
%40 = call i32 @strtoll(i8* %36, i8** %6, i32 %39)
%41 = load i32*, i32** %5
store i32 %40, i32* %41
%42 = load i8*, i8** %6
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %30
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 1, i32* %10
br label %47
46: ; preds = %30
store i8* null, i8** %3
store i32 1, i32* %10
br label %47
47: ; preds = %46, %45
%48 = load i8*, i8** %8
br label %50
49: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %50
50: ; preds = %49, %47
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
@.str = [24 x i8] c"cant' parse this number\00"
@.str.1 = [16 x i8] c"no number found\00"
define i8* @string_to_number(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = bitcast i8** %3 to i8*
%7 = load i8, i8* %0
switch i8 %7, label %12 [
i8 36, label %8
i8 37, label %10
]
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %0, i64 1
br label %12
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %0, i64 1
br label %12
12: ; preds = %5, %10, %8
%13 = phi i32 [ 16, %8 ], [ 2, %10 ], [ 0, %5 ]
%14 = phi i8* [ %9, %8 ], [ %11, %10 ], [ %0, %5 ]
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = tail call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = call i32 @strrm(i8* %19, i8* %14, i8 signext 95)
%21 = call i32 @strtoll(i8* %19, i8** %3, i32 %13)
store i32 %21, i32* %1
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
%25 = select i1 %24, i8* null, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0)
br label %26
26: ; preds = %2, %12
%27 = phi i8* [ %25, %12 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %2 ]
ret i8* %27
}