#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*/ my_putchar(char);
int my_putnbr_write(int, int, int);
int my_putnbr(int nbr) {
  int writed;
  int nbr_save;
  int car;
  car = 0;
  writed = 0;
  if (nbr < 0) {
    writed += 1;
    my_putchar('-');
    nbr *= -1;
  }
  nbr_save = nbr;
  while (nbr != 0) {
    nbr /= 10;
    car += 1;
  }
  return (my_putnbr_write(car, nbr_save, writed));
}


x86 assembly (clang, -O0):
<my_putnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    115d <my_putnbr+0x3d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x2d,%edi
call   1040 <my_putchar@plt>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1189 <my_putnbr+0x69>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1163 <my_putnbr+0x43>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1030 <my_putnbr_write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_putnbr>:
push   %rbx
mov    %edi,%ebx
test   %edi,%edi
js     113d <my_putnbr+0x1d>
xor    %edx,%edx
mov    $0x0,%esi
mov    $0x0,%edi
test   %ebx,%ebx
jne    114e <my_putnbr+0x2e>
pop    %rbx
jmp    1030 <my_putnbr_write@plt>
mov    $0x2d,%edi
call   1040 <my_putchar@plt>
neg    %ebx
mov    $0x1,%edx
xor    %edi,%edi
mov    %ebx,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rax
add    %esi,%eax
add    $0x1,%edi
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1160 <my_putnbr+0x40>
mov    %ebx,%esi
pop    %rbx
jmp    1030 <my_putnbr_write@plt>

LLVM IR (-O0):
define i32 @my_putnbr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
store i32 0, i32* %3
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = call i32 @my_putchar(i8 signext 45)
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, -1
store i32 %13, i32* %2
br label %14
14: ; preds = %8, %1
%15 = load i32, i32* %2
store i32 %15, i32* %4
br label %16
16: ; preds = %19, %14
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* %2
%21 = sdiv i32 %20, 10
store i32 %21, i32* %2
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %16
24: ; preds = %16
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = call i32 @my_putnbr_write(i32 %25, i32 %26, i32 %27)
ret i32 %28
}

LLVM IR (-O2):
define i32 @my_putnbr(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @my_putchar(i8 signext 45)
%5 = sub nsw i32 0, %0
br label %8
6: ; preds = %1
%7 = icmp eq i32 %0, 0
br i1 %7, label %18, label %8
8: ; preds = %3, %6
%9 = phi i32 [ %5, %3 ], [ %0, %6 ]
%10 = phi i32 [ 1, %3 ], [ 0, %6 ]
br label %11
11: ; preds = %8, %11
%12 = phi i32 [ %15, %11 ], [ 0, %8 ]
%13 = phi i32 [ %14, %11 ], [ %9, %8 ]
%14 = sdiv i32 %13, 10
%15 = add nuw nsw i32 %12, 1
%16 = add i32 %13, 9
%17 = icmp ult i32 %16, 19
br i1 %17, label %18, label %11
18: ; preds = %11, %6
%19 = phi i32 [ 0, %6 ], [ %9, %11 ]
%20 = phi i32 [ 0, %6 ], [ %10, %11 ]
%21 = phi i32 [ 0, %6 ], [ %15, %11 ]
%22 = tail call i32 @my_putnbr_write(i32 %21, i32 %19, i32 %20)
ret i32 %22
}