#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*/ kprintc(char);
short no_of_digits(int);
scalar_t__ power(int, short);
void kprinti(int value) {
  short digits = no_of_digits(value);
  int divisor = (int)power(10, digits - 1);
  for (int i = divisor; i > 0; i /= 10) {
    short digit = value / i;
    value %= i;
    kprintc((char)(digit + 48));
  }
}


x86 assembly (clang, -O0):
<kprinti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <no_of_digits@plt>
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
sub    $0x1,%eax
mov    $0xa,%edi
movswl %ax,%esi
call   1030 <power@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11a7 <kprinti+0x77>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
movswl -0x12(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1040 <kprintc@plt>
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1164 <kprinti+0x34>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kprinti>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
call   1050 <no_of_digits@plt>
add    $0xffffffff,%eax
movswl %ax,%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %rax,%rbx
test   %ebx,%ebx
jle    1182 <kprinti+0x52>
mov    $0xcccccccd,%r14d
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
cltd
idiv   %ebx
add    $0x30,%al
movsbl %al,%edi
mov    %edx,%ebp
call   1040 <kprintc@plt>
mov    %ebx,%eax
imul   %r14,%rax
shr    $0x23,%rax
cmp    $0xa,%ebx
mov    %eax,%ebx
jae    1160 <kprinti+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @kprinti(i32 %0) {
%2 = alloca i32
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call signext i16 @no_of_digits(i32 %7)
store i16 %8, i16* %3
%9 = load i16, i16* %3
%10 = sext i16 %9 to i32
%11 = sub nsw i32 %10, 1
%12 = trunc i32 %11 to i16
%13 = call i64 @power(i32 10, i16 signext %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %4
%15 = load i32, i32* %4
store i32 %15, i32* %5
br label %16
16: ; preds = %32, %1
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %16
%20 = load i32, i32* %2
%21 = load i32, i32* %5
%22 = sdiv i32 %20, %21
%23 = trunc i32 %22 to i16
store i16 %23, i16* %6
%24 = load i32, i32* %5
%25 = load i32, i32* %2
%26 = srem i32 %25, %24
store i32 %26, i32* %2
%27 = load i16, i16* %6
%28 = sext i16 %27 to i32
%29 = add nsw i32 %28, 48
%30 = trunc i32 %29 to i8
%31 = call i32 @kprintc(i8 signext %30)
br label %32
32: ; preds = %19
%33 = load i32, i32* %5
%34 = sdiv i32 %33, 10
store i32 %34, i32* %5
br label %16
35: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @kprinti(i32 %0) {
%2 = tail call signext i16 @no_of_digits(i32 %0)
%3 = add i16 %2, -1
%4 = tail call i64 @power(i32 10, i16 signext %3)
%5 = trunc i64 %4 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %8, label %7
7: ; preds = %8, %1
ret void
8: ; preds = %1, %8
%9 = phi i32 [ %12, %8 ], [ %0, %1 ]
%10 = phi i32 [ %16, %8 ], [ %5, %1 ]
%11 = sdiv i32 %9, %10
%12 = srem i32 %9, %10
%13 = trunc i32 %11 to i8
%14 = add i8 %13, 48
%15 = tail call i32 @kprintc(i8 signext %14)
%16 = udiv i32 %10, 10
%17 = icmp ult i32 %10, 10
br i1 %17, label %7, label %8
}