#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(char);
int /*<<< orphan*/ ft_putstr(char *);
int ft_strlen(char *);
void ft_putnbr_base(int n, char *str) {
  int base;
  base = ft_strlen(str);
  if (n < 0) {
    if (n == -2147483648) {
      ft_putstr("-2147483648");
      return;
    } else {
      ft_putchar('-');
      n = n * -1;
    }
  }
  if (n >= base)
    ft_putnbr_base(n / base, str);
  else
    ft_putchar(str[(n % base)]);
}


x86 assembly (clang, -O0):
<ft_putnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    119c <ft_putnbr_base+0x5c>
movslq -0x4(%rbp),%rax
cmp    $0xffffffff80000000,%rax
jne    1186 <ft_putnbr_base+0x46>
lea    0xe84(%rip),%rdi
call   1060 <ft_putstr@plt>
jmp    11de <ft_putnbr_base+0x9e>
mov    $0x2d,%edi
call   1040 <ft_putchar@plt>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <ft_putnbr_base+0x5c>
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11bf <ft_putnbr_base+0x7f>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <ft_putnbr_base@plt>
jmp    11de <ft_putnbr_base+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <ft_putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr_base>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ebx
test   %ebp,%ebp
jns    1162 <ft_putnbr_base+0x32>
cmp    $0x80000000,%ebp
je     117f <ft_putnbr_base+0x4f>
mov    $0x2d,%edi
call   1040 <ft_putchar@plt>
neg    %ebp
mov    %ebp,%eax
cltd
cmp    %ebx,%ebp
jl     116f <ft_putnbr_base+0x3f>
idiv   %ebx
mov    %eax,%ebp
jmp    1140 <ft_putnbr_base+0x10>
idiv   %ebx
movsbl (%r14,%rdx,1),%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <ft_putchar@plt>
lea    0xe7a(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <ft_putstr@plt>

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

LLVM IR (-O2):
@.str = [12 x i8] c"-2147483648\00"
define void @ft_putnbr_base(i32 %0, i8* %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i32 [ %0, %2 ], [ %18, %17 ]
%5 = tail call i32 @ft_strlen(i8* %1)
%6 = icmp slt i32 %4, 0
br i1 %6, label %7, label %14
7: ; preds = %3
%8 = icmp eq i32 %4, -2147483648
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %25
11: ; preds = %7
%12 = tail call i32 @ft_putchar(i8 signext 45)
%13 = sub nsw i32 0, %4
br label %14
14: ; preds = %11, %3
%15 = phi i32 [ %13, %11 ], [ %4, %3 ]
%16 = icmp slt i32 %15, %5
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = sdiv i32 %15, %5
br label %3
19: ; preds = %14
%20 = srem i32 %15, %5
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @ft_putchar(i8 signext %23)
br label %25
25: ; preds = %19, %9
ret void
}