#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 */
scalar_t__ check_base_condition(char *);
int /*<<< orphan*/ ft_putchar(char);
int /*<<< orphan*/ ft_putmaxneg_base(int, char *);
int ft_strlen(char *);
void ft_putnbr_base(int nbr, char *base) {
  if (check_base_condition(base)) {
    if (nbr == -2147483648) {
      ft_putchar('-');
      ft_putmaxneg_base(nbr, base);
      return;
    }
    if (nbr < 0) {
      ft_putchar('-');
      nbr = -nbr;
    }
    if (nbr >= ft_strlen(base)) {
      ft_putnbr_base(nbr / ft_strlen(base), base);
      ft_putnbr_base(nbr % ft_strlen(base), base);
    } else
      ft_putchar(base[nbr]);
  }
}


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   1070 <check_base_condition@plt>
cmp    $0x0,%rax
je     1234 <ft_putnbr_base+0xe4>
movslq -0x4(%rbp),%rax
cmp    $0xffffffff80000000,%rax
jne    119d <ft_putnbr_base+0x4d>
mov    $0x2d,%edi
call   1040 <ft_putchar@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <ft_putmaxneg_base@plt>
jmp    1234 <ft_putnbr_base+0xe4>
cmpl   $0x0,-0x4(%rbp)
jge    11b9 <ft_putnbr_base+0x69>
mov    $0x2d,%edi
call   1040 <ft_putchar@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jl     121e <ft_putnbr_base+0xce>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <ft_putnbr_base@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x10(%rbp),%rsi
call   1050 <ft_putnbr_base@plt>
jmp    122f <ft_putnbr_base+0xdf>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <ft_putchar@plt>
jmp    1234 <ft_putnbr_base+0xe4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr_base>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
nopl   0x0(%rax,%rax,1)
call   1070 <check_base_condition@plt>
test   %rax,%rax
je     11bd <ft_putnbr_base+0x6d>
cmp    $0x80000000,%ebp
je     11c4 <ft_putnbr_base+0x74>
test   %ebp,%ebp
jns    1182 <ft_putnbr_base+0x32>
mov    $0x2d,%edi
call   1040 <ft_putchar@plt>
neg    %ebp
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
cmp    %eax,%ebp
jl     11e1 <ft_putnbr_base+0x91>
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <ft_putnbr_base@plt>
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
mov    %rbx,%rdi
jmp    1160 <ft_putnbr_base+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x2d,%edi
call   1040 <ft_putchar@plt>
mov    $0x80000000,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <ft_putmaxneg_base@plt>
mov    %ebp,%eax
movsbl (%rbx,%rax,1),%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <ft_putchar@plt>

LLVM IR (-O0):
define void @ft_putnbr_base(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i64 @check_base_condition(i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %48
8: ; preds = %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = icmp eq i64 %10, -2147483648
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = call i32 @ft_putchar(i8 signext 45)
%14 = load i32, i32* %3
%15 = load i8*, i8** %4
%16 = call i32 @ft_putmaxneg_base(i32 %14, i8* %15)
br label %48
17: ; preds = %8
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 @ft_putchar(i8 signext 45)
%22 = load i32, i32* %3
%23 = sub nsw i32 0, %22
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %17
%25 = load i32, i32* %3
%26 = load i8*, i8** %4
%27 = call i32 @ft_strlen(i8* %26)
%28 = icmp sge i32 %25, %27
br i1 %28, label %29, label %40
29: ; preds = %24
%30 = load i32, i32* %3
%31 = load i8*, i8** %4
%32 = call i32 @ft_strlen(i8* %31)
%33 = sdiv i32 %30, %32
%34 = load i8*, i8** %4
%35 = load i32, i32* %3
%36 = load i8*, i8** %4
%37 = call i32 @ft_strlen(i8* %36)
%38 = srem i32 %35, %37
%39 = load i8*, i8** %4
br label %47
40: ; preds = %24
%41 = load i8*, i8** %4
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = call i32 @ft_putchar(i8 signext %45)
br label %47
47: ; preds = %40, %29
br label %48
48: ; preds = %12, %47, %2
ret void
}

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