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


x86 assembly (clang, -O0):
<kputn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeda(%rip),%rax
mov    %rax,-0x58(%rbp)
cmpl   $0x24,-0xc(%rbp)
jle    1139 <kputn+0x29>
jmp    119f <kputn+0x8f>
lea    -0x50(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    -0x68(%rbp),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x60(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x60(%rbp)
mov    %cl,-0x1(%rax)
movslq -0xc(%rbp),%rcx
mov    -0x8(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <kputn+0x3c>
mov    -0x60(%rbp),%rdi
call   1030 <kputs@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kputn>:
cmp    $0x24,%esi
jg     1179 <kputn+0x69>
sub    $0x48,%rsp
mov    %rdi,%rcx
lea    0x40(%rsp),%rdi
movb   $0x0,0x40(%rsp)
movslq %esi,%r8
lea    0xed0(%rip),%r9
jmp    115c <kputn+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rcx,%rax
xor    %edx,%edx
div    %r8
movzbl (%rdx,%r9,1),%edx
mov    %dl,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
cmp    %r8,%rcx
mov    %rax,%rcx
jb     1170 <kputn+0x60>
mov    %rcx,%rax
or     %r8,%rax
shr    $0x20,%rax
jne    1140 <kputn+0x30>
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
jmp    1148 <kputn+0x38>
call   1030 <kputs@plt>
add    $0x48,%rsp
ret

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

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