#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__ my_pow(int, int);
int my_strlen(char *);
int my_stoi(char *str) {
  int result = 0;
  for (int i = 0; i < my_strlen(str); i++) {
    result += my_pow((int)str[i], my_strlen(str) - i);
  }
  return result;
}


x86 assembly (clang, -O0):
<my_stoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    1196 <my_stoi+0x76>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
sub    -0x10(%rbp),%esi
call   1040 <my_pow@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <my_stoi+0x1a>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_stoi>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <my_strlen@plt>
test   %eax,%eax
jle    1173 <my_stoi+0x53>
xor    %ebx,%ebx
xor    %ebp,%ebp
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbp,1),%r15d
mov    %r14,%rdi
call   1030 <my_strlen@plt>
lea    (%rax,%rbx,1),%esi
mov    %r15d,%edi
call   1040 <my_pow@plt>
add    %eax,%r12d
add    $0x1,%rbp
mov    %r14,%rdi
call   1030 <my_strlen@plt>
cltq
add    $0xffffffff,%ebx
cmp    %rax,%rbp
jl     1140 <my_stoi+0x20>
jmp    1176 <my_stoi+0x56>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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