#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 */
char ft_absolute(long long);
int /*<<< orphan*/ ft_putchar_fd(char, int);
void ft_putsbase_fd(long long n, long long base, int fd, char hex) {
  if (base > 32)
    return;
  if (n < 0)
    ft_putchar_fd('-', fd);
  if (n > (base - 1) || n < -(base - 1)) {
    ft_putsbase_fd(ft_absolute(n / base), base, fd, hex);
    ft_putsbase_fd(ft_absolute(n % base), base, fd, hex);
  } else if (n <= 9)
    ft_putchar_fd((ft_absolute(n) + '0'), fd);
  else if (hex == 0)
    ft_putchar_fd((ft_absolute(n) + 'a' - 10), fd);
  else if (hex == 1)
    ft_putchar_fd((ft_absolute(n) + 'A' - 10), fd);
}


x86 assembly (clang, -O0):
<ft_putsbase_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
cmpq   $0x20,-0x10(%rbp)
jle    1158 <ft_putsbase_fd+0x28>
jmp    1282 <ft_putsbase_fd+0x152>
cmpq   $0x0,-0x8(%rbp)
jge    1170 <ft_putsbase_fd+0x40>
mov    -0x14(%rbp),%esi
mov    $0x2d,%edi
call   1050 <ft_putchar_fd@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jg     119f <ft_putsbase_fd+0x6f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
cmp    %rcx,%rax
jge    11f0 <ft_putsbase_fd+0xc0>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x10(%rbp)
mov    %rax,%rdi
call   1040 <ft_absolute@plt>
movsbq %al,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl -0x15(%rbp),%ecx
call   1030 <ft_putsbase_fd@plt>
mov    -0x8(%rbp),%rax
cqto
idivq  -0x10(%rbp)
mov    %rdx,%rdi
call   1040 <ft_absolute@plt>
movsbq %al,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsbl -0x15(%rbp),%ecx
call   1030 <ft_putsbase_fd@plt>
jmp    1282 <ft_putsbase_fd+0x152>
cmpq   $0x9,-0x8(%rbp)
jg     121a <ft_putsbase_fd+0xea>
mov    -0x8(%rbp),%rdi
call   1040 <ft_absolute@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    -0x14(%rbp),%esi
movsbl %al,%edi
call   1050 <ft_putchar_fd@plt>
jmp    127d <ft_putsbase_fd+0x14d>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
jne    1249 <ft_putsbase_fd+0x119>
mov    -0x8(%rbp),%rdi
call   1040 <ft_absolute@plt>
movsbl %al,%eax
add    $0x61,%eax
sub    $0xa,%eax
mov    -0x14(%rbp),%esi
movsbl %al,%edi
call   1050 <ft_putchar_fd@plt>
jmp    1278 <ft_putsbase_fd+0x148>
movsbl -0x15(%rbp),%eax
cmp    $0x1,%eax
jne    1273 <ft_putsbase_fd+0x143>
mov    -0x8(%rbp),%rdi
call   1040 <ft_absolute@plt>
movsbl %al,%eax
add    $0x41,%eax
sub    $0xa,%eax
mov    -0x14(%rbp),%esi
movsbl %al,%edi
call   1050 <ft_putchar_fd@plt>
jmp    1278 <ft_putsbase_fd+0x148>
jmp    127d <ft_putsbase_fd+0x14d>
jmp    1282 <ft_putsbase_fd+0x152>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putsbase_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x20,%rsi
jle    1150 <ft_putsbase_fd+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    $0x1,%r13d
sub    %rsi,%r13
movsbl %r14b,%r12d
jmp    11ad <ft_putsbase_fd+0x7d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     11e0 <ft_putsbase_fd+0xb0>
mov    %rbx,%rax
cqto
idiv   %rbp
mov    %rdx,%rbx
mov    %rax,%rdi
call   1040 <ft_absolute@plt>
movsbq %al,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
call   1030 <ft_putsbase_fd@plt>
mov    %rbx,%rdi
call   1040 <ft_absolute@plt>
movsbq %al,%rbx
test   %rbx,%rbx
js     11c0 <ft_putsbase_fd+0x90>
cmp    %rbp,%rbx
jge    1170 <ft_putsbase_fd+0x40>
cmp    %rbx,%r13
jg     1170 <ft_putsbase_fd+0x40>
jmp    11ea <ft_putsbase_fd+0xba>
xchg   %ax,%ax
mov    $0x2d,%edi
mov    %r15d,%esi
call   1050 <ft_putchar_fd@plt>
cmp    %rbp,%rbx
jl     11b7 <ft_putsbase_fd+0x87>
jmp    1170 <ft_putsbase_fd+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,%ebx
jmp    1187 <ft_putsbase_fd+0x57>
mov    $0x30,%bpl
cmp    $0xa,%rbx
jl     120a <ft_putsbase_fd+0xda>
test   %r14b,%r14b
je     1207 <ft_putsbase_fd+0xd7>
cmp    $0x1,%r14b
jne    1141 <ft_putsbase_fd+0x11>
mov    $0x37,%bpl
jmp    120a <ft_putsbase_fd+0xda>
mov    $0x57,%bpl
mov    %rbx,%rdi
call   1040 <ft_absolute@plt>
add    %bpl,%al
movsbl %al,%edi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ft_putchar_fd@plt>

