#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);
unsigned long str_len(char *);
void ft_putnbr_16_base(int nbr) {
  unsigned long base_len;
  char resault[2048];
  int it;
  if (nbr < 0)
    nbr *= -1;
  it = 0;
  base_len = str_len("0123456789abcdef");
  while (nbr / base_len >= base_len) {
    resault[it++] = "0123456789abcdef"[nbr % base_len];
    nbr /= base_len;
  }
  resault[it++] = "0123456789abcdef"[nbr % base_len];
  resault[it] = "0123456789abcdef"[nbr / base_len];
  while (it >= 0)
    ft_putchar(resault[it--]);
}


x86 assembly (clang, -O0):
<ft_putnbr_16_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    113f <ft_putnbr_16_base+0x1f>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x814(%rbp)
lea    0xeb0(%rip),%rdi
call   1040 <str_len@plt>
mov    %rax,-0x10(%rbp)
movslq -0x4(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
cmp    -0x10(%rbp),%rax
jb     11b4 <ft_putnbr_16_base+0x94>
movslq -0x4(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
lea    0xe7e(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x814(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x814(%rbp)
cltq
mov    %cl,-0x810(%rbp,%rax,1)
mov    -0x10(%rbp),%rcx
movslq -0x4(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %eax,-0x4(%rbp)
jmp    1159 <ft_putnbr_16_base+0x39>
movslq -0x4(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
lea    0xe39(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x814(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x814(%rbp)
cltq
mov    %cl,-0x810(%rbp,%rax,1)
movslq -0x4(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rax,%rcx
lea    0xe06(%rip),%rax
mov    (%rax,%rcx,1),%cl
movslq -0x814(%rbp),%rax
mov    %cl,-0x810(%rbp,%rax,1)
cmpl   $0x0,-0x814(%rbp)
jl     123d <ft_putnbr_16_base+0x11d>
mov    -0x814(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x814(%rbp)
cltq
movsbl -0x810(%rbp,%rax,1),%edi
ff
call   1030 <ft_putchar@plt>
jmp    120b <ft_putnbr_16_base+0xeb>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_putnbr_16_base>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %edi,%r15d
neg    %r15d
cmovs  %edi,%r15d
lea    0xec1(%rip),%r14
mov    %r14,%rdi
call   1040 <str_len@plt>
mov    %rax,%rcx
xor    %r12d,%r12d
cmp    %rax,%r15
jb     1162 <ft_putnbr_16_base+0x42>
mov    %r15d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
cmp    %rcx,%rsi
jae    1181 <ft_putnbr_16_base+0x61>
jmp    11d3 <ft_putnbr_16_base+0xb3>
xor    %esi,%esi
cmp    %rcx,%rsi
jae    1181 <ft_putnbr_16_base+0x61>
jmp    11d3 <ft_putnbr_16_base+0xb3>
nopl   0x0(%rax,%rax,1)
mov    %esi,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
add    $0x1,%r12
cmp    %rcx,%rsi
jb     11d3 <ft_putnbr_16_base+0xb3>
mov    %r15,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11a0 <ft_putnbr_16_base+0x80>
mov    %r15,%rax
xor    %edx,%edx
div    %rcx
jmp    11a7 <ft_putnbr_16_base+0x87>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%eax
xor    %edx,%edx
div    %ecx
movzbl (%rdx,%r14,1),%eax
mov    %al,(%rsp,%r12,1)
movslq %esi,%r15
mov    %r15,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1170 <ft_putnbr_16_base+0x50>
mov    %r15,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
add    $0x1,%r12
cmp    %rcx,%rsi
jae    1181 <ft_putnbr_16_base+0x61>
mov    %rcx,%rax
or     %r15,%rax
shr    $0x20,%rax
je     11e9 <ft_putnbr_16_base+0xc9>
mov    %r15,%rax
xor    %edx,%edx
div    %rcx
jmp    11f0 <ft_putnbr_16_base+0xd0>
mov    %r15d,%eax
xor    %edx,%edx
div    %ecx
mov    (%rdx,%r14,1),%cl
mov    %r12d,%eax
mov    %cl,(%rsp,%rax,1)
mov    (%rsi,%r14,1),%cl
mov    %cl,0x1(%rsp,%rax,1)
cmp    $0xffffffff,%r12d
jl     1235 <ft_putnbr_16_base+0x115>
add    $0x2,%r12d
mov    %rsp,%rcx
lea    (%rax,%rcx,1),%rbx
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1030 <ft_putchar@plt>
add    $0xffffffff,%r12d
add    $0xffffffffffffffff,%rbx
test   %r12d,%r12d
jg     1220 <ft_putnbr_16_base+0x100>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @ft_putnbr_16_base(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca [2048 x i8]
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* %2
%10 = mul nsw i32 %9, -1
store i32 %10, i32* %2
br label %11
11: ; preds = %8, %1
store i32 0, i32* %5
%12 = call i64 @str_len(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i64 %12, i64* %3
br label %13
13: ; preds = %20, %11
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = load i64, i64* %3
%17 = udiv i64 %15, %16
%18 = load i64, i64* %3
%19 = icmp uge i64 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %13
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = load i64, i64* %3
%24 = urem i64 %22, %23
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %29
store i8 %26, i8* %30
%31 = load i64, i64* %3
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = udiv i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %2
br label %13
36: ; preds = %13
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = load i64, i64* %3
%40 = urem i64 %38, %39
%41 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %45
store i8 %42, i8* %46
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = load i64, i64* %3
%50 = udiv i64 %48, %49
%51 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %54
store i8 %52, i8* %55
br label %56
56: ; preds = %59, %36
%57 = load i32, i32* %5
%58 = icmp sge i32 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %56
%60 = load i32, i32* %5
%61 = add nsw i32 %60, -1
store i32 %61, i32* %5
%62 = sext i32 %60 to i64
%63 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %62
%64 = load i8, i8* %63
%65 = call i32 @ft_putchar(i8 signext %64)
br label %56
66: ; preds = %56
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @ft_putnbr_16_base(i32 %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%5 = tail call i64 @str_len(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = zext i32 %4 to i64
%7 = udiv i64 %6, %5
%8 = icmp ult i64 %7, %5
br i1 %8, label %24, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %16, %9 ], [ 0, %1 ]
%11 = phi i64 [ %20, %9 ], [ %7, %1 ]
%12 = phi i64 [ %19, %9 ], [ %6, %1 ]
%13 = urem i64 %12, %5
%14 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = add nuw i64 %10, 1
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %10
store i8 %15, i8* %17
%18 = shl i64 %11, 32
%19 = ashr exact i64 %18, 32
%20 = udiv i64 %19, %5
%21 = icmp ult i64 %20, %5
br i1 %21, label %22, label %9
22: ; preds = %9
%23 = trunc i64 %16 to i32
br label %24
24: ; preds = %22, %1
%25 = phi i32 [ 0, %1 ], [ %23, %22 ]
%26 = phi i64 [ %6, %1 ], [ %19, %22 ]
%27 = phi i64 [ %7, %1 ], [ %20, %22 ]
%28 = urem i64 %26, %5
%29 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = add nuw nsw i32 %25, 1
%32 = zext i32 %25 to i64
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %32
store i8 %30, i8* %33
%34 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %27
%35 = load i8, i8* %34
%36 = zext i32 %31 to i64
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %36
store i8 %35, i8* %37
%38 = icmp sgt i32 %25, -2
br i1 %38, label %39, label %49
39: ; preds = %24
%40 = add nuw nsw i64 %32, 1
br label %41
41: ; preds = %39, %41
%42 = phi i64 [ %40, %39 ], [ %43, %41 ]
%43 = add nsw i64 %42, -1
%44 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %42
%45 = load i8, i8* %44
%46 = tail call i32 @ft_putchar(i8 signext %45)
%47 = trunc i64 %42 to i32
%48 = icmp sgt i32 %47, 0
br i1 %48, label %41, label %49
49: ; preds = %41, %24
ret void
}