#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*/ fputc(unsigned int, char);
int fputsn(unsigned int, char *, int);
int num_to_base(int, char *, int);
int print_dec(unsigned int channel, int num) {
  int digits;
  int negative = 0;
  char buffer[20];
  if (num < 0) {
    fputc(channel, '-');
    negative = 1;
    num *= -1;
  }
  digits = num_to_base(num, buffer, 10);
  return fputsn(channel, buffer, digits) + negative;
}


x86 assembly (clang, -O0):
<print_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    116a <print_dec+0x3a>
mov    -0x4(%rbp),%edi
mov    $0x2d,%esi
call   1050 <fputc@plt>
movl   $0x1,-0x10(%rbp)
imul   $0xffffffff,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1030 <num_to_base@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <fputsn@plt>
add    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_dec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %edi,%r14d
xor    %ebx,%ebx
test   %esi,%esi
jns    1159 <print_dec+0x29>
mov    %r14d,%edi
mov    $0x2d,%esi
call   1050 <fputc@plt>
neg    %ebp
mov    $0x1,%ebx
mov    %rsp,%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1030 <num_to_base@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <fputsn@plt>
add    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @print_dec(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [20 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* %3
%12 = call i32 @fputc(i32 %11, i8 signext 45)
store i32 1, i32* %6
%13 = load i32, i32* %4
%14 = mul nsw i32 %13, -1
store i32 %14, i32* %4
br label %15
15: ; preds = %10, %2
%16 = load i32, i32* %4
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%18 = call i32 @num_to_base(i32 %16, i8* %17, i32 10)
store i32 %18, i32* %5
%19 = load i32, i32* %3
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i32 @fputsn(i32 %19, i8* %20, i32 %21)
%23 = load i32, i32* %6
%24 = add nsw i32 %22, %23
ret i32 %24
}

LLVM IR (-O2):
define i32 @print_dec(i32 %0, i32 %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %1, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @fputc(i32 %0, i8 signext 45)
%8 = sub nsw i32 0, %1
br label %9
9: ; preds = %6, %2
%10 = phi i32 [ %8, %6 ], [ %1, %2 ]
%11 = phi i32 [ 1, %6 ], [ 0, %2 ]
%12 = call i32 @num_to_base(i32 %10, i8* %4, i32 10)
%13 = call i32 @fputsn(i32 %0, i8* %4, i32 %12)
%14 = add nsw i32 %13, %11
ret i32 %14
}