#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 nb) {
  char char_buffer[11];
  int num_chars;
  int factor;
  num_chars = 0;
  factor = 1;
  if (nb == 0)
    write(1, "0", 1);
  if (nb < 0) {
    factor = -1;
    write(1, "-", 1);
  }
  while (nb != 0) {
    char_buffer[num_chars++] = factor * (nb % 10) + '0';
    nb /= 10;
  }
  num_chars--;
  while (num_chars >= 0)
    write(1, &char_buffer[num_chars--], 1);
}


x86 assembly (clang, -O0):
<ft_putnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1146 <ft_putnbr+0x36>
mov    $0x1,%edx
lea    0xec1(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
cmpl   $0x0,-0x4(%rbp)
jge    116a <ft_putnbr+0x5a>
movl   $0xffffffff,-0x18(%rbp)
mov    $0x1,%edx
lea    0xe9f(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    116f <ft_putnbr+0x5f>
cmpl   $0x0,-0x4(%rbp)
je     11b9 <ft_putnbr+0xa9>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
imul   %edx,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
cltq
mov    %cl,-0xf(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    116f <ft_putnbr+0x5f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11f1 <ft_putnbr+0xe1>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cltq
lea    -0xf(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
jmp    11c2 <ft_putnbr+0xb2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr>:
test   %edi,%edi
je     11ca <ft_putnbr+0xba>
push   %rbx
lea    -0x10(%rsp),%rsp
mov    %edi,%ebx
mov    $0x1,%eax
jns    1142 <ft_putnbr+0x32>
lea    0xed4(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebx,%rdx
imul   $0x66666667,%rdx,%rbx
mov    %rbx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rbx
add    %esi,%ebx
lea    (%rbx,%rbx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
imul   %eax,%edi
add    $0x30,%dil
mov    %dil,0x5(%rsp,%rcx,1)
add    $0x1,%rcx
add    $0x9,%edx
cmp    $0x13,%edx
jae    1150 <ft_putnbr+0x40>
test   %ecx,%ecx
jle    11c4 <ft_putnbr+0xb4>
mov    %ecx,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x2(%rbx),%eax
lea    (%rsp,%rax,1),%rsi
add    $0x5,%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11a0 <ft_putnbr+0x90>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe2f(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
jmp    1030 <write@plt>

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

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