#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 *my_revstr(char *);
int my_strlen(char *);
char *convert_base(char *nbr, char *base_from, char *base_to) {
  int i;
  int nb;
  char *res;
  i = 0;
  res = malloc(sizeof(char) * 300);
  nb = my_getnbr_base(nbr, base_from);
  while (nb > 0) {
    res[i] = base_to[nb % my_strlen(base_to)];
    nb = nb / my_strlen(base_to);
    i = i + 1;
  }
  res[i] = '\0';
  res = my_revstr(res);
  return (res);
}


x86 assembly (clang, -O0):
<convert_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x12c,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <my_getnbr_base@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11df <convert_base+0x9f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cltd
idiv   %ecx
mov    -0x38(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1179 <convert_base+0x39>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1040 <my_revstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_base>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbp
mov    $0x12c,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <my_getnbr_base@plt>
test   %eax,%eax
jle    11b5 <convert_base+0x75>
mov    %eax,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
movzbl (%r12,%rdx,1),%eax
mov    %al,(%r14,%rbx,1)
mov    %r12,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
add    $0x1,%rbx
mov    %eax,%ebp
test   %eax,%eax
jg     1180 <convert_base+0x40>
mov    %ebx,%eax
jmp    11b7 <convert_base+0x77>
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <my_revstr@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 i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%10 = call i8* @malloc(i32 300)
store i8* %10, i8** %9
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 @my_getnbr_base(i8* %11, i8* %12)
store i32 %13, i32* %8
br label %14
14: ; preds = %17, %3
%15 = load i32, i32* %8
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = load i8*, i8** %6
%19 = load i32, i32* %8
%20 = load i8*, i8** %6
%21 = call i32 @my_strlen(i8* %20)
%22 = srem i32 %19, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %18, i64 %23
%25 = load i8, i8* %24
%26 = load i8*, i8** %9
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i32, i32* %8
%31 = load i8*, i8** %6
%32 = call i32 @my_strlen(i8* %31)
%33 = sdiv i32 %30, %32
store i32 %33, i32* %8
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %14
36: ; preds = %14
%37 = load i8*, i8** %9
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %9
%42 = call i8* @my_revstr(i8* %41)
store i8* %42, i8** %9
%43 = load i8*, i8** %9
ret i8* %43
}

LLVM IR (-O2):
define i8* @convert_base(i8* %0, i8* %1, i8* %2) {
%4 = tail call dereferenceable_or_null(300) i8* @malloc(i32 300)
%5 = tail call i32 @my_getnbr_base(i8* %0, i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %3, %7
%8 = phi i64 [ %18, %7 ], [ 0, %3 ]
%9 = phi i32 [ %17, %7 ], [ %5, %3 ]
%10 = tail call i32 @my_strlen(i8* %2)
%11 = srem i32 %9, %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %4, i64 %8
store i8 %14, i8* %15
%16 = tail call i32 @my_strlen(i8* %2)
%17 = sdiv i32 %9, %16
%18 = add nuw i64 %8, 1
%19 = icmp sgt i32 %17, 0
br i1 %19, label %7, label %20
20: ; preds = %7
%21 = and i64 %18, 4294967295
br label %22
22: ; preds = %20, %3
%23 = phi i64 [ 0, %3 ], [ %21, %20 ]
%24 = getelementptr inbounds i8, i8* %4, i64 %23
store i8 0, i8* %24
%25 = tail call i8* @my_revstr(i8* %4)
ret i8* %25
}