#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*/ n;

/* Variables and functions */
int CHAR_BIT;
char int2digit(int);
int /*<<< orphan*/ printf(char const *, char *);
void print_num(unsigned long long n, int base, const char *fmt) {
  const size_t bufsize = sizeof(n) * CHAR_BIT + 1;
  char buf[bufsize], *p;
  int rem;
  p = buf + bufsize - 1;
  *p = '\0';
  while (n) {
    rem = n % base;
    *--p = int2digit(rem);
    n /= base;
  }
  printf(fmt, *p == '\0' ? "0" : p);
}


x86 assembly (clang, -O0):
<print_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ea6(%rip),%rax
movslq (%rax),%rax
lea    0x1(,%rax,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,%rsp
mov    %rcx,-0x30(%rbp)
add    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     11ce <print_num+0xae>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1040 <int2digit@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
movslq -0xc(%rbp),%rcx
mov    -0x8(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
jmp    117f <print_num+0x5f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f6 <print_num+0xd6>
lea    0xe13(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    11fe <print_num+0xde>
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_num>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r8
mov    0x2ea8(%rip),%rax
movslq (%rax),%rax
mov    %rsp,%rcx
lea    0x10(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%rcx
mov    %rcx,%rsp
movb   $0x0,(%rcx,%rax,8)
test   %rdi,%rdi
je     11c0 <print_num+0xa0>
mov    %esi,%r15d
mov    %rdi,%r12
mov    %r8,-0x30(%rbp)
lea    (%rcx,%rax,8),%rbx
movslq %esi,%r14
jmp    1192 <print_num+0x72>
nopl   0x0(%rax)
mov    %r12,%rax
xor    %edx,%edx
div    %r14
mov    %rdx,%rdi
mov    %rax,%r13
call   1040 <int2digit@plt>
mov    %al,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%r12
mov    %r13,%r12
jb     11ad <print_num+0x8d>
mov    %r12,%rax
or     %r14,%rax
shr    $0x20,%rax
jne    1170 <print_num+0x50>
mov    %r12d,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,%edi
mov    %eax,%r13d
jmp    117e <print_num+0x5e>
test   %al,%al
lea    0xe4a(%rip),%rax
cmove  %rax,%rbx
mov    -0x30(%rbp),%r8
jmp    11c7 <print_num+0xa7>
lea    0xe39(%rip),%rbx
mov    %r8,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [2 x i8] c"0\00"
define void @print_num(i64 %0, i32 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i64 %0, i64* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%12 = load i32, i32* @CHAR_BIT
%13 = sext i32 %12 to i64
%14 = mul i64 8, %13
%15 = add i64 %14, 1
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i64, i64* %7
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 -1
store i8* %21, i8** %10
%22 = load i8*, i8** %10
store i8 0, i8* %22
br label %23
23: ; preds = %26, %3
%24 = load i64, i64* %4
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = load i64, i64* %4
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = urem i64 %27, %29
%31 = trunc i64 %30 to i32
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = call signext i8 @int2digit(i32 %32)
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %10
store i8 %33, i8* %35
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = load i64, i64* %4
%39 = udiv i64 %38, %37
store i64 %39, i64* %4
br label %23
40: ; preds = %23
%41 = load i8*, i8** %6
%42 = load i8*, i8** %10
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
br label %49
47: ; preds = %40
%48 = load i8*, i8** %10
br label %49
49: ; preds = %47, %46
%50 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %46 ], [ %48, %47 ]
%51 = call i32 @printf(i8* %41, i8* %50)
%52 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [2 x i8] c"0\00"
define void @print_num(i64 %0, i32 %1, i8* %2) {
%4 = load i32, i32* @CHAR_BIT
%5 = sext i32 %4 to i64
%6 = shl nsw i64 %5, 3
%7 = or i64 %6, 1
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 %7
%10 = getelementptr inbounds i8, i8* %9, i64 -1
store i8 0, i8* %10
%11 = icmp eq i64 %0, 0
br i1 %11, label %26, label %12
12: ; preds = %3
%13 = sext i32 %1 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ %0, %12 ], [ %21, %14 ]
%16 = phi i8* [ %10, %12 ], [ %20, %14 ]
%17 = urem i64 %15, %13
%18 = trunc i64 %17 to i32
%19 = tail call signext i8 @int2digit(i32 %18)
%20 = getelementptr inbounds i8, i8* %16, i64 -1
store i8 %19, i8* %20
%21 = udiv i64 %15, %13
%22 = icmp ult i64 %15, %13
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = icmp eq i8 %19, 0
%25 = select i1 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %20
br label %26
26: ; preds = %23, %3
%27 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %3 ], [ %25, %23 ]
%28 = call i32 @printf(i8* %2, i8* %27)
ret void
}