#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 */
size_t itoa(char *, int);
int /*<<< orphan*/ print(char *, size_t);
size_t print_d(size_t *maxrem, int dec) {
  char str[10];
  size_t written, len;
  written = 0;
  len = 0;
  if (dec < 0) {
    dec *= -1;
    if (!print("-", 1))
      return 0;
    written++;
  }
  len = itoa(str, dec);
  if (*maxrem < len) {
    return -1;
  }
  if (!print(str, len))
    return -1;
  written += len;
  return written;
}


x86 assembly (clang, -O0):
<print_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1183 <print_d+0x63>
imul   $0xffffffff,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x1,%esi
call   1030 <print@plt>
cmp    $0x0,%eax
jne    1177 <print_d+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11e8 <print_d+0xc8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    -0x1e(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <itoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x30(%rbp),%rax
jae    11b1 <print_d+0x91>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e8 <print_d+0xc8>
lea    -0x1e(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <print@plt>
cmp    $0x0,%eax
jne    11d4 <print_d+0xb4>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e8 <print_d+0xc8>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_d>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
js     1135 <print_d+0x15>
xor    %ebx,%ebx
jmp    1151 <print_d+0x31>
lea    0xec4(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
call   1030 <print@plt>
test   %eax,%eax
je     1187 <print_d+0x67>
neg    %ebp
lea    0x6(%rsp),%rdi
mov    %ebp,%esi
call   1040 <itoa@plt>
mov    %rax,%rbp
mov    $0xffffffffffffffff,%rax
cmp    %rbp,(%r14)
jb     1189 <print_d+0x69>
lea    0x6(%rsp),%rdi
mov    %rbp,%rsi
call   1030 <print@plt>
add    %rbp,%rbx
cmp    $0x1,%eax
sbb    %rax,%rax
or     %rbx,%rax
jmp    1189 <print_d+0x69>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
define i64 @print_d(i64* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i64*
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca i64
%8 = alloca i64
store i64* %0, i64** %4
store i32 %1, i32* %5
store i64 0, i64* %7
store i64 0, i64* %8
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i32, i32* %5
%13 = mul nsw i32 %12, -1
store i32 %13, i32* %5
%14 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %11
store i64 0, i64* %3
br label %40
17: ; preds = %11
%18 = load i64, i64* %7
%19 = add i64 %18, 1
store i64 %19, i64* %7
br label %20
20: ; preds = %17, %2
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i64 @itoa(i8* %21, i32 %22)
store i64 %23, i64* %8
%24 = load i64*, i64** %4
%25 = load i64, i64* %24
%26 = load i64, i64* %8
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %20
store i64 -1, i64* %3
br label %40
29: ; preds = %20
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%31 = load i64, i64* %8
%32 = call i32 @print(i8* %30, i64 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %29
store i64 -1, i64* %3
br label %40
35: ; preds = %29
%36 = load i64, i64* %8
%37 = load i64, i64* %7
%38 = add i64 %37, %36
store i64 %38, i64* %7
%39 = load i64, i64* %7
store i64 %39, i64* %3
br label %40
40: ; preds = %35, %34, %28, %16
%41 = load i64, i64* %3
ret i64 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define i64 @print_d(i64* nocapture %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = sub nsw i32 0, %1
br label %11
11: ; preds = %9, %2
%12 = phi i32 [ %10, %9 ], [ %1, %2 ]
%13 = phi i64 [ 1, %9 ], [ 0, %2 ]
%14 = call i64 @itoa(i8* %4, i32 %12)
%15 = load i64, i64* %0
%16 = icmp ult i64 %15, %14
br i1 %16, label %22, label %17
17: ; preds = %11
%18 = call i32 @print(i8* %4, i64 %14)
%19 = icmp eq i32 %18, 0
%20 = add i64 %14, %13
%21 = select i1 %19, i64 -1, i64 %20
br label %22
22: ; preds = %17, %11, %6
%23 = phi i64 [ 0, %6 ], [ -1, %11 ], [ %21, %17 ]
ret i64 %23
}