#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*/ drawHundreds(int);
int /*<<< orphan*/ drawOnes(int);
int /*<<< orphan*/ drawTens(int);
int /*<<< orphan*/ drawThousands(int);
void draw(int v) {
  int thousands = v / 1000;
  v %= 1000;
  int hundreds = v / 100;
  v %= 100;
  int tens = v / 10;
  int ones = v % 10;
  if (thousands > 0) {
    drawThousands(thousands);
  }
  if (hundreds > 0) {
    drawHundreds(hundreds);
  }
  if (tens > 0) {
    drawTens(tens);
  }
  if (ones > 0) {
    drawOnes(ones);
  }
}


x86 assembly (clang, -O0):
<draw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11b1 <draw+0x71>
mov    -0x8(%rbp),%edi
call   1040 <drawThousands@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11c3 <draw+0x83>
mov    -0xc(%rbp),%edi
call   1050 <drawHundreds@plt>
cmpl   $0x0,-0x10(%rbp)
jle    11d5 <draw+0x95>
mov    -0x10(%rbp),%edi
call   1060 <drawTens@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11e7 <draw+0xa7>
mov    -0x14(%rbp),%edi
call   1030 <drawOnes@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
mov    %eax,%r14d
sub    %ecx,%r14d
movswl %r14w,%ecx
imul   $0x147b,%ecx,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x13,%ebx
add    %ecx,%ebx
imul   $0x64,%ebx,%ecx
mov    %r14d,%r12d
sub    %ecx,%r12d
mov    %r12d,%r15d
movsbl %r15b,%ecx
imul   $0x67,%ecx,%ecx
movzwl %cx,%ecx
movswl %cx,%ebp
shr    $0xf,%ecx
shr    $0xa,%ebp
add    %cl,%bpl
movzbl %bpl,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%r13d
cmp    $0x3e8,%eax
jl     11c7 <draw+0x87>
mov    %edi,%eax
imul   $0x10624dd3,%rax,%rdi
shr    $0x26,%rdi
call   1040 <drawThousands@plt>
cmp    $0x64,%r14d
jl     11d4 <draw+0x94>
mov    %ebx,%edi
call   1050 <drawHundreds@plt>
sub    %r13b,%r12b
cmp    $0xa,%r15w
jl     11e7 <draw+0xa7>
movsbl %bpl,%edi
call   1060 <drawTens@plt>
test   %r12b,%r12b
jle    1203 <draw+0xc3>
movsbl %r12b,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <drawOnes@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @draw(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = sdiv i32 %7, 1000
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = srem i32 %9, 1000
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = sdiv i32 %11, 100
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = srem i32 %13, 100
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 10
store i32 %16, i32* %5
%17 = load i32, i32* %2
%18 = srem i32 %17, 10
store i32 %18, i32* %6
%19 = load i32, i32* %3
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %1
%22 = load i32, i32* %3
%23 = call i32 @drawThousands(i32 %22)
br label %24
24: ; preds = %21, %1
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %4
%29 = call i32 @drawHundreds(i32 %28)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %5
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %5
%35 = call i32 @drawTens(i32 %34)
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %6
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %6
%41 = call i32 @drawOnes(i32 %40)
br label %42
42: ; preds = %39, %36
ret void
}

LLVM IR (-O2):
define void @draw(i32 %0) {
%2 = srem i32 %0, 1000
%3 = trunc i32 %2 to i16
%4 = sdiv i16 %3, 100
%5 = sext i16 %4 to i32
%6 = srem i16 %3, 100
%7 = trunc i16 %6 to i8
%8 = sdiv i8 %7, 10
%9 = sext i8 %8 to i32
%10 = srem i8 %7, 10
%11 = sext i8 %10 to i32
%12 = icmp sgt i32 %0, 999
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = udiv i32 %0, 1000
%15 = tail call i32 @drawThousands(i32 %14)
br label %16
16: ; preds = %13, %1
%17 = icmp sgt i32 %2, 99
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @drawHundreds(i32 %5)
br label %20
20: ; preds = %18, %16
%21 = icmp sgt i16 %6, 9
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @drawTens(i32 %9)
br label %24
24: ; preds = %22, %20
%25 = icmp sgt i8 %10, 0
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = tail call i32 @drawOnes(i32 %11)
br label %28
28: ; preds = %26, %24
ret void
}