#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*/ printf_c(char);
void printf_d(int i) {
  char buf[16];
  char *p = buf;
  if (i < 0) {
    printf_c('-');
    i *= -1;
  }
  while (i > 0 || p == buf) {
    *(p++) = (char)('0' + (i % 10));
    i /= 10;
  }
  while (p != buf) {
    printf_c(*(--p));
  }
}


x86 assembly (clang, -O0):
<printf_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    113e <printf_d+0x2e>
mov    $0x2d,%edi
call   1030 <printf_c@plt>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1143 <printf_d+0x33>
mov    $0x1,%al
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x29(%rbp)
jg     1163 <printf_d+0x53>
mov    -0x28(%rbp),%rax
lea    -0x20(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1173 <printf_d+0x63>
jmp    11a7 <printf_d+0x97>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1143 <printf_d+0x33>
jmp    11ac <printf_d+0x9c>
mov    -0x28(%rbp),%rax
lea    -0x20(%rbp),%rcx
cmp    %rcx,%rax
je     11da <printf_d+0xca>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movsbl -0x1(%rax),%edi
call   1030 <printf_c@plt>
jmp    11ac <printf_d+0x9c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_d>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
test   %edi,%edi
jns    112b <printf_d+0x1b>
mov    $0x2d,%edi
call   1030 <printf_c@plt>
neg    %r14d
xor    %ebx,%ebx
nopl   (%rax)
mov    %rbx,%rax
movslq %r14d,%rcx
imul   $0x66666667,%rcx,%r14
mov    %r14,%rdx
shr    $0x3f,%rdx
sar    $0x22,%r14
add    %edx,%r14d
lea    (%r14,%r14,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x9,%ecx
jg     1130 <printf_d+0x20>
cmp    $0xffffffffffffffff,%rax
je     1130 <printf_d+0x20>
nopl   (%rax)
movsbl -0x1(%rsp,%rbx,1),%edi
call   1030 <printf_c@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <printf_d+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @printf_d(i32 %0) {
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
store i8* %5, i8** %4
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32 @printf_c(i8 signext 45)
%10 = load i32, i32* %2
%11 = mul nsw i32 %10, -1
store i32 %11, i32* %2
br label %12
12: ; preds = %8, %1
br label %13
13: ; preds = %22, %12
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%19 = icmp eq i8* %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ true, %13 ], [ %19, %16 ]
br i1 %21, label %22, label %31
22: ; preds = %20
%23 = load i32, i32* %2
%24 = srem i32 %23, 10
%25 = add nsw i32 48, %24
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
store i8 %26, i8* %27
%29 = load i32, i32* %2
%30 = sdiv i32 %29, 10
store i32 %30, i32* %2
br label %13
31: ; preds = %20
br label %32
32: ; preds = %36, %31
%33 = load i8*, i8** %4
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%35 = icmp ne i8* %33, %34
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %4
%39 = load i8, i8* %38
%40 = call i32 @printf_c(i8 signext %39)
br label %32
41: ; preds = %32
ret void
}

LLVM IR (-O2):
define void @printf_d(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @printf_c(i8 signext 45)
%7 = sub nsw i32 0, %0
br label %8
8: ; preds = %5, %1
%9 = phi i32 [ %0, %1 ], [ %7, %5 ]
br label %10
10: ; preds = %8, %10
%11 = phi i8* [ %16, %10 ], [ %3, %8 ]
%12 = phi i32 [ %17, %10 ], [ %9, %8 ]
%13 = srem i32 %12, 10
%14 = trunc i32 %13 to i8
%15 = add nsw i8 %14, 48
%16 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %15, i8* %11
%17 = sdiv i32 %12, 10
%18 = icmp sgt i32 %12, 9
%19 = icmp eq i8* %16, %3
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %10, label %21
21: ; preds = %10, %21
%22 = phi i8* [ %23, %21 ], [ %16, %10 ]
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = load i8, i8* %23
%25 = call i32 @printf_c(i8 signext %24)
%26 = icmp eq i8* %23, %3
br i1 %26, label %27, label %21
27: ; preds = %21
ret void
}