#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 */
long LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ errors(char *, int);
int /*<<< orphan*/ pprint(char const *, int);
int p_putnbr(long nb, int fd) {
  if (nb >= LONG_MAX || nb <= LONG_MIN)
    errors("putnbr: illegal value\n", 84);
  if (nb < 0) {
    pprint("-", fd);
    p_putnbr(nb * -1, fd);
  }
  if (nb >= 0 && nb <= 9) {
    nb = nb + '0';
    pprint((const char *)&nb, fd);
  } else if (nb > 9) {
    p_putnbr(nb / 10, fd);
    nb = (nb % 10) + '0';
    pprint((const char *)&nb, fd);
  }
  return (0);
}


x86 assembly (clang, -O0):
<p_putnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
jge    1167 <p_putnbr+0x37>
mov    -0x8(%rbp),%rax
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%rax
jg     1178 <p_putnbr+0x48>
lea    0xe92(%rip),%rdi
mov    $0x54,%esi
call   1050 <errors@plt>
cmpq   $0x0,-0x8(%rbp)
jge    119f <p_putnbr+0x6f>
mov    -0xc(%rbp),%esi
lea    0xe8a(%rip),%rdi
call   1040 <pprint@plt>
imul   $0xffffffffffffffff,-0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <p_putnbr@plt>
cmpq   $0x0,-0x8(%rbp)
jl     11d2 <p_putnbr+0xa2>
cmpq   $0x9,-0x8(%rbp)
jg     11d2 <p_putnbr+0xa2>
mov    -0x8(%rbp),%rax
add    $0x30,%rax
mov    %rax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <pprint@plt>
jmp    121d <p_putnbr+0xed>
cmpq   $0x9,-0x8(%rbp)
jle    1218 <p_putnbr+0xe8>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,%rdi
mov    -0xc(%rbp),%esi
call   1030 <p_putnbr@plt>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
add    $0x30,%rdx
mov    %rdx,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <pprint@plt>
jmp    121d <p_putnbr+0xed>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_putnbr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e93(%rip),%rax
cmp    %rdi,(%rax)
jle    1167 <p_putnbr+0x37>
mov    0x2e97(%rip),%rax
cmp    %rbx,(%rax)
jge    1167 <p_putnbr+0x37>
test   %rbx,%rbx
js     117d <p_putnbr+0x4d>
cmp    $0x9,%rbx
ja     119c <p_putnbr+0x6c>
add    $0x30,%rbx
jmp    11d3 <p_putnbr+0xa3>
lea    0xe92(%rip),%rdi
mov    $0x54,%esi
call   1050 <errors@plt>
test   %rbx,%rbx
jns    115b <p_putnbr+0x2b>
lea    0xe93(%rip),%rdi
mov    %r14d,%esi
call   1040 <pprint@plt>
neg    %rbx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <p_putnbr@plt>
jmp    11e5 <p_putnbr+0xb5>
movabs $0xcccccccccccccccd,%rcx
cc cc cc
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%rbp
shr    $0x3,%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
call   1030 <p_putnbr@plt>
add    %rbp,%rbp
lea    0x0(,%rbp,4),%rax
add    %rbp,%rax
sub    %rax,%rbx
or     $0x30,%rbx
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    %r14d,%esi
call   1040 <pprint@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str = [23 x i8] c"putnbr: illegal value\0A\00"
@.str.1 = [2 x i8] c"-\00"
define i32 @p_putnbr(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
%5 = load i64, i64* %3
%6 = load i64, i64* @LONG_MAX
%7 = icmp sge i64 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i64, i64* %3
%10 = load i64, i64* @LONG_MIN
%11 = icmp sle i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8, %2
%13 = call i32 @errors(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 84)
br label %14
14: ; preds = %12, %8
%15 = load i64, i64* %3
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %4
%19 = call i32 @pprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i64, i64* %3
%21 = mul nsw i64 %20, -1
%22 = load i32, i32* %4
%23 = call i32 @p_putnbr(i64 %21, i32 %22)
br label %24
24: ; preds = %17, %14
%25 = load i64, i64* %3
%26 = icmp sge i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i64, i64* %3
%29 = icmp sle i64 %28, 9
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i64, i64* %3
%32 = add nsw i64 %31, 48
store i64 %32, i64* %3
%33 = bitcast i64* %3 to i8*
%34 = load i32, i32* %4
%35 = call i32 @pprint(i8* %33, i32 %34)
br label %51
36: ; preds = %27, %24
%37 = load i64, i64* %3
%38 = icmp sgt i64 %37, 9
br i1 %38, label %39, label %50
39: ; preds = %36
%40 = load i64, i64* %3
%41 = sdiv i64 %40, 10
%42 = load i32, i32* %4
%43 = call i32 @p_putnbr(i64 %41, i32 %42)
%44 = load i64, i64* %3
%45 = srem i64 %44, 10
%46 = add nsw i64 %45, 48
store i64 %46, i64* %3
%47 = bitcast i64* %3 to i8*
%48 = load i32, i32* %4
%49 = call i32 @pprint(i8* %47, i32 %48)
br label %50
50: ; preds = %39, %36
br label %51
51: ; preds = %50, %30
ret i32 0
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str = [23 x i8] c"putnbr: illegal value\0A\00"
@.str.1 = [2 x i8] c"-\00"
define i32 @p_putnbr(i64 %0, i32 %1) {
%3 = alloca i64
%4 = load i64, i64* @LONG_MAX
%5 = icmp sgt i64 %4, %0
%6 = load i64, i64* @LONG_MIN
%7 = icmp slt i64 %6, %0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @errors(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 84)
br label %11
11: ; preds = %2, %9
%12 = icmp slt i64 %0, 0
br i1 %12, label %19, label %13
13: ; preds = %11
%14 = icmp ult i64 %0, 10
br i1 %14, label %15, label %24
15: ; preds = %13
%16 = add nuw nsw i64 %0, 48
store i64 %16, i64* %3
%17 = bitcast i64* %3 to i8*
%18 = call i32 @pprint(i8* %17, i32 %1)
br label %23
19: ; preds = %11
%20 = tail call i32 @pprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%21 = sub nsw i64 0, %0
%22 = tail call i32 @p_putnbr(i64 %21, i32 %1)
br label %23
23: ; preds = %19, %15, %24
ret i32 0
24: ; preds = %13
%25 = udiv i64 %0, 10
%26 = tail call i32 @p_putnbr(i64 %25, i32 %1)
%27 = urem i64 %0, 10
%28 = or i64 %27, 48
store i64 %28, i64* %3
%29 = bitcast i64* %3 to i8*
%30 = call i32 @pprint(i8* %29, i32 %1)
br label %23
}