#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*/ write(int, char *, int);
void ft_putnbr(int n) {
  char c;
  long num;
  long trunc;
  trunc = 10;
  num = n;
  (n < 0) ? (num = -(long)(n)) : 0;
  while ((num /= 10) >= 1)
    trunc *= 10;
  num = n;
  (n < 0) ? (num = -(long)(n)) : 0;
  (n < 0) ? write(1, "-", 1) : 0;
  while ((trunc /= 10) >= 1) {
    c = num / trunc + '0';
    num %= trunc;
    write(1, &c, 1);
  }
}


x86 assembly (clang, -O0):
<ft_putnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0xa,-0x18(%rbp)
movslq -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1147 <ft_putnbr+0x37>
movslq -0x4(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <ft_putnbr+0x3c>
jmp    114c <ft_putnbr+0x3c>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
cmp    $0x1,%rax
jl     1176 <ft_putnbr+0x66>
imul   $0xa,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    114c <ft_putnbr+0x3c>
movslq -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    119a <ft_putnbr+0x8a>
movslq -0x4(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    119f <ft_putnbr+0x8f>
jmp    119f <ft_putnbr+0x8f>
cmpl   $0x0,-0x4(%rbp)
jge    11c1 <ft_putnbr+0xb1>
mov    $0x1,%edx
lea    0xe4b(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    11c6 <ft_putnbr+0xb6>
jmp    11c6 <ft_putnbr+0xb6>
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
cmp    $0x1,%rax
jl     1219 <ft_putnbr+0x109>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
add    $0x30,%rax
mov    %al,-0x5(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
mov    $0x1,%edx
lea    -0x5(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    11c6 <ft_putnbr+0xb6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movslq %edi,%rax
mov    %rax,%r14
neg    %r14
cmovs  %rax,%r14
mov    $0xa,%ebx
cmp    $0xa,%r14
jb     116a <ft_putnbr+0x5a>
mov    $0xa,%ebx
movabs $0xcccccccccccccccd,%rsi
cc cc cc
mov    %r14,%rcx
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rax
mul    %rsi
shr    $0x3,%rdx
add    %rbx,%rbx
lea    (%rbx,%rbx,4),%rbx
cmp    $0x63,%rcx
mov    %rdx,%rcx
ja     1150 <ft_putnbr+0x40>
test   %edi,%edi
js     1179 <ft_putnbr+0x69>
cmp    $0xa,%rbx
jge    1195 <ft_putnbr+0x85>
jmp    120c <ft_putnbr+0xfc>
lea    0xe80(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xa,%rbx
jl     120c <ft_putnbr+0xfc>
movabs $0x6666666666666667,%r13
66 66 66
lea    0xf(%rsp),%r15
jmp    11dc <ft_putnbr+0xcc>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rax
cqto
idiv   %r12
mov    %rdx,%r14
add    $0x30,%al
mov    %al,0xf(%rsp)
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x63,%rbx
mov    %r12,%rbx
jle    120c <ft_putnbr+0xfc>
mov    %rbx,%rax
imul   %r13
mov    %rdx,%r12
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%r12
add    %rax,%r12
mov    %r14,%rax
or     %r12,%rax
shr    $0x20,%rax
jne    11b0 <ft_putnbr+0xa0>
mov    %r14d,%eax
xor    %edx,%edx
div    %r12d
mov    %edx,%r14d
jmp    11bb <ft_putnbr+0xab>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
define void @ft_putnbr(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %2
store i64 10, i64* %5
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
store i64 %7, i64* %4
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = sub nsw i64 0, %12
store i64 %13, i64* %4
br label %15
14: ; preds = %1
br label %15
15: ; preds = %14, %10
%16 = phi i64 [ %13, %10 ], [ 0, %14 ]
br label %17
17: ; preds = %21, %15
%18 = load i64, i64* %4
%19 = sdiv i64 %18, 10
store i64 %19, i64* %4
%20 = icmp sge i64 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64, i64* %5
%23 = mul nsw i64 %22, 10
store i64 %23, i64* %5
br label %17
24: ; preds = %17
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
store i64 %26, i64* %4
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = sub nsw i64 0, %31
store i64 %32, i64* %4
br label %34
33: ; preds = %24
br label %34
34: ; preds = %33, %29
%35 = phi i64 [ %32, %29 ], [ 0, %33 ]
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %41
40: ; preds = %34
br label %41
41: ; preds = %40, %38
%42 = phi i32 [ %39, %38 ], [ 0, %40 ]
br label %43
43: ; preds = %47, %41
%44 = load i64, i64* %5
%45 = sdiv i64 %44, 10
store i64 %45, i64* %5
%46 = icmp sge i64 %45, 1
br i1 %46, label %47, label %57
47: ; preds = %43
%48 = load i64, i64* %4
%49 = load i64, i64* %5
%50 = sdiv i64 %48, %49
%51 = add nsw i64 %50, 48
%52 = trunc i64 %51 to i8
store i8 %52, i8* %3
%53 = load i64, i64* %5
%54 = load i64, i64* %4
%55 = srem i64 %54, %53
store i64 %55, i64* %4
%56 = call i32 @write(i32 1, i8* %3, i32 1)
br label %43
57: ; preds = %43
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
define void @ft_putnbr(i32 %0) {
%2 = alloca i8
%3 = sext i32 %0 to i64
%4 = icmp slt i32 %0, 0
%5 = sub nsw i64 0, %3
%6 = select i1 %4, i64 %5, i64 %3
%7 = icmp ugt i64 %6, 9
br i1 %7, label %8, label %14
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ 10, %1 ]
%10 = phi i64 [ %11, %8 ], [ %6, %1 ]
%11 = udiv i64 %10, 10
%12 = mul nsw i64 %9, 10
%13 = icmp ugt i64 %10, 99
br i1 %13, label %8, label %14
14: ; preds = %8, %1
%15 = phi i64 [ 10, %1 ], [ %12, %8 ]
br i1 %4, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %18
18: ; preds = %14, %16
%19 = icmp sgt i64 %15, 9
br i1 %19, label %20, label %30
20: ; preds = %18, %20
%21 = phi i64 [ %23, %20 ], [ %15, %18 ]
%22 = phi i64 [ %27, %20 ], [ %6, %18 ]
%23 = sdiv i64 %21, 10
%24 = sdiv i64 %22, %23
%25 = trunc i64 %24 to i8
%26 = add i8 %25, 48
store i8 %26, i8* %2
%27 = srem i64 %22, %23
%28 = call i32 @write(i32 1, i8* %2, i32 1)
%29 = icmp sgt i64 %21, 99
br i1 %29, label %20, label %30
30: ; preds = %20, %18
ret void
}