#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*/ putstr(char *);
void print_dec(int num) {
  char buf[12];
  int i = 12;
  buf[--i] = '\0';
  while (num) {
    buf[--i] = (num % 10) + '0';
    num /= 10;
  }
  putstr(&buf[i]);
}


x86 assembly (clang, -O0):
<print_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xc,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cltq
movb   $0x0,-0x10(%rbp,%rax,1)
cmpl   $0x0,-0x4(%rbp)
je     116e <print_dec+0x5e>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cltq
mov    %cl,-0x10(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1132 <print_dec+0x22>
movslq -0x14(%rbp),%rax
lea    -0x10(%rbp),%rdi
add    %rax,%rdi
call   1030 <putstr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_dec>:
sub    $0x18,%rsp
movb   $0x0,0x17(%rsp)
test   %edi,%edi
je     117d <print_dec+0x6d>
lea    0x16(%rsp),%rcx
movabs $0xb00000000,%rax
movabs $0xffffffff00000000,%r8
ff ff ff
cs nopw 0x0(%rax,%rax,1)
add    %r8,%rax
movslq %edi,%rsi
imul   $0x66666667,%rsi,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%r9d
mov    %esi,%edx
sub    %r9d,%edx
add    $0x30,%dl
mov    %dl,(%rcx)
add    $0x9,%esi
add    $0xffffffffffffffff,%rcx
cmp    $0x12,%esi
ja     1140 <print_dec+0x30>
sar    $0x20,%rax
jmp    1182 <print_dec+0x72>
mov    $0xb,%eax
lea    (%rsp,%rax,1),%rdi
add    $0xc,%rdi
call   1030 <putstr@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @print_dec(i32 %0) {
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca i32
store i32 %0, i32* %2
store i32 12, i32* %4
%5 = load i32, i32* %4
%6 = add nsw i32 %5, -1
store i32 %6, i32* %4
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %7
store i8 0, i8* %8
br label %9
9: ; preds = %12, %1
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %2
%14 = srem i32 %13, 10
%15 = add nsw i32 %14, 48
%16 = trunc i32 %15 to i8
%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 [12 x i8], [12 x i8]* %3, i64 0, i64 %19
store i8 %16, i8* %20
%21 = load i32, i32* %2
%22 = sdiv i32 %21, 10
store i32 %22, i32* %2
br label %9
23: ; preds = %9
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 %25
%27 = call i32 @putstr(i8* %26)
ret void
}

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