#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 find(char, char *);
int strlen(char *);
int my_getnbr_base(char *str, char *base) {
  int res;
  int l_base;
  int l_str;
  int fact;
  res = 1;
  fact = 1;
  l_base = strlen(base);
  l_str = strlen(str) - 1;
  while (l_str >= 0) {
    res = res + find(str[l_str], base) * fact;
    fact = l_base * fact;
    l_str = l_str - 1;
  }
  res -= 1;
  return res;
}


x86 assembly (clang, -O0):
<my_getnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11a6 <my_getnbr_base+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <find@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   -0x20(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <my_getnbr_base+0x39>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_getnbr_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <my_getnbr_base+0x6a>
mov    %eax,%ebp
add    $0x1,%rbp
mov    $0x1,%ebx
mov    $0x1,%r13d
nopl   0x0(%rax)
lea    -0x2(%rbp),%eax
movsbl (%r15,%rax,1),%edi
mov    %r14,%rsi
call   1040 <find@plt>
imul   %ebx,%eax
add    %eax,%r13d
imul   %r12d,%ebx
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1160 <my_getnbr_base+0x40>
add    $0xffffffff,%r13d
jmp    118d <my_getnbr_base+0x6d>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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