#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 */
int /*<<< orphan*/ printf(char *);
int a_to_i(char *str) {
  int n;
  int number = 0;
  while (*str != '\0') {
    switch (*str) {
    case '0':
      n = 0;
      break;
    case '1':
      n = 1;
      break;
    case '2':
      n = 2;
      break;
    case '3':
      n = 3;
      break;
    case '4':
      n = 4;
      break;
    case '5':
      n = 5;
      break;
    case '6':
      n = 6;
      break;
    case '7':
      n = 7;
      break;
    case '8':
      n = 8;
      break;
    case '9':
      n = 9;
      break;
    default:
      printf("ERROR! Non numeric characters are not allowed.\n");
      return -1;
    }
    number = (number * 10) + n;
    str++;
  }
  return number;
}


x86 assembly (clang, -O0):
<a_to_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     120b <a_to_i+0xfb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x9,%eax
ja     11d8 <a_to_i+0xc8>
mov    -0x20(%rbp),%rax
lea    0xea9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x1,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x2,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x3,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x4,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x5,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x6,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x7,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x8,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
movl   $0x9,-0x14(%rbp)
jmp    11f0 <a_to_i+0xe0>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <a_to_i+0x101>
imul   $0xa,-0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <a_to_i+0x13>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_to_i>:
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     113e <a_to_i+0x2e>
add    $0x1,%rdi
xor    %eax,%eax
nopl   (%rax)
movsbl %cl,%ecx
add    $0xffffffd0,%ecx
cmp    $0xa,%ecx
jae    1142 <a_to_i+0x32>
lea    (%rax,%rax,4),%eax
lea    (%rcx,%rax,2),%eax
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
jne    1120 <a_to_i+0x10>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [48 x i8] c"ERROR! Non numeric characters are not allowed.\0A\00"
define i32 @a_to_i(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
br label %6
6: ; preds = %27, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %25 [
i32 48, label %15
i32 49, label %16
i32 50, label %17
i32 51, label %18
i32 52, label %19
i32 53, label %20
i32 54, label %21
i32 55, label %22
i32 56, label %23
i32 57, label %24
]
15: ; preds = %11
store i32 0, i32* %4
br label %27
16: ; preds = %11
store i32 1, i32* %4
br label %27
17: ; preds = %11
store i32 2, i32* %4
br label %27
18: ; preds = %11
store i32 3, i32* %4
br label %27
19: ; preds = %11
store i32 4, i32* %4
br label %27
20: ; preds = %11
store i32 5, i32* %4
br label %27
21: ; preds = %11
store i32 6, i32* %4
br label %27
22: ; preds = %11
store i32 7, i32* %4
br label %27
23: ; preds = %11
store i32 8, i32* %4
br label %27
24: ; preds = %11
store i32 9, i32* %4
br label %27
25: ; preds = %11
%26 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %36
27: ; preds = %24, %23, %22, %21, %20, %19, %18, %17, %16, %15
%28 = load i32, i32* %5
%29 = mul nsw i32 %28, 10
%30 = load i32, i32* %4
%31 = add nsw i32 %29, %30
store i32 %31, i32* %5
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %6
34: ; preds = %6
%35 = load i32, i32* %5
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %25
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@str = [47 x i8] c"ERROR! Non numeric characters are not allowed.\00"
define i32 @a_to_i(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %13
%5 = phi i8 [ %17, %13 ], [ %2, %1 ]
%6 = phi i32 [ %15, %13 ], [ 0, %1 ]
%7 = phi i8* [ %16, %13 ], [ %0, %1 ]
%8 = sext i8 %5 to i32
%9 = add nsw i32 %8, -48
%10 = icmp ult i32 %9, 10
br i1 %10, label %13, label %11
11: ; preds = %4
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %19
13: ; preds = %4
%14 = mul nsw i32 %6, 10
%15 = add nsw i32 %9, %14
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %13, %1, %11
%20 = phi i32 [ -1, %11 ], [ 0, %1 ], [ %15, %13 ]
ret i32 %20
}