#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 power_10(int);
int char_to_int(char number[], int len) {
  int int_number = 0;
  int power = 0;
  int result_power;
  char current_symbol;
  while (len > 0) {
    len--;
    current_symbol = *(number + len);
    result_power = power_10(power);
    int_number = int_number + ((current_symbol - 48) * result_power);
    power++;
  }
  return int_number;
}


x86 assembly (clang, -O0):
<char_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    117a <char_to_int+0x6a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <power_10@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
movsbl -0x19(%rbp),%ecx
sub    $0x30,%ecx
imul   -0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <char_to_int+0x1d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_int>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1157 <char_to_int+0x47>
mov    %rdi,%r14
mov    %esi,%ebp
add    $0xffffffffffffffff,%rbp
xor    %r15d,%r15d
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
movsbl (%r14,%rax,1),%ebx
mov    %r12d,%edi
call   1030 <power_10@plt>
add    $0xffffffd0,%ebx
imul   %eax,%ebx
add    %ebx,%r15d
add    $0x1,%r12d
add    $0xffffffffffffffff,%rbp
cmp    $0xffffffff,%ebp
jne    1130 <char_to_int+0x20>
jmp    115a <char_to_int+0x4a>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @char_to_int(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %12, %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = load i32, i32* %4
%14 = add nsw i32 %13, -1
store i32 %14, i32* %4
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %8
%20 = load i32, i32* %6
%21 = call i32 @power_10(i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %5
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 48
%26 = load i32, i32* %7
%27 = mul nsw i32 %25, %26
%28 = add nsw i32 %22, %27
store i32 %28, i32* %5
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %9
31: ; preds = %9
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @char_to_int(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %21
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ %5, %4 ], [ %10, %6 ]
%8 = phi i32 [ 0, %4 ], [ %18, %6 ]
%9 = phi i32 [ 0, %4 ], [ %19, %6 ]
%10 = add nsw i64 %7, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @power_10(i32 %9)
%15 = sext i8 %13 to i32
%16 = add nsw i32 %15, -48
%17 = mul nsw i32 %16, %14
%18 = add nsw i32 %17, %8
%19 = add nuw nsw i32 %9, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %6
21: ; preds = %6, %2
%22 = phi i32 [ 0, %2 ], [ %18, %6 ]
ret i32 %22
}