#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__ ft_power_base(char const, int, int);
int /*<<< orphan*/ ft_putchar(char);
int /*<<< orphan*/ ft_putnbr(int);
int ft_strlen(char const *);
int ft_atoi_base(const char *str, int str_base) {
  int neg;
  int len;
  int dec;
  int j;
  int i;
  neg = 0;
  dec = 0;
  i = 0;
  if (*str == '-') {
    neg = 1;
    str++;
  }
  len = ft_strlen(str) - 1;
  j = len;
  while (i <= len) {
    dec += (int)ft_power_base(str[i], j, str_base);
    j--;
    i++;
  }
  if (neg) {
    ft_putchar('-');
  }
  ft_putnbr(dec);
  return (0);
}


x86 assembly (clang, -O0):
<ft_atoi_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1187 <ft_atoi_base+0x47>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11de <ft_atoi_base+0x9e>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
movsbl %al,%edi
call   1040 <ft_power_base@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119c <ft_atoi_base+0x5c>
cmpl   $0x0,-0x10(%rbp)
je     11f2 <ft_atoi_base+0xb2>
mov    $0x2d,%edi
call   1050 <ft_putchar@plt>
mov    -0x18(%rbp),%edi
call   1060 <ft_putnbr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_atoi_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    (%rdi),%al
xor    %r15d,%r15d
mov    %al,0x7(%rsp)
cmp    $0x2d,%al
sete   %r15b
add    %rdi,%r15
mov    %r15,%rdi
call   1030 <ft_strlen@plt>
test   %eax,%eax
jle    11c9 <ft_atoi_base+0x89>
mov    %eax,%ebx
mov    %eax,%r13d
neg    %r13
add    $0xffffffff,%ebx
xor    %r12d,%r12d
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%r15,%r12,1),%edi
mov    %ebx,%esi
mov    %r14d,%edx
call   1040 <ft_power_base@plt>
add    %eax,%ebp
add    $0x1,%r12
add    $0xffffffff,%ebx
mov    %r13,%rax
add    %r12,%rax
jne    1180 <ft_atoi_base+0x40>
cmpb   $0x2d,0x7(%rsp)
jne    11b1 <ft_atoi_base+0x71>
mov    $0x2d,%edi
call   1050 <ft_putchar@plt>
mov    %ebp,%edi
call   1060 <ft_putnbr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
cmpb   $0x2d,0x7(%rsp)
je     11a7 <ft_atoi_base+0x67>
jmp    11b1 <ft_atoi_base+0x71>

LLVM IR (-O0):
define i32 @ft_atoi_base(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %7
store i32 0, i32* %9
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 45
br i1 %13, label %14, label %17
14: ; preds = %2
store i32 1, i32* %5
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
br label %17
17: ; preds = %14, %2
%18 = load i8*, i8** %3
%19 = call i32 @ft_strlen(i8* %18)
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %6
%21 = load i32, i32* %6
store i32 %21, i32* %8
br label %22
22: ; preds = %26, %17
%23 = load i32, i32* %9
%24 = load i32, i32* %6
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i32, i32* %8
%33 = load i32, i32* %4
%34 = call i64 @ft_power_base(i8 signext %31, i32 %32, i32 %33)
%35 = trunc i64 %34 to i32
%36 = load i32, i32* %7
%37 = add nsw i32 %36, %35
store i32 %37, i32* %7
%38 = load i32, i32* %8
%39 = add nsw i32 %38, -1
store i32 %39, i32* %8
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %22
42: ; preds = %22
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @ft_putchar(i8 signext 45)
br label %47
47: ; preds = %45, %42
%48 = load i32, i32* %7
%49 = call i32 @ft_putnbr(i32 %48)
ret i32 0
}

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