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


x86 assembly (clang, -O0):
<printnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jb     1174 <printnum+0x54>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <printnum@plt>
jmp    11a4 <printnum+0x84>
jmp    1179 <printnum+0x59>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    119f <printnum+0x7f>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putch@plt>
jmp    1179 <printnum+0x59>
jmp    11a4 <printnum+0x84>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
div    %rcx
lea    0xe49(%rip),%rax
mov    (%rax,%rdx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putch@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printnum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
cmp    %rsi,%r12
jbe    1164 <printnum+0x44>
cmp    $0x2,%ebp
jl     1193 <printnum+0x73>
add    $0x1,%ebp
movsbl %r8b,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <putch@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
ja     1150 <printnum+0x30>
jmp    1193 <printnum+0x73>
mov    %edx,%ecx
mov    %r14,%rax
shr    $0x20,%rax
je     1179 <printnum+0x59>
mov    %r14,%rax
xor    %edx,%edx
div    %r12
jmp    1181 <printnum+0x61>
mov    %r14d,%eax
xor    %edx,%edx
div    %r12d
add    $0xffffffff,%ebp
mov    %r15,%rdi
mov    %rax,%rsi
mov    %ecx,%edx
mov    %ebp,%ecx
call   1030 <printnum@plt>
mov    %r14,%rax
shr    $0x20,%rax
je     11a6 <printnum+0x86>
mov    %r14,%rax
xor    %edx,%edx
div    %r12
jmp    11ae <printnum+0x8e>
mov    %r14d,%eax
xor    %edx,%edx
div    %r12d
lea    0xe4b(%rip),%rax
movsbl (%rdx,%rax,1),%edi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <putch@plt>

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

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