#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 */
unsigned long long INT_MAX;
int /*<<< orphan*/ checkDigit(char);
unsigned int charToInt(char *charNumber) {
  unsigned long long int number = 0;
  for (unsigned int i = 0; charNumber[i] != '\0'; i++) {
    if (!checkDigit(charNumber[i]))
      return 0;
    number = number * 10 + charNumber[i] - '0';
    if (number > INT_MAX)
      return 0;
  }
  return (unsigned int)number;
}


x86 assembly (clang, -O0):
<charToInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11b3 <charToInt+0xa3>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <checkDigit@plt>
cmp    $0x0,%eax
jne    1164 <charToInt+0x54>
movl   $0x0,-0x4(%rbp)
jmp    11ba <charToInt+0xaa>
imul   $0xa,-0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%edx
movsbq (%rcx,%rdx,1),%rcx
add    %rcx,%rax
sub    $0x30,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%rax
jbe    11a0 <charToInt+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11ba <charToInt+0xaa>
jmp    11a5 <charToInt+0x95>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <charToInt+0x1b>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charToInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1179 <charToInt+0x69>
mov    %rdi,%r12
mov    $0x1,%ebp
xor    %r14d,%r14d
mov    0x2eb5(%rip),%r15
mov    %rdi,%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <checkDigit@plt>
test   %eax,%eax
je     117c <charToInt+0x6c>
lea    (%rbx,%rbx,4),%rax
movsbq 0x0(%r13),%rcx
lea    (%rcx,%rax,2),%rbx
add    $0xffffffffffffffd0,%rbx
cmp    (%r15),%rbx
ja     117c <charToInt+0x6c>
mov    %ebp,%eax
lea    (%r12,%rax,1),%r13
movzbl (%r12,%rax,1),%eax
add    $0x1,%ebp
test   %al,%al
jne    1140 <charToInt+0x30>
mov    %ebx,%r14d
jmp    117c <charToInt+0x6c>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i32 @charToInt(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 0, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %39, %1
%7 = load i8*, i8** %3
%8 = load i32, i32* %5
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %42
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @checkDigit(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %14
store i32 0, i32* %2
br label %45
23: ; preds = %14
%24 = load i64, i64* %4
%25 = mul i64 %24, 10
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i64
%32 = add i64 %25, %31
%33 = sub i64 %32, 48
store i64 %33, i64* %4
%34 = load i64, i64* %4
%35 = load i64, i64* @INT_MAX
%36 = icmp ugt i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %23
store i32 0, i32* %2
br label %45
38: ; preds = %23
br label %39
39: ; preds = %38
%40 = load i32, i32* %5
%41 = add i32 %40, 1
store i32 %41, i32* %5
br label %6
42: ; preds = %6
%43 = load i64, i64* %4
%44 = trunc i64 %43 to i32
store i32 %44, i32* %2
br label %45
45: ; preds = %42, %37, %22
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i32 @charToInt(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %27, label %9
4: ; preds = %16
%5 = zext i32 %24 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %1, %4
%10 = phi i8 [ %7, %4 ], [ %2, %1 ]
%11 = phi i8* [ %6, %4 ], [ %0, %1 ]
%12 = phi i32 [ %24, %4 ], [ 0, %1 ]
%13 = phi i64 [ %21, %4 ], [ 0, %1 ]
%14 = tail call i32 @checkDigit(i8 signext %10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %9
%17 = mul i64 %13, 10
%18 = load i8, i8* %11
%19 = sext i8 %18 to i64
%20 = add i64 %17, -48
%21 = add i64 %20, %19
%22 = load i64, i64* @INT_MAX
%23 = icmp ugt i64 %21, %22
%24 = add i32 %12, 1
br i1 %23, label %27, label %4
25: ; preds = %4
%26 = trunc i64 %21 to i32
br label %27
27: ; preds = %16, %9, %1, %25
%28 = phi i32 [ 0, %1 ], [ %26, %25 ], [ 0, %9 ], [ 0, %16 ]
ret i32 %28
}