#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ printn2(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int printn(FILE *restrict fp, int n, int b, int sign) {
  int cnt = 0;
  if (sign && n < 0) {
    n = -n;
    putc('-', fp);
    ++cnt;
  }
  cnt += printn2(fp, n, b);
  return cnt;
}


x86 assembly (clang, -O0):
<printn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     116f <printn+0x4f>
cmpl   $0x0,-0xc(%rbp)
jge    116f <printn+0x4f>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x2d,%edi
call   1040 <putc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <printn2@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
xor    %ebx,%ebx
test   %esi,%esi
jns    114d <printn+0x2d>
test   %ecx,%ecx
je     114d <printn+0x2d>
neg    %ebp
mov    $0x2d,%edi
mov    %r15,%rsi
call   1040 <putc@plt>
mov    $0x1,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <printn2@plt>
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @printn(i32* noalias %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %4
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %6
%17 = sub nsw i32 0, %16
store i32 %17, i32* %6
%18 = load i32*, i32** %5
%19 = call i32 @putc(i8 signext 45, i32* %18)
%20 = load i32, i32* %9
%21 = add nsw i32 %20, 1
store i32 %21, i32* %9
br label %22
22: ; preds = %15, %12, %4
%23 = load i32*, i32** %5
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = call i64 @printn2(i32* %23, i32 %24, i32 %25)
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %9
%31 = load i32, i32* %9
ret i32 %31
}

LLVM IR (-O2):
define i32 @printn(i32* noalias %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp ne i32 %3, 0
%6 = icmp slt i32 %1, 0
%7 = and i1 %6, %5
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = sub nsw i32 0, %1
%10 = tail call i32 @putc(i8 signext 45, i32* %0)
br label %11
11: ; preds = %8, %4
%12 = phi i32 [ %9, %8 ], [ %1, %4 ]
%13 = phi i64 [ 1, %8 ], [ 0, %4 ]
%14 = tail call i64 @printn2(i32* %0, i32 %12, i32 %2)
%15 = add nsw i64 %14, %13
%16 = trunc i64 %15 to i32
ret i32 %16
}