#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 */
char *malloc(int);
int my_getnbr_base(char *, char *);
char *rev_str(char *);
int strlen(char *);
char *convert_base(char *nbr, char *ib, char *ob) {
  int i;
  int nb;
  char *res;
  i = 0;
  if ((res = malloc(strlen(nbr) + (strlen(ib) * strlen(ob)))) == NULL)
    return (NULL);
  nb = my_getnbr_base(nbr, ib);
  while (nb > 0) {
    res[i] = ob[nb % strlen(ob)];
    nb = nb / strlen(ob);
    i += 1;
  }
  res[i] = '\0';
  res = rev_str(res);
  return res;
}


x86 assembly (clang, -O0):
<convert_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
imul   %ecx,%eax
add    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11a9 <convert_base+0x69>
movq   $0x0,-0x8(%rbp)
jmp    1240 <convert_base+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <my_getnbr_base@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    121f <convert_base+0xdf>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cltd
idiv   %ecx
mov    -0x48(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b9 <convert_base+0x79>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1040 <rev_str@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <strlen@plt>
imul   %eax,%ebp
add    %r14d,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d6 <convert_base+0x96>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <my_getnbr_base@plt>
test   %eax,%eax
jle    11e7 <convert_base+0xa7>
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
movzbl 0x0(%r13,%rdx,1),%eax
mov    %al,(%r14,%rbx,1)
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
add    $0x1,%rbx
mov    %eax,%ebp
test   %eax,%eax
jg     11a0 <convert_base+0x60>
mov    %ebx,%eax
jmp    11e9 <convert_base+0xa9>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <rev_str@plt>

LLVM IR (-O0):
define i8* @convert_base(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %7
%16 = call i32 @strlen(i8* %15)
%17 = mul nsw i32 %14, %16
%18 = add nsw i32 %12, %17
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %3
store i8* null, i8** %4
br label %56
22: ; preds = %3
%23 = load i8*, i8** %5
%24 = load i8*, i8** %6
%25 = call i32 @my_getnbr_base(i8* %23, i8* %24)
store i32 %25, i32* %9
br label %26
26: ; preds = %29, %22
%27 = load i32, i32* %9
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = load i32, i32* %9
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* %32)
%34 = srem i32 %31, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %30, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %10
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 %37, i8* %41
%42 = load i32, i32* %9
%43 = load i8*, i8** %7
%44 = call i32 @strlen(i8* %43)
%45 = sdiv i32 %42, %44
store i32 %45, i32* %9
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %26
48: ; preds = %26
%49 = load i8*, i8** %10
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
%53 = load i8*, i8** %10
%54 = call i8* @rev_str(i8* %53)
store i8* %54, i8** %10
%55 = load i8*, i8** %10
store i8* %55, i8** %4
br label %56
56: ; preds = %48, %21
%57 = load i8*, i8** %4
ret i8* %57
}

LLVM IR (-O2):
define i8* @convert_base(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = tail call i32 @strlen(i8* %2)
%7 = mul nsw i32 %6, %5
%8 = add nsw i32 %7, %4
%9 = tail call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %33, label %11
11: ; preds = %3
%12 = tail call i32 @my_getnbr_base(i8* %0, i8* %1)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11, %14
%15 = phi i64 [ %25, %14 ], [ 0, %11 ]
%16 = phi i32 [ %24, %14 ], [ %12, %11 ]
%17 = tail call i32 @strlen(i8* %2)
%18 = srem i32 %16, %17
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %2, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %9, i64 %15
store i8 %21, i8* %22
%23 = tail call i32 @strlen(i8* %2)
%24 = sdiv i32 %16, %23
%25 = add nuw i64 %15, 1
%26 = icmp sgt i32 %24, 0
br i1 %26, label %14, label %27
27: ; preds = %14
%28 = and i64 %25, 4294967295
br label %29
29: ; preds = %27, %11
%30 = phi i64 [ 0, %11 ], [ %28, %27 ]
%31 = getelementptr inbounds i8, i8* %9, i64 %30
store i8 0, i8* %31
%32 = tail call i8* @rev_str(i8* %9)
br label %33
33: ; preds = %3, %29
%34 = phi i8* [ %32, %29 ], [ null, %3 ]
ret i8* %34
}