#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 *calloc(int, int);
char *convDecToBase(int dec, int base) {
  if (dec == 0)
    return 0;
  char NUMS[] = "0123456789ABCDEF";
  char *res = calloc(64, sizeof(char));
  int i = 0;
  do {
    res[i] = NUMS[dec % base];
    dec /= base;
    i++;
  } while (dec != 0);
  return res;
}


x86 assembly (clang, -O0):
<convDecToBase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1135 <convDecToBase+0x25>
movq   $0x0,-0x8(%rbp)
jmp    11ae <convDecToBase+0x9e>
mov    0xec4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xebf(%rip),%al
mov    %al,-0x20(%rbp)
mov    $0x40,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
movslq %edx,%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116e <convDecToBase+0x5e>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convDecToBase>:
test   %edi,%edi
je     1162 <convDecToBase+0x52>
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x40,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
lea    0xecc(%rip),%rsi
mov    %rax,%rdi
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
cltd
idiv   %ebx
movslq %edx,%rdx
movzbl (%rdx,%rsi,1),%edx
mov    %dl,(%rdi)
add    $0x1,%rdi
mov    %eax,%ebp
test   %eax,%eax
jne    1140 <convDecToBase+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
mov    %rcx,%rax
ret
xor    %ecx,%ecx
mov    %rcx,%rax
ret

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

LLVM IR (-O2):
@__const.convDecToBase.NUMS = [17 x i8] c"0123456789ABCDEF\00"
define noalias i8* @convDecToBase(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call dereferenceable_or_null(64) i8* @calloc(i32 64, i32 1)
br label %6
6: ; preds = %6, %4
%7 = phi i64 [ %15, %6 ], [ 0, %4 ]
%8 = phi i32 [ %14, %6 ], [ %0, %4 ]
%9 = srem i32 %8, %1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.convDecToBase.NUMS, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 %12, i8* %13
%14 = sdiv i32 %8, %1
%15 = add nuw i64 %7, 1
%16 = icmp eq i32 %14, 0
br i1 %16, label %17, label %6
17: ; preds = %6, %2
%18 = phi i8* [ null, %2 ], [ %5, %6 ]
ret i8* %18
}