#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 */
unsigned int do_div(unsigned long long, unsigned int);
void printnum(void (*putch)(int, void *), void *putdat, unsigned long long num,
              unsigned base, int width, int padc) {
  unsigned long long result = num;
  unsigned mod = do_div(result, base);
  if (num >= base) {
    printnum(putch, putdat, result, base, width - 1, padc);
  } else {
    while (--width > 0)
      putch(padc, putdat);
  }
  putch("0123456789abcdef"[mod], putdat);
}


x86 assembly (clang, -O0):
<printnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <do_div@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmp    %rcx,%rax
jb     118b <printnum+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
sub    $0x1,%r8d
mov    -0x24(%rbp),%r9d
call   1030 <printnum@plt>
jmp    11b9 <printnum+0x99>
jmp    1190 <printnum+0x70>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    11b4 <printnum+0x94>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
jmp    1190 <printnum+0x70>
jmp    11b9 <printnum+0x99>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
lea    0xe37(%rip),%rcx
movsbl (%rcx,%rdx,1),%edi
mov    -0x10(%rbp),%rsi
call   *%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printnum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8d,%ebp
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    %ecx,%esi
call   1040 <do_div@plt>
mov    %r12d,%ecx
cmp    %r13,%rcx
mov    %eax,0x4(%rsp)
jbe    1178 <printnum+0x58>
cmp    $0x2,%ebp
mov    %rbx,%rdx
jl     1195 <printnum+0x75>
add    $0x1,%ebp
xchg   %ax,%ax
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rdx,%rbx
call   *%rdx
mov    %rbx,%rdx
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
ja     1160 <printnum+0x40>
jmp    1195 <printnum+0x75>
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %ebp,%r8d
mov    %r14d,%r9d
call   1030 <printnum@plt>
mov    %rbx,%rdx
mov    0x4(%rsp),%eax
lea    0xe60(%rip),%rcx
movsbl (%rax,%rcx,1),%edi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    *%rdx

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @printnum(void (i32, i8*)* nocapture %0, i8* %1, i64 %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 @do_div(i64 %2, i32 %3)
%8 = zext i32 %3 to i64
%9 = icmp ugt i64 %8, %2
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = icmp sgt i32 %4, 1
br i1 %11, label %14, label %18
12: ; preds = %6
%13 = add nsw i32 %4, -1
tail call void @printnum(void (i32, i8*)* %0, i8* %1, i64 %2, i32 %3, i32 %13, i32 %5)
br label %18
14: ; preds = %10, %14
%15 = phi i32 [ %16, %14 ], [ %4, %10 ]
%16 = add nsw i32 %15, -1
tail call void %0(i32 %5, i8* %1)
%17 = icmp ugt i32 %15, 2
br i1 %17, label %14, label %18
18: ; preds = %14, %10, %12
%19 = zext i32 %7 to i64
%20 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
tail call void %0(i32 %22, i8* %1)
ret void
}