#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*/ debug_putc(int);
void debug_putd(int n) {
  bool leading = true;
  if (n == 0) {
    debug_putc('0');
    return;
  }
  if (n & 0x80000000) {
    n = ~n + 1;
    debug_putc('-');
  }
  for (unsigned int i = 1000000000; i > 0; i /= 10) {
    if (n / i == 0 && !leading)
      debug_putc('0');
    else if (n / i != 0) {
      debug_putc('0' + (n / i));
      n %= i;
      leading = false;
    }
  }
}


x86 assembly (clang, -O0):
<debug_putd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    113b <debug_putd+0x2b>
mov    $0x30,%edi
call   1030 <debug_putc@plt>
jmp    11f2 <debug_putd+0xe2>
mov    -0x4(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     1162 <debug_putd+0x52>
mov    -0x4(%rbp),%eax
xor    $0xffffffff,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x2d,%edi
call   1030 <debug_putc@plt>
movl   $0x3b9aca00,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    11f2 <debug_putd+0xe2>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
cmp    $0x0,%eax
jne    119d <debug_putd+0x8d>
cmpl   $0x0,-0x8(%rbp)
jne    119d <debug_putd+0x8d>
mov    $0x30,%edi
call   1030 <debug_putc@plt>
jmp    11d9 <debug_putd+0xc9>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
cmp    $0x0,%eax
je     11d4 <debug_putd+0xc4>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    %eax,%edi
add    $0x30,%edi
call   1030 <debug_putc@plt>
mov    -0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    11d9 <debug_putd+0xc9>
jmp    11de <debug_putd+0xce>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
jmp    1169 <debug_putd+0x59>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_putd>:
test   %edi,%edi
je     118e <debug_putd+0x7e>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
jns    112b <debug_putd+0x1b>
neg    %ebx
mov    $0x2d,%edi
call   1030 <debug_putc@plt>
mov    $0x1,%ecx
mov    $0x3b9aca00,%ebp
mov    $0xcccccccd,%r15d
jmp    115d <debug_putd+0x4d>
nopl   (%rax)
mov    $0x30,%edi
call   1030 <debug_putc@plt>
xor    %ecx,%ecx
mov    %ebp,%eax
imul   %r15,%rax
shr    $0x23,%rax
cmp    $0x9,%ebp
mov    %eax,%ebp
jbe    1183 <debug_putd+0x73>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,%r14d
cmp    %ebx,%ebp
jbe    116e <debug_putd+0x5e>
test   %ecx,%ecx
je     1140 <debug_putd+0x30>
cmp    %ebx,%ebp
ja     114c <debug_putd+0x3c>
add    $0x30,%eax
mov    %eax,%edi
call   1030 <debug_putc@plt>
xor    %ecx,%ecx
mov    %r14d,%ebx
jmp    114c <debug_putd+0x3c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x30,%edi
jmp    1030 <debug_putc@plt>

LLVM IR (-O0):
define void @debug_putd(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @debug_putc(i32 48)
br label %51
9: ; preds = %1
%10 = load i32, i32* %2
%11 = and i32 %10, -2147483648
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* %2
%15 = xor i32 %14, -1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
%17 = call i32 @debug_putc(i32 45)
br label %18
18: ; preds = %13, %9
store i32 1000000000, i32* %4
br label %19
19: ; preds = %48, %18
%20 = load i32, i32* %4
%21 = icmp ugt i32 %20, 0
br i1 %21, label %22, label %51
22: ; preds = %19
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = udiv i32 %23, %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @debug_putc(i32 48)
br label %47
32: ; preds = %27, %22
%33 = load i32, i32* %2
%34 = load i32, i32* %4
%35 = udiv i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %32
%38 = load i32, i32* %2
%39 = load i32, i32* %4
%40 = udiv i32 %38, %39
%41 = add i32 48, %40
%42 = call i32 @debug_putc(i32 %41)
%43 = load i32, i32* %4
%44 = load i32, i32* %2
%45 = urem i32 %44, %43
store i32 %45, i32* %2
store i32 0, i32* %3
br label %46
46: ; preds = %37, %32
br label %47
47: ; preds = %46, %30
br label %48
48: ; preds = %47
%49 = load i32, i32* %4
%50 = udiv i32 %49, 10
store i32 %50, i32* %4
br label %19
51: ; preds = %7, %19
ret void
}

LLVM IR (-O2):
define void @debug_putd(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @debug_putc(i32 48)
br label %32
5: ; preds = %1
%6 = icmp sgt i32 %0, -1
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = sub i32 0, %0
%9 = tail call i32 @debug_putc(i32 45)
br label %10
10: ; preds = %7, %5
%11 = phi i32 [ %0, %5 ], [ %8, %7 ]
br label %12
12: ; preds = %10, %27
%13 = phi i32 [ %30, %27 ], [ 1000000000, %10 ]
%14 = phi i32 [ %29, %27 ], [ 1, %10 ]
%15 = phi i32 [ %28, %27 ], [ %11, %10 ]
%16 = udiv i32 %15, %13
%17 = urem i32 %15, %13
%18 = icmp ule i32 %13, %15
%19 = icmp ne i32 %14, 0
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %23, label %21
21: ; preds = %12
%22 = tail call i32 @debug_putc(i32 48)
br label %27
23: ; preds = %12
br i1 %18, label %24, label %27
24: ; preds = %23
%25 = add i32 %16, 48
%26 = tail call i32 @debug_putc(i32 %25)
br label %27
27: ; preds = %21, %24, %23
%28 = phi i32 [ %17, %24 ], [ %15, %23 ], [ %15, %21 ]
%29 = phi i32 [ 0, %24 ], [ %14, %23 ], [ 0, %21 ]
%30 = udiv i32 %13, 10
%31 = icmp ult i32 %13, 10
br i1 %31, label %32, label %12
32: ; preds = %27, %3
ret void
}