#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*/ kputs(char *);
void kputn(int n, const int base) {
  if (base > 36)
    return;
  const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
  char buf[65];
  char *p = buf + 64;
  *p = '\0';
  do {
    *--p = digits[n % base];
    n /= base;
  } while (n);
  kputs(p);
}


x86 assembly (clang, -O0):
<kputn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x24,-0x8(%rbp)
jle    1140 <kputn+0x20>
jmp    11b6 <kputn+0x96>
lea    -0x30(%rbp),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x25,%edx
call   1030 <memcpy@plt>
lea    -0x80(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
movslq %edx,%rax
mov    -0x30(%rbp,%rax,1),%cl
mov    -0x88(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x88(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    116e <kputn+0x4e>
mov    -0x88(%rbp),%rdi
call   1040 <kputs@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kputn>:
cmp    $0x24,%esi
jg     114e <kputn+0x3e>
sub    $0x48,%rsp
mov    %edi,%eax
lea    0x40(%rsp),%rdi
movb   $0x0,0x40(%rsp)
lea    0xed4(%rip),%rcx
nopl   0x0(%rax)
cltd
idiv   %esi
movslq %edx,%rdx
movzbl (%rdx,%rcx,1),%edx
mov    %dl,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
test   %eax,%eax
jne    1130 <kputn+0x20>
call   1030 <kputs@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
@__const.kputn.digits = [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @kputn(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [37 x i8]
%6 = alloca [65 x i8]
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 36
br i1 %9, label %10, label %11
10: ; preds = %2
br label %34
11: ; preds = %2
%12 = bitcast [37 x i8]* %5 to i8*
%13 = getelementptr inbounds [65 x i8], [65 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 64
store i8* %14, i8** %7
%15 = load i8*, i8** %7
store i8 0, i8* %15
br label %16
16: ; preds = %28, %11
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = srem i32 %17, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [37 x i8], [37 x i8]* %5, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %7
store i8 %22, i8* %24
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sdiv i32 %26, %25
store i32 %27, i32* %3
br label %28
28: ; preds = %16
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
br i1 %30, label %16, label %31
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = call i32 @kputs(i8* %32)
br label %34
34: ; preds = %31, %10
ret void
}

LLVM IR (-O2):
@__const.kputn.digits = [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @kputn(i32 %0, i32 %1) {
%3 = alloca [65 x i8]
%4 = icmp sgt i32 %1, 36
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 64
store i8 0, i8* %7
br label %8
8: ; preds = %8, %5
%9 = phi i32 [ %0, %5 ], [ %16, %8 ]
%10 = phi i8* [ %7, %5 ], [ %15, %8 ]
%11 = srem i32 %9, %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [37 x i8], [37 x i8]* @__const.kputn.digits, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds i8, i8* %10, i64 -1
store i8 %14, i8* %15
%16 = sdiv i32 %9, %1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %8
%19 = call i32 @kputs(i8* %15)
br label %20
20: ; preds = %2, %18
ret void
}