#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 ft_basetoi_indexof(char const *, char const *);
int ft_pow(int const, int);
int ft_basetoi(const char *s, const int base) {
  int result;
  int value;
  int pos;
  const char *keys =
      "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (!s)
    return -1;
  pos = 0;
  result = 0;
  while (s[pos] != '\0') {
    value = ft_basetoi_indexof(&s[pos], keys);
    if (value < 0)
      return -2;
    result += value * ft_pow(base, pos);
    pos++;
  }
  return result;
}


x86 assembly (clang, -O0):
<ft_basetoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1151 <ft_basetoi+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <ft_basetoi+0xb4>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ce <ft_basetoi+0xae>
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1030 <ft_basetoi_indexof@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a1 <ft_basetoi+0x81>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11d4 <ft_basetoi+0xb4>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <ft_pow@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115f <ft_basetoi+0x3f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_basetoi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1180 <ft_basetoi+0x60>
mov    %rdi,%r15
cmpb   $0x0,(%rdi)
je     1188 <ft_basetoi+0x68>
mov    %esi,%r14d
xor    %ebx,%ebx
lea    0xebc(%rip),%r12
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rdi
mov    %r12,%rsi
call   1030 <ft_basetoi_indexof@plt>
test   %eax,%eax
js     118d <ft_basetoi+0x6d>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %ebx,%esi
call   1040 <ft_pow@plt>
imul   %ebp,%eax
add    %eax,%r13d
cmpb   $0x0,0x1(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1150 <ft_basetoi+0x30>
jmp    1193 <ft_basetoi+0x73>
mov    $0xffffffff,%r13d
jmp    1193 <ft_basetoi+0x73>
xor    %r13d,%r13d
jmp    1193 <ft_basetoi+0x73>
mov    $0xfffffffe,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i32 @ft_basetoi(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 -1, i32* %3
br label %44
13: ; preds = %2
store i32 0, i32* %8
store i32 0, i32* %6
br label %14
14: ; preds = %32, %13
%15 = load i8*, i8** %4
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8*, i8** %9
%28 = call i32 @ft_basetoi_indexof(i8* %26, i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %22
store i32 -2, i32* %3
br label %44
32: ; preds = %22
%33 = load i32, i32* %7
%34 = load i32, i32* %5
%35 = load i32, i32* %8
%36 = call i32 @ft_pow(i32 %34, i32 %35)
%37 = mul nsw i32 %33, %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, %37
store i32 %39, i32* %6
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %14
42: ; preds = %14
%43 = load i32, i32* %6
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %31, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i32 @ft_basetoi(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %4, %13
%8 = phi i64 [ %18, %13 ], [ 0, %4 ]
%9 = phi i8* [ %19, %13 ], [ %0, %4 ]
%10 = phi i32 [ %17, %13 ], [ 0, %4 ]
%11 = tail call i32 @ft_basetoi_indexof(i8* %9, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%12 = icmp slt i32 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %7
%14 = trunc i64 %8 to i32
%15 = tail call i32 @ft_pow(i32 %1, i32 %14)
%16 = mul nsw i32 %15, %11
%17 = add nsw i32 %16, %10
%18 = add nuw i64 %8, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %7
22: ; preds = %7, %13, %4, %2
%23 = phi i32 [ -1, %2 ], [ 0, %4 ], [ -2, %7 ], [ %17, %13 ]
ret i32 %23
}