#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_putnbr(int);
int ft_printf_d(int nbr) {
  int ret;
  int copy;
  copy = nbr;
  ret = 0;
  if (nbr <= 0)
    ret++;
  while (nbr >= 1 || nbr <= -1) {
    nbr = nbr / 10;
    ret++;
  }
  ft_putnbr(copy);
  return (ret);
}


x86 assembly (clang, -O0):
<ft_printf_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     113b <ft_printf_d+0x2b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1140 <ft_printf_d+0x30>
mov    $0x1,%al
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0xd(%rbp)
jge    1159 <ft_printf_d+0x49>
cmpl   $0xffffffff,-0x4(%rbp)
setle  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1169 <ft_printf_d+0x59>
jmp    1185 <ft_printf_d+0x75>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1140 <ft_printf_d+0x30>
mov    -0xc(%rbp),%edi
call   1030 <ft_putnbr@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_printf_d>:
push   %rbx
xor    %ebx,%ebx
test   %edi,%edi
setle  %bl
je     1142 <ft_printf_d+0x32>
mov    %edi,%eax
nopl   0x0(%rax)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    $0x1,%ebx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1120 <ft_printf_d+0x10>
call   1030 <ft_putnbr@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ft_printf_d(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
store i32 %5, i32* %4
store i32 0, i32* %3
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
br label %11
11: ; preds = %8, %1
br label %12
12: ; preds = %20, %11
%13 = load i32, i32* %2
%14 = icmp sge i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %2
%17 = icmp sle i32 %16, -1
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br i1 %19, label %20, label %25
20: ; preds = %18
%21 = load i32, i32* %2
%22 = sdiv i32 %21, 10
store i32 %22, i32* %2
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %12
25: ; preds = %18
%26 = load i32, i32* %4
%27 = call i32 @ft_putnbr(i32 %26)
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @ft_printf_d(i32 %0) {
%2 = icmp slt i32 %0, 1
%3 = zext i1 %2 to i32
%4 = icmp eq i32 %0, 0
br i1 %4, label %12, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %8, %5 ], [ %0, %1 ]
%7 = phi i32 [ %9, %5 ], [ %3, %1 ]
%8 = sdiv i32 %6, 10
%9 = add nuw nsw i32 %7, 1
%10 = add i32 %6, 9
%11 = icmp ult i32 %10, 19
br i1 %11, label %12, label %5
12: ; preds = %5, %1
%13 = phi i32 [ %3, %1 ], [ %9, %5 ]
%14 = tail call i32 @ft_putnbr(i32 %0)
ret i32 %13
}