#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*/ kprint(char *);
int /*<<< orphan*/ kprintc(char);
int power(int, int);
void kprintx(int value) {
  kprint("0x");
  int divisor = power(16, 7);
  for (int i = 0; i < 8; i++) {
    short digit = value / divisor;
    value %= divisor;
    divisor /= 16;
    if (digit < 10)
      kprintc((char)(digit + 48));
    else
      kprintc((char)(digit + 55));
  }
}


x86 assembly (clang, -O0):
<kprintx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
call   1050 <kprint@plt>
mov    $0x10,%edi
mov    $0x7,%esi
call   1030 <power@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11d2 <kprintx+0xa2>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
movswl -0xe(%rbp),%eax
cmp    $0xa,%eax
jge    11b0 <kprintx+0x80>
movswl -0xe(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1040 <kprintc@plt>
jmp    11bf <kprintx+0x8f>
movswl -0xe(%rbp),%eax
add    $0x37,%eax
movsbl %al,%edi
call   1040 <kprintc@plt>
jmp    11c4 <kprintx+0x94>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1160 <kprintx+0x30>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kprintx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xebc(%rip),%rdi
call   1050 <kprint@plt>
mov    $0x10,%edi
mov    $0x7,%esi
call   1030 <power@plt>
mov    %eax,%ecx
lea    0xfffffff(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
mov    %eax,0x4(%rsp)
lea    0xffffff(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
mov    %eax,(%rsp)
lea    0xfffff(%rcx),%ebp
test   %ecx,%ecx
cmovns %ecx,%ebp
lea    0xffff(%rcx),%r12d
test   %ecx,%ecx
cmovns %ecx,%r12d
lea    0xfff(%rcx),%r14d
test   %ecx,%ecx
cmovns %ecx,%r14d
lea    0xff(%rcx),%r15d
test   %ecx,%ecx
cmovns %ecx,%r15d
lea    0xf(%rcx),%r13d
test   %ecx,%ecx
cmovns %ecx,%r13d
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %edx,%ebx
sar    $0x4,%r13d
cmp    $0xa,%ax
mov    $0x30,%edx
mov    $0x37,%ecx
cmovl  %edx,%ecx
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %r13d
mov    %edx,%ebx
sar    $0x8,%r15d
cmp    $0xa,%ax
mov    $0x37,%ecx
mov    $0x30,%r13d
cmovl  %r13d,%ecx
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %r15d
mov    %edx,%ebx
sar    $0xc,%r14d
cmp    $0xa,%ax
mov    $0x37,%ecx
cmovl  %r13d,%ecx
mov    $0x30,%r15d
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %r14d
mov    %edx,%ebx
sar    $0x10,%r12d
cmp    $0xa,%ax
mov    $0x37,%ecx
cmovl  %r15d,%ecx
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %r12d
mov    %edx,%ebx
sar    $0x14,%ebp
cmp    $0xa,%ax
mov    $0x37,%ecx
cmovl  %r15d,%ecx
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %edx,%ebx
mov    (%rsp),%ebp
sar    $0x18,%ebp
cmp    $0xa,%ax
mov    $0x37,%ecx
cmovl  %r15d,%ecx
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %edx,%ebx
mov    0x4(%rsp),%ebp
sar    $0x1c,%ebp
cmp    $0xa,%ax
mov    $0x37,%ecx
cmovl  %r15d,%ecx
add    %al,%cl
movsbl %cl,%edi
call   1040 <kprintc@plt>
mov    %ebx,%eax
cltd
idiv   %ebp
cmp    $0xa,%ax
mov    $0x37,%ecx
cmovl  %r15d,%ecx
add    %al,%cl
movsbl %cl,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <kprintc@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
define void @kprintx(i32 %0) {
%2 = tail call i32 @kprint(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @power(i32 16, i32 7)
%4 = sdiv i32 %0, %3
%5 = srem i32 %0, %3
%6 = sdiv i32 %3, 16
%7 = trunc i32 %4 to i16
%8 = icmp slt i16 %7, 10
%9 = trunc i32 %4 to i8
%10 = select i1 %8, i8 48, i8 55
%11 = add i8 %10, %9
%12 = tail call i32 @kprintc(i8 signext %11)
%13 = sdiv i32 %5, %6
%14 = srem i32 %5, %6
%15 = sdiv i32 %3, 256
%16 = trunc i32 %13 to i16
%17 = icmp slt i16 %16, 10
%18 = trunc i32 %13 to i8
%19 = select i1 %17, i8 48, i8 55
%20 = add i8 %19, %18
%21 = tail call i32 @kprintc(i8 signext %20)
%22 = sdiv i32 %14, %15
%23 = srem i32 %14, %15
%24 = sdiv i32 %3, 4096
%25 = trunc i32 %22 to i16
%26 = icmp slt i16 %25, 10
%27 = trunc i32 %22 to i8
%28 = select i1 %26, i8 48, i8 55
%29 = add i8 %28, %27
%30 = tail call i32 @kprintc(i8 signext %29)
%31 = sdiv i32 %23, %24
%32 = srem i32 %23, %24
%33 = sdiv i32 %3, 65536
%34 = trunc i32 %31 to i16
%35 = icmp slt i16 %34, 10
%36 = trunc i32 %31 to i8
%37 = select i1 %35, i8 48, i8 55
%38 = add i8 %37, %36
%39 = tail call i32 @kprintc(i8 signext %38)
%40 = sdiv i32 %32, %33
%41 = srem i32 %32, %33
%42 = sdiv i32 %3, 1048576
%43 = trunc i32 %40 to i16
%44 = icmp slt i16 %43, 10
%45 = trunc i32 %40 to i8
%46 = select i1 %44, i8 48, i8 55
%47 = add i8 %46, %45
%48 = tail call i32 @kprintc(i8 signext %47)
%49 = sdiv i32 %41, %42
%50 = srem i32 %41, %42
%51 = sdiv i32 %3, 16777216
%52 = trunc i32 %49 to i16
%53 = icmp slt i16 %52, 10
%54 = trunc i32 %49 to i8
%55 = select i1 %53, i8 48, i8 55
%56 = add i8 %55, %54
%57 = tail call i32 @kprintc(i8 signext %56)
%58 = sdiv i32 %50, %51
%59 = srem i32 %50, %51
%60 = sdiv i32 %3, 268435456
%61 = trunc i32 %58 to i16
%62 = icmp slt i16 %61, 10
%63 = trunc i32 %58 to i8
%64 = select i1 %62, i8 48, i8 55
%65 = add i8 %64, %63
%66 = tail call i32 @kprintc(i8 signext %65)
%67 = sdiv i32 %59, %60
%68 = trunc i32 %67 to i16
%69 = icmp slt i16 %68, 10
%70 = trunc i32 %67 to i8
%71 = select i1 %69, i8 48, i8 55
%72 = add i8 %71, %70
%73 = tail call i32 @kprintc(i8 signext %72)
ret void
}