#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*/ ft_putchar_fd(long, int);
void ft_putnbr_fd(int n, int fd) {
  long num;
  num = (long)n;
  if (num < 0) {
    num = num * -1;
    ft_putchar_fd('-', fd);
  }
  if (num >= 10)
    ft_putnbr_fd(num / 10, fd);
  ft_putchar_fd(num % 10 + '0', fd);
}


x86 assembly (clang, -O0):
<ft_putnbr_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1157 <ft_putnbr_fd+0x37>
imul   $0xffffffffffffffff,-0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x2d,%edi
call   1040 <ft_putchar_fd@plt>
cmpq   $0xa,-0x10(%rbp)
jl     117a <ft_putnbr_fd+0x5a>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   1030 <ft_putnbr_fd@plt>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rdx,%rdi
add    $0x30,%rdi
mov    -0x8(%rbp),%esi
call   1040 <ft_putchar_fd@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr_fd>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
movslq %edi,%rbx
test   %ebx,%ebx
js     1185 <ft_putnbr_fd+0x65>
cmp    $0xa,%rbx
jl     1148 <ft_putnbr_fd+0x28>
mov    %ebx,%eax
mov    $0xcccccccd,%edi
imul   %rax,%rdi
shr    $0x23,%rdi
mov    %ebp,%esi
call   1030 <ft_putnbr_fd@plt>
movabs $0x6666666666666667,%rcx
66 66 66
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
add    %rdx,%rdx
lea    (%rdx,%rdx,4),%rax
neg    %rax
lea    (%rbx,%rax,1),%rdi
add    $0x30,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <ft_putchar_fd@plt>
neg    %rbx
mov    $0x2d,%edi
mov    %ebp,%esi
call   1040 <ft_putchar_fd@plt>
cmp    $0xa,%rbx
jge    1132 <ft_putnbr_fd+0x12>
jmp    1148 <ft_putnbr_fd+0x28>

LLVM IR (-O0):
define void @ft_putnbr_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i64, i64* %5
%12 = mul nsw i64 %11, -1
store i64 %12, i64* %5
%13 = load i32, i32* %4
%14 = call i32 @ft_putchar_fd(i64 45, i32 %13)
br label %15
15: ; preds = %10, %2
%16 = load i64, i64* %5
%17 = icmp sge i64 %16, 10
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i64, i64* %5
%20 = sdiv i64 %19, 10
%21 = trunc i64 %20 to i32
%22 = load i32, i32* %4
br label %23
23: ; preds = %18, %15
%24 = load i64, i64* %5
%25 = srem i64 %24, 10
%26 = add nsw i64 %25, 48
%27 = load i32, i32* %4
%28 = call i32 @ft_putchar_fd(i64 %26, i32 %27)
ret void
}

LLVM IR (-O2):
define void @ft_putnbr_fd(i32 %0, i32 %1) {
%3 = sext i32 %0 to i64
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = sub nsw i64 0, %3
%7 = tail call i32 @ft_putchar_fd(i64 45, i32 %1)
br label %8
8: ; preds = %5, %2
%9 = phi i64 [ %6, %5 ], [ %3, %2 ]
%10 = icmp sgt i64 %9, 9
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = trunc i64 %9 to i32
%13 = udiv i32 %12, 10
tail call void @ft_putnbr_fd(i32 %13, i32 %1)
br label %14
14: ; preds = %11, %8
%15 = srem i64 %9, 10
%16 = add nsw i64 %15, 48
%17 = tail call i32 @ft_putchar_fd(i64 %16, i32 %1)
ret void
}