#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 printDigit(int n) {
  if (n < 10) {
    putchar("0123456789"[n]);
  } else {
    putchar("0123456789"[n % 10]);
    printDigit(n / 10);
  }
}


x86 assembly (clang, -O0):
<printDigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    114e <printDigit+0x2e>
movslq -0x4(%rbp),%rcx
lea    0xec0(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    117e <printDigit+0x5e>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xe9d(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <printDigit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printDigit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
cmp    $0xa,%edi
jge    1122 <printDigit+0x12>
mov    %ebp,%ebx
jmp    1155 <printDigit+0x45>
mov    $0xcccccccd,%r14d
lea    0xed1(%rip),%r15
nop
mov    %ebp,%ebx
imul   %r14,%rbx
shr    $0x23,%rbx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
movsbl (%rcx,%r15,1),%edi
call   1030 <putchar@plt>
cmp    $0x64,%ebp
mov    %ebx,%ebp
jae    1130 <printDigit+0x20>
movslq %ebx,%rax
lea    0xea1(%rip),%rcx
movsbl (%rax,%rcx,1),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define void @printDigit(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 10
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = call i32 @putchar(i8 signext %9)
br label %20
11: ; preds = %1
%12 = load i32, i32* %2
%13 = srem i32 %12, 10
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @putchar(i8 signext %16)
%18 = load i32, i32* %2
%19 = sdiv i32 %18, 10
br label %20
20: ; preds = %11, %5
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define void @printDigit(i32 %0) {
%2 = icmp slt i32 %0, 10
br i1 %2, label %3, label %9
3: ; preds = %9, %1
%4 = phi i32 [ %0, %1 ], [ %16, %9 ]
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i32 @putchar(i8 signext %7)
ret void
9: ; preds = %1, %9
%10 = phi i32 [ %16, %9 ], [ %0, %1 ]
%11 = urem i32 %10, 10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @putchar(i8 signext %14)
%16 = udiv i32 %10, 10
%17 = icmp ult i32 %10, 100
br i1 %17, label %3, label %9
}