#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(int);
void putn(int n) {
  int ns[16] = {0, n % 10}, nd = 1;
  while (n /= 10)
    ns[++nd] = n % 10;
  while (nd)
    putchar(ns[nd--] + '0');
}


x86 assembly (clang, -O0):
<putn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4c(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1186 <putn+0x66>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
cltq
mov    %edx,-0x50(%rbp,%rax,4)
jmp    1150 <putn+0x30>
jmp    118b <putn+0x6b>
cmpl   $0x0,-0x54(%rbp)
je     11b3 <putn+0x93>
mov    -0x54(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x54(%rbp)
cltq
mov    -0x50(%rbp,%rax,4),%edi
add    $0x30,%edi
call   1030 <putchar@plt>
jmp    118b <putn+0x6b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putn>:
push   %rbx
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
mov    %edx,0x4(%rsp)
add    $0x9,%eax
mov    $0x1,%ebx
cmp    $0x13,%eax
jb     11d0 <putn+0xc0>
movabs $0x100000000,%r8
lea    0x8(%rsp),%r9
mov    %r8,%rbx
xchg   %ax,%ax
movslq %edi,%rdx
imul   $0x66666667,%rdx,%rdx
mov    %rdx,%r10
shr    $0x3f,%r10
sar    $0x22,%rdx
lea    (%rdx,%r10,1),%edi
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rcx
add    %esi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,(%r9)
lea    (%rdx,%r10,1),%eax
add    $0x9,%eax
add    %r8,%rbx
add    $0x4,%r9
cmp    $0x13,%eax
jae    1170 <putn+0x60>
sar    $0x20,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp,%rbx,4),%edi
add    $0xffffffffffffffff,%rbx
add    $0x30,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
jne    11d0 <putn+0xc0>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @putn(i32 %0) {
%2 = alloca i32
%3 = alloca [16 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [16 x i32]* %3 to i8*
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %2
%9 = srem i32 %8, 10
store i32 %9, i32* %7
store i32 1, i32* %4
br label %10
10: ; preds = %14, %1
%11 = load i32, i32* %2
%12 = sdiv i32 %11, 10
store i32 %12, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i32, i32* %2
%16 = srem i32 %15, 10
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %19
store i32 %16, i32* %20
br label %10
21: ; preds = %10
br label %22
22: ; preds = %25, %21
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 48
%32 = call i32 @putchar(i32 %31)
br label %22
33: ; preds = %22
ret void
}

LLVM IR (-O2):
define void @putn(i32 %0) {
%2 = alloca [16 x i32]
%3 = bitcast [16 x i32]* %2 to i8*
%4 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 1
%5 = srem i32 %0, 10
store i32 %5, i32* %4
%6 = add i32 %0, 9
%7 = icmp ult i32 %6, 19
br i1 %7, label %8, label %13
8: ; preds = %10, %1
%9 = phi i64 [ %12, %10 ], [ 1, %1 ]
br label %22
10: ; preds = %13
%11 = shl i64 %18, 32
%12 = ashr exact i64 %11, 32
br label %8
13: ; preds = %1, %13
%14 = phi i64 [ %18, %13 ], [ 1, %1 ]
%15 = phi i32 [ %16, %13 ], [ %0, %1 ]
%16 = sdiv i32 %15, 10
%17 = srem i32 %16, 10
%18 = add nuw nsw i64 %14, 1
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %18
store i32 %17, i32* %19
%20 = add nsw i32 %16, 9
%21 = icmp ult i32 %20, 19
br i1 %21, label %10, label %13
22: ; preds = %8, %22
%23 = phi i64 [ %24, %22 ], [ %9, %8 ]
%24 = add nsw i64 %23, -1
%25 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %23
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 48
%28 = tail call i32 @putchar(i32 %27)
%29 = trunc i64 %24 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %22
31: ; preds = %22
ret void
}