#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__ contains(char const, char *, int);
int strlen(char const *);
int char_to_int(const char *str) {
  int buf = 0;
  int len = strlen(str);
  int mlen = strlen("0123456789"
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                    "."
                    "-"
                    "+");
  for (unsigned int i = 0; i < len; i++)
    if (contains(str[i],
                 "0123456789"
                 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
                 "."
                 "-"
                 "+",
                 mlen))
      buf += (int)str[i];
  return buf;
}


x86 assembly (clang, -O0):
<char_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11ab <char_to_int+0x8b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x14(%rbp),%edx
lea    0xe8b(%rip),%rsi
movsbl %al,%edi
call   1040 <contains@plt>
cmp    $0x0,%rax
je     1198 <char_to_int+0x78>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119d <char_to_int+0x7d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1155 <char_to_int+0x35>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xec4(%rip),%rdi
call   1030 <strlen@plt>
test   %ebp,%ebp
je     1186 <char_to_int+0x66>
mov    %eax,%r14d
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xeac(%rip),%r15
xor    %r13d,%r13d
jmp    1169 <char_to_int+0x49>
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1189 <char_to_int+0x69>
movsbl (%rbx,%rbp,1),%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <contains@plt>
test   %rax,%rax
je     1160 <char_to_int+0x40>
movsbl (%rbx,%rbp,1),%eax
add    %eax,%r13d
jmp    1160 <char_to_int+0x40>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-+\00"
define i32 @char_to_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
%9 = call i32 @strlen(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %5
store i32 0, i32* %6
br label %10
10: ; preds = %33, %1
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %36
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = load i32, i32* %5
%21 = call i64 @contains(i8 signext %19, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %14
%24 = load i8*, i8** %2
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = load i32, i32* %3
%31 = add nsw i32 %30, %29
store i32 %31, i32* %3
br label %32
32: ; preds = %23, %14
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add i32 %34, 1
store i32 %35, i32* %6
br label %10
36: ; preds = %10
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [66 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-+\00"
define i32 @char_to_int(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = zext i32 %2 to i64
br label %9
7: ; preds = %20, %1
%8 = phi i32 [ 0, %1 ], [ %21, %20 ]
ret i32 %8
9: ; preds = %5, %20
%10 = phi i64 [ 0, %5 ], [ %22, %20 ]
%11 = phi i32 [ 0, %5 ], [ %21, %20 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = tail call i64 @contains(i8 signext %13, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %9
%17 = load i8, i8* %12
%18 = sext i8 %17 to i32
%19 = add nsw i32 %11, %18
br label %20
20: ; preds = %9, %16
%21 = phi i32 [ %19, %16 ], [ %11, %9 ]
%22 = add nuw nsw i64 %10, 1
%23 = icmp eq i64 %22, %6
br i1 %23, label %7, label %9
}