#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*/ printc(char);
void printd(int x) {
  char digit[10] = "0123456789";
  char buffer[10];
  if (x < 0) {
    printc('-');
    x = -x;
  }
  if (x == 0) {
    printc('0');
    return;
  }
  int i = 0;
  while (x) {
    buffer[i++] = digit[x % 10];
    x /= 10;
  }
  while (i) {
    printc(buffer[--i]);
  }
}


x86 assembly (clang, -O0):
<printd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0xe(%rbp)
mov    0xedb(%rip),%ax
mov    %ax,-0x6(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    114d <printd+0x3d>
mov    $0x2d,%edi
call   1030 <printc@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1166 <printd+0x56>
mov    $0x30,%edi
call   1030 <printc@plt>
jmp    11d6 <printd+0xc6>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11ad <printd+0x9d>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0xe(%rbp,%rax,1),%cl
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
cltq
mov    %cl,-0x18(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    116d <printd+0x5d>
jmp    11b2 <printd+0xa2>
cmpl   $0x0,-0x1c(%rbp)
je     11d6 <printd+0xc6>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cltq
movsbl -0x18(%rbp,%rax,1),%edi
call   1030 <printc@plt>
jmp    11b2 <printd+0xa2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printd>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
test   %edi,%edi
js     1134 <printd+0x24>
jne    1140 <printd+0x30>
mov    $0x30,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printc@plt>
mov    $0x2d,%edi
call   1030 <printc@plt>
neg    %ebx
xor    %r14d,%r14d
lea    0xeb6(%rip),%rax
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rcx
imul   $0x66666667,%rcx,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rbx
add    %edx,%ebx
lea    (%rbx,%rbx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
movslq %esi,%rdx
movzbl (%rdx,%rax,1),%edx
mov    %dl,0x6(%rsp,%r14,1)
add    $0x1,%r14
add    $0x9,%ecx
cmp    $0x13,%ecx
jae    1150 <printd+0x40>
movslq %r14d,%rax
lea    (%rsp,%rax,1),%r15
add    $0x5,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <printc@plt>
lea    -0x1(%rbx),%rax
add    %r14d,%ebx
cmp    $0x1,%ebx
mov    %rax,%rbx
jne    11a0 <printd+0x90>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.printd.digit = [10 x i8] c"0123456789"
define void @printd(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 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 @printc(i8 signext 45)
%7 = sub nsw i32 0, %0
br label %10
8: ; preds = %1
%9 = icmp eq i32 %0, 0
br i1 %9, label %12, label %10
10: ; preds = %5, %8
%11 = phi i32 [ %0, %8 ], [ %7, %5 ]
br label %17
12: ; preds = %8
%13 = tail call i32 @printc(i8 signext 48)
br label %37
14: ; preds = %17
%15 = shl i64 %24, 32
%16 = ashr exact i64 %15, 32
br label %29
17: ; preds = %10, %17
%18 = phi i64 [ %24, %17 ], [ 0, %10 ]
%19 = phi i32 [ %26, %17 ], [ %11, %10 ]
%20 = srem i32 %19, 10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [10 x i8], [10 x i8]* @__const.printd.digit, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = add nuw i64 %18, 1
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %18
store i8 %23, i8* %25
%26 = sdiv i32 %19, 10
%27 = add i32 %19, 9
%28 = icmp ult i32 %27, 19
br i1 %28, label %14, label %17
29: ; preds = %14, %29
%30 = phi i64 [ %16, %14 ], [ %31, %29 ]
%31 = add nsw i64 %30, -1
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = tail call i32 @printc(i8 signext %33)
%35 = trunc i64 %31 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %29
37: ; preds = %29, %12
ret void
}