#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 charlong(char *);
char pow(int, int);
int strtoint(char *chaine) {
  int i, resultat;
  resultat = 0;
  for (i = 0; i < charlong(chaine); i++) {
    resultat =
        resultat + ((chaine[i] - '0') * pow(10, charlong(chaine) - 1 - i));
  }
  return resultat;
}


x86 assembly (clang, -O0):
<strtoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <charlong@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11aa <strtoint+0x8a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <charlong@plt>
mov    %eax,%esi
sub    $0x1,%esi
sub    -0xc(%rbp),%esi
mov    $0xa,%edi
call   1040 <pow@plt>
mov    -0x1c(%rbp),%ecx
mov    %al,%dl
mov    -0x18(%rbp),%eax
movsbl %dl,%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <strtoint+0x1a>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoint>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <charlong@plt>
test   %eax,%eax
jle    1180 <strtoint+0x60>
xor    %ebx,%ebx
mov    $0xffffffff,%ebp
xor    %r15d,%r15d
xchg   %ax,%ax
movsbl (%r14,%rbx,1),%r12d
add    $0xffffffd0,%r12d
mov    %r14,%rdi
call   1030 <charlong@plt>
lea    (%rax,%rbp,1),%esi
mov    $0xa,%edi
call   1040 <pow@plt>
movsbl %al,%eax
imul   %r12d,%eax
add    %eax,%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <charlong@plt>
cltq
add    $0xffffffff,%ebp
cmp    %rax,%rbx
jl     1140 <strtoint+0x20>
jmp    1183 <strtoint+0x63>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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