#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 strlen(char *);
int /*<<< orphan*/ terminal_putchar(char);
void terminal_putnbr_base(int nb, char *base) {
  int result;
  int diviseur;
  int size_base;
  size_base = strlen(base);
  if (nb < 0) {
    terminal_putchar('-');
    nb = -nb;
  }
  diviseur = 1;
  while ((nb / diviseur) >= size_base)
    diviseur = diviseur * size_base;
  while (diviseur > 0) {
    result = (nb / diviseur) % size_base;
    terminal_putchar(base[result]);
    diviseur = diviseur / size_base;
  }
}


x86 assembly (clang, -O0):
<terminal_putnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1157 <terminal_putnbr_base+0x37>
mov    $0x2d,%edi
call   1040 <terminal_putchar@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    -0x1c(%rbp),%eax
jl     117d <terminal_putnbr_base+0x5d>
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    115e <terminal_putnbr_base+0x3e>
jmp    1182 <terminal_putnbr_base+0x62>
cmpl   $0x0,-0x18(%rbp)
jle    11ba <terminal_putnbr_base+0x9a>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cltd
idivl  -0x1c(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <terminal_putchar@plt>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x18(%rbp)
jmp    1182 <terminal_putnbr_base+0x62>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminal_putnbr_base>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
test   %r15d,%r15d
jns    1149 <terminal_putnbr_base+0x29>
mov    $0x2d,%edi
call   1040 <terminal_putchar@plt>
neg    %r15d
mov    $0x1,%ebp
cmp    %ebx,%r15d
jl     1180 <terminal_putnbr_base+0x60>
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
imul   %ebx,%ebp
mov    %r15d,%eax
cltd
idiv   %ebp
cmp    %ebx,%eax
jge    1160 <terminal_putnbr_base+0x40>
test   %ebp,%ebp
jle    11a1 <terminal_putnbr_base+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%eax
cltd
idiv   %ebp
cltd
idiv   %ebx
movslq %edx,%rax
movsbl (%r14,%rax,1),%edi
call   1040 <terminal_putchar@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
mov    %eax,%ebp
test   %eax,%eax
jg     1180 <terminal_putnbr_base+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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