#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_fd(int nb, int fd) {
  char c;
  if (nb == -2147483648) {
    write(fd, "-2147483648", 11);
    return;
  }
  if (nb < 0) {
    write(fd, "-", 1);
    nb = 0 - nb;
  }
  if (nb >= 10)
    ft_putnbr_fd(nb / 10, fd);
  c = '0' + nb % 10;
  write(fd, &c, 1);
}


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
cmp    $0xffffffff80000000,%rax
jne    1157 <ft_putnbr_fd+0x37>
mov    -0x8(%rbp),%edi
lea    0xeb8(%rip),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
jmp    11c0 <ft_putnbr_fd+0xa0>
cmpl   $0x0,-0x4(%rbp)
jge    117d <ft_putnbr_fd+0x5d>
mov    -0x8(%rbp),%edi
lea    0xea1(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jl     119c <ft_putnbr_fd+0x7c>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   1030 <ft_putnbr_fd@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr_fd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
cmp    $0x80000000,%edi
jne    114f <ft_putnbr_fd+0x2f>
lea    0xec6(%rip),%rsi
mov    %r14d,%edi
mov    $0xb,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <write@plt>
mov    %edi,%ebp
test   %edi,%edi
jns    116b <ft_putnbr_fd+0x4b>
lea    0xeb0(%rip),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <write@plt>
neg    %ebp
mov    %ebp,%ebx
cmp    $0xa,%ebp
jb     1187 <ft_putnbr_fd+0x67>
mov    $0xcccccccd,%edi
imul   %rbx,%rdi
shr    $0x23,%rdi
mov    %r14d,%esi
call   1030 <ft_putnbr_fd@plt>
mov    $0xcccccccd,%eax
imul   %rbx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
or     $0x30,%bpl
mov    %bpl,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"-2147483648\00"
@.str.1 = [2 x i8] c"-\00"
define void @ft_putnbr_fd(i32 %0, i32 %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, -2147483648
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
br label %22
7: ; preds = %2
%8 = icmp slt i32 %0, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = sub nsw i32 0, %0
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ %11, %9 ], [ %0, %7 ]
%14 = icmp ugt i32 %13, 9
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = udiv i32 %13, 10
tail call void @ft_putnbr_fd(i32 %16, i32 %1)
br label %17
17: ; preds = %15, %12
%18 = urem i32 %13, 10
%19 = trunc i32 %18 to i8
%20 = or i8 %19, 48
store i8 %20, i8* %3
%21 = call i32 @write(i32 %1, i8* %3, i32 1)
br label %22
22: ; preds = %17, %5
ret void
}