LLVM IR (-O0):
define void @ft_putsbase_fd(i64 %0, i64 %1, i32 %2, i8 signext %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8
store i64 %0, i64* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i8 %3, i8* %8
%9 = load i64, i64* %6
%10 = icmp sgt i64 %9, 32
br i1 %10, label %11, label %12
11: ; preds = %4
br label %86
12: ; preds = %4
%13 = load i64, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %7
%17 = call i32 @ft_putchar_fd(i8 signext 45, i32 %16)
br label %18
18: ; preds = %15, %12
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = sub nsw i64 %20, 1
%22 = icmp sgt i64 %19, %21
br i1 %22, label %29, label %23
23: ; preds = %18
%24 = load i64, i64* %5
%25 = load i64, i64* %6
%26 = sub nsw i64 %25, 1
%27 = sub nsw i64 0, %26
%28 = icmp slt i64 %24, %27
br i1 %28, label %29, label %46
29: ; preds = %23, %18
%30 = load i64, i64* %5
%31 = load i64, i64* %6
%32 = sdiv i64 %30, %31
%33 = call signext i8 @ft_absolute(i64 %32)
%34 = sext i8 %33 to i64
%35 = load i64, i64* %6
%36 = load i32, i32* %7
%37 = load i8, i8* %8
%38 = load i64, i64* %5
%39 = load i64, i64* %6
%40 = srem i64 %38, %39
%41 = call signext i8 @ft_absolute(i64 %40)
%42 = sext i8 %41 to i64
%43 = load i64, i64* %6
%44 = load i32, i32* %7
%45 = load i8, i8* %8
br label %86
46: ; preds = %23
%47 = load i64, i64* %5
%48 = icmp sle i64 %47, 9
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i64, i64* %5
%51 = call signext i8 @ft_absolute(i64 %50)
%52 = sext i8 %51 to i32
%53 = add nsw i32 %52, 48
%54 = trunc i32 %53 to i8
%55 = load i32, i32* %7
%56 = call i32 @ft_putchar_fd(i8 signext %54, i32 %55)
br label %85
57: ; preds = %46
%58 = load i8, i8* %8
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %70
61: ; preds = %57
%62 = load i64, i64* %5
%63 = call signext i8 @ft_absolute(i64 %62)
%64 = sext i8 %63 to i32
%65 = add nsw i32 %64, 97
%66 = sub nsw i32 %65, 10
%67 = trunc i32 %66 to i8
%68 = load i32, i32* %7
%69 = call i32 @ft_putchar_fd(i8 signext %67, i32 %68)
br label %84
70: ; preds = %57
%71 = load i8, i8* %8
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %83
74: ; preds = %70
%75 = load i64, i64* %5
%76 = call signext i8 @ft_absolute(i64 %75)
%77 = sext i8 %76 to i32
%78 = add nsw i32 %77, 65
%79 = sub nsw i32 %78, 10
%80 = trunc i32 %79 to i8
%81 = load i32, i32* %7
%82 = call i32 @ft_putchar_fd(i8 signext %80, i32 %81)
br label %83
83: ; preds = %74, %70
br label %84
84: ; preds = %83, %61
br label %85
85: ; preds = %84, %49
br label %86
86: ; preds = %11, %85, %29
ret void
}

LLVM IR (-O2):
define void @ft_putsbase_fd(i64 %0, i64 %1, i32 %2, i8 signext %3) {
%5 = icmp sgt i64 %1, 32
br i1 %5, label %33, label %6
6: ; preds = %4
%7 = sub i64 1, %1
br label %8
8: ; preds = %17, %6
%9 = phi i64 [ %0, %6 ], [ %23, %17 ]
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @ft_putchar_fd(i8 signext 45, i32 %2)
br label %13
13: ; preds = %11, %8
%14 = icmp sge i64 %9, %1
%15 = icmp sgt i64 %7, %9
%16 = or i1 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = sdiv i64 %9, %1
%19 = tail call signext i8 @ft_absolute(i64 %18)
%20 = sext i8 %19 to i64
tail call void @ft_putsbase_fd(i64 %20, i64 %1, i32 %2, i8 signext %3)
%21 = srem i64 %9, %1
%22 = tail call signext i8 @ft_absolute(i64 %21)
%23 = sext i8 %22 to i64
br label %8
24: ; preds = %13
%25 = icmp slt i64 %9, 10
br i1 %25, label %28, label %26
26: ; preds = %24
switch i8 %3, label %33 [
i8 0, label %28
i8 1, label %27
]
27: ; preds = %26
br label %28
28: ; preds = %26, %24, %27
%29 = phi i8 [ 55, %27 ], [ 48, %24 ], [ 87, %26 ]
%30 = tail call signext i8 @ft_absolute(i64 %9)
%31 = add i8 %30, %29
%32 = tail call i32 @ft_putchar_fd(i8 signext %31, i32 %2)
br label %33
33: ; preds = %28, %4, %26
ret void
}