#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ print_str(char *);
void print_num(unsigned long long value, int base) {
  char digits[] = "0123456789abcdef";
  char buf[32];
  int i = sizeof(buf) - 2, j;
  for (j = 0; j < 32; j++) {
    buf[j] = 0;
  }
  do {
    buf[i--] = digits[value % base];
    value /= base;
  } while (value);
  print_str(&buf[i + 1]);
}


x86 assembly (clang, -O0):
<print_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed5(%rip),%al
mov    %al,-0x10(%rbp)
movl   $0x1e,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
cmpl   $0x20,-0x48(%rbp)
jge    116d <print_num+0x5d>
movslq -0x48(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    114c <print_num+0x3c>
jmp    1172 <print_num+0x62>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    -0x20(%rbp,%rdx,1),%cl
mov    -0x44(%rbp),%eax
mov    %eax,%edx
add    $0xffffffff,%edx
mov    %edx,-0x44(%rbp)
cltq
mov    %cl,-0x40(%rbp,%rax,1)
movslq -0xc(%rbp),%rcx
mov    -0x8(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1172 <print_num+0x62>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
cltq
lea    -0x40(%rbp),%rdi
add    %rax,%rdi
call   1030 <print_str@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_num>:
sub    $0x28,%rsp
mov    %rdi,%rcx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movslq %esi,%r8
lea    0x1f(%rsp),%rdi
lea    0xece(%rip),%r9
jmp    115c <print_num+0x4c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rcx,%rax
xor    %edx,%edx
div    %r8
movzbl (%rdx,%r9,1),%edx
mov    %dl,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
cmp    %r8,%rcx
mov    %rax,%rcx
jb     1170 <print_num+0x60>
mov    %rcx,%rax
or     %r8,%rax
shr    $0x20,%rax
jne    1140 <print_num+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1148 <print_num+0x38>
call   1030 <print_str@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.print_num.digits = [17 x i8] c"0123456789abcdef\00"
define void @print_num(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
%9 = bitcast [17 x i8]* %5 to i8*
store i32 30, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %17, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 32
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %13
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
store i32 %19, i32* %8
br label %10
20: ; preds = %10
br label %21
21: ; preds = %36, %20
%22 = load i64, i64* %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = urem i64 %22, %24
%26 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, -1
store i32 %29, i32* %7
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %30
store i8 %27, i8* %31
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = load i64, i64* %3
%35 = udiv i64 %34, %33
store i64 %35, i64* %3
br label %36
36: ; preds = %21
%37 = load i64, i64* %3
%38 = icmp ne i64 %37, 0
br i1 %38, label %21, label %39
39: ; preds = %36
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %42
%44 = call i32 @print_str(i8* %43)
ret void
}

LLVM IR (-O2):
@__const.print_num.digits = [17 x i8] c"0123456789abcdef\00"
define void @print_num(i64 %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = sext i32 %1 to i64
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ 30, %2 ], [ %13, %7 ]
%9 = phi i64 [ %0, %2 ], [ %15, %7 ]
%10 = urem i64 %9, %6
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.print_num.digits, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = add i64 %8, -1
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %8
store i8 %12, i8* %14
%15 = udiv i64 %9, %6
%16 = icmp ult i64 %9, %6
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %8
%19 = call i32 @print_str(i8* %18)
ret void
}