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

/* Variables and functions */
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int printn2(FILE *restrict fp, unsigned n, int base) {
  unsigned t;
  int cnt = 0;
  static char digits[] = "0123456789ABCDEF";
  if ((t = n / base) != 0)
    cnt += printn2(fp, t, base);
  putc(digits[n % base], fp);
  return cnt + 1;
}


x86 assembly (clang, -O0):
<printn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1162 <printn2+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <printn2@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    %edx,%eax
mov    %eax,%ecx
lea    0x2ecb(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <putc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printn2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
mov    $0x1,%ebx
cmp    %esi,%edx
ja     1150 <printn2+0x30>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebp
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1030 <printn2@plt>
mov    %eax,%ebx
add    $0x1,%ebx
mov    %r15d,%eax
xor    %edx,%edx
div    %ebp
lea    0xea2(%rip),%rax
movsbl (%rdx,%rax,1),%edi
mov    %r14,%rsi
call   1040 <putc@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@printn2.digits = internal global [17 x i8] c"0123456789ABCDEF\00"
define i32 @printn2(i32* noalias %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = udiv i32 %9, %10
store i32 %11, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32*, i32** %4
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = call i32 @printn2(i32* %14, i32 %15, i32 %16)
%18 = load i32, i32* %8
%19 = add nsw i32 %18, %17
store i32 %19, i32* %8
br label %20
20: ; preds = %13, %3
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = urem i32 %21, %22
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @printn2.digits, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = load i32*, i32** %4
%28 = call i32 @putc(i8 signext %26, i32* %27)
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
ret i32 %30
}

LLVM IR (-O2):
@printn2.digits = internal unnamed_addr constant [17 x i8] c"0123456789ABCDEF\00"
define i32 @printn2(i32* noalias nocapture %0, i32 %1, i32 %2) {
%4 = icmp ugt i32 %2, %1
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = udiv i32 %1, %2
%7 = tail call i32 @printn2(i32* %0, i32 %6, i32 %2)
%8 = add i32 %7, 1
br label %9
9: ; preds = %5, %3
%10 = phi i32 [ %8, %5 ], [ 1, %3 ]
%11 = urem i32 %1, %2
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [17 x i8], [17 x i8]* @printn2.digits, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @putc(i8 signext %14, i32* %0)
ret i32 %10
}