#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*/ putchar(char);
void printkns(long n, int b) {
  char prbuf[24];
  register char *cp;
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  cp = prbuf;
  do {
    *cp++ = "0123456789ABCDEF"[(int)(n % b)];
  } while ((n = n / b & 0x0FFFFFFF) != 0);
  do {
    putchar(*--cp);
  } while (cp > prbuf);
}


x86 assembly (clang, -O0):
<printkns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    113e <printkns+0x2e>
mov    $0x2d,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%eax
movslq %eax,%rcx
lea    0xea1(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cqto
idiv   %rcx
and    $0xfffffff,%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1146 <printkns+0x36>
jmp    1199 <printkns+0x89>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movsbl -0x1(%rax),%edi
call   1030 <putchar@plt>
mov    -0x38(%rbp),%rax
lea    -0x30(%rbp),%rcx
cmp    %rcx,%rax
ja     1199 <printkns+0x89>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printkns>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
test   %rdi,%rdi
jns    1130 <printkns+0x20>
mov    $0x2d,%edi
call   1030 <putchar@plt>
neg    %rbx
mov    %rsp,%rbp
movslq %r14d,%rcx
lea    0xec3(%rip),%rsi
jmp    115f <printkns+0x4f>
nop
mov    %rbx,%rax
cqto
idiv   %rcx
mov    %rax,%rbx
movzbl (%rdx,%rsi,1),%eax
mov    %al,0x0(%rbp)
add    $0x1,%rbp
and    $0xfffffff,%rbx
je     1176 <printkns+0x66>
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1140 <printkns+0x30>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %eax,%ebx
jmp    114b <printkns+0x3b>
mov    %rsp,%rbx
nopl   0x0(%rax)
movsbl -0x1(%rbp),%edi
add    $0xffffffffffffffff,%rbp
call   1030 <putchar@plt>
cmp    %rbx,%rbp
ja     1180 <printkns+0x70>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @printkns(i64 %0, i32 %1) {
%3 = alloca [24 x i8]
%4 = getelementptr inbounds [24 x i8], [24 x i8]* %3, i64 0, i64 0
%5 = icmp slt i64 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @putchar(i8 signext 45)
%8 = sub nsw i64 0, %0
br label %9
9: ; preds = %6, %2
%10 = phi i64 [ %8, %6 ], [ %0, %2 ]
%11 = sext i32 %1 to i64
br label %12
12: ; preds = %12, %9
%13 = phi i64 [ %10, %9 ], [ %20, %12 ]
%14 = phi i8* [ %4, %9 ], [ %18, %12 ]
%15 = srem i64 %13, %11
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %17, i8* %14
%19 = sdiv i64 %13, %11
%20 = and i64 %19, 268435455
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %12
22: ; preds = %12, %22
%23 = phi i8* [ %24, %22 ], [ %18, %12 ]
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = load i8, i8* %24
%26 = call i32 @putchar(i8 signext %25)
%27 = icmp ugt i8* %24, %4
br i1 %27, label %22, label %28
28: ; preds = %22
ret void
}