#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__ charToInt(char);
unsigned int fastUnsignedPower10(unsigned int);
unsigned int stringToUnsignedInteger(char *str) {
  unsigned int len, c, i, j;
  len = c = 0;
  while (str[c] != '\0') {
    c++;
  }
  j = c;
  c = c - 1;
  for (i = 0; i < j; ++i) {
    len += ((unsigned int)charToInt(str[c])) * fastUnsignedPower10(i);
    c--;
  }
  return len;
}


x86 assembly (clang, -O0):
<stringToUnsignedInteger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     115c <stringToUnsignedInteger+0x3c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <stringToUnsignedInteger+0x1a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11be <stringToUnsignedInteger+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <charToInt@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <fastUnsignedPower10@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <stringToUnsignedInteger+0x52>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringToUnsignedInteger>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x1,%ebp
cmpb   $0x0,(%r14,%rax,1)
jne    1130 <stringToUnsignedInteger+0x10>
xor    %r12d,%r12d
cmp    $0x1,%ebp
je     117d <stringToUnsignedInteger+0x5d>
lea    -0x3(%rbp),%r13d
add    $0xfffffffe,%ebp
xor    %r12d,%r12d
xor    %ebx,%ebx
mov    %ebp,%eax
movsbl (%r14,%rax,1),%edi
call   1030 <charToInt@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   1040 <fastUnsignedPower10@plt>
imul   %r15d,%eax
add    %eax,%r12d
add    $0x1,%ebx
add    $0xffffffff,%ebp
add    $0xffffffff,%r13d
cmp    $0xfffffffe,%r13d
jne    1150 <stringToUnsignedInteger+0x30>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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