#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__ malloc(int);
int /*<<< orphan*/ reverse(char *);
char *dec_to_(int num, int base) {
  char chars[] = "0123456789ABCDEFGHIJ";
  char *res = (char *)malloc(100);
  int i = 0;
  while (num > 0) {
    res[i++] = chars[num % base];
    num = num / base;
  }
  res[i] = '\0';
  reverse(res);
  return res;
}


x86 assembly (clang, -O0):
<dec_to_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec6(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xec1(%rip),%al
mov    %al,-0xc(%rbp)
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11a7 <dec_to_+0x87>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
movslq %edx,%rax
mov    -0x20(%rbp,%rax,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x4(%rbp)
jmp    116b <dec_to_+0x4b>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1030 <reverse@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_to_>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    116b <dec_to_+0x4b>
xor    %ecx,%ecx
lea    0xebe(%rip),%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
cltd
idiv   %ebp
movzbl (%rdx,%rsi,1),%edx
mov    %dl,(%r14,%rcx,1)
add    $0x1,%rcx
mov    %eax,%ebx
test   %eax,%eax
jg     1150 <dec_to_+0x30>
mov    %ecx,%eax
jmp    116d <dec_to_+0x4d>
xor    %eax,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   1030 <reverse@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.dec_to_.chars = [21 x i8] c"0123456789ABCDEFGHIJ\00"
define i8* @dec_to_(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [21 x i8]
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [21 x i8]* %5 to i8*
%9 = call i64 @malloc(i32 100)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
store i32 0, i32* %7
br label %11
11: ; preds = %14, %2
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = srem i32 %15, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 %20, i8* %25
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = sdiv i32 %26, %27
store i32 %28, i32* %3
br label %11
29: ; preds = %11
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = call i32 @reverse(i8* %34)
%36 = load i8*, i8** %6
ret i8* %36
}

LLVM IR (-O2):
@__const.dec_to_.chars = [21 x i8] c"0123456789ABCDEFGHIJ\00"
define i8* @dec_to_(i32 %0, i32 %1) {
%3 = tail call i64 @malloc(i32 100)
%4 = inttoptr i64 %3 to i8*
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %19
6: ; preds = %2, %6
%7 = phi i64 [ %13, %6 ], [ 0, %2 ]
%8 = phi i32 [ %15, %6 ], [ %0, %2 ]
%9 = srem i32 %8, %1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [21 x i8], [21 x i8]* @__const.dec_to_.chars, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = add nuw i64 %7, 1
%14 = getelementptr inbounds i8, i8* %4, i64 %7
store i8 %12, i8* %14
%15 = sdiv i32 %8, %1
%16 = icmp sgt i32 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %6
%18 = and i64 %13, 4294967295
br label %19
19: ; preds = %17, %2
%20 = phi i64 [ 0, %2 ], [ %18, %17 ]
%21 = getelementptr inbounds i8, i8* %4, i64 %20
store i8 0, i8* %21
%22 = tail call i32 @reverse(i8* %4)
ret i8* %4
}