#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*/ my_putchar(char);
int my_strlen(char *);
void my_putnbr_base(int nbr, char *base) {
  int result;
  int div;
  int size_base;
  div = 1;
  size_base = my_strlen(base);
  if (nbr < 0) {
    my_putchar('-');
    nbr = -nbr;
  }
  while (nbr / div >= size_base)
    div *= size_base;
  while (div > 0) {
    result = (nbr / div) % size_base;
    my_putchar(base[result]);
    div /= size_base;
  }
}


x86 assembly (clang, -O0):
<my_putnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    115e <my_putnbr_base+0x3e>
mov    $0x2d,%edi
call   1040 <my_putchar@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1163 <my_putnbr_base+0x43>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    -0x1c(%rbp),%eax
jl     1182 <my_putnbr_base+0x62>
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <my_putnbr_base+0x43>
jmp    1187 <my_putnbr_base+0x67>
cmpl   $0x0,-0x18(%rbp)
jle    11c1 <my_putnbr_base+0xa1>
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 <my_putchar@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    1187 <my_putnbr_base+0x67>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_putnbr_base>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ebx
test   %r15d,%r15d
jns    1149 <my_putnbr_base+0x29>
mov    $0x2d,%edi
call   1040 <my_putchar@plt>
neg    %r15d
mov    $0x1,%ebp
cmp    %ebx,%r15d
jl     1180 <my_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 <my_putnbr_base+0x40>
test   %ebp,%ebp
jle    11a1 <my_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 <my_putchar@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
mov    %eax,%ebp
test   %eax,%eax
jg     1180 <my_putnbr_base+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @my_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
store i32 1, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @my_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 @my_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
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* %7
%25 = load i32, i32* %6
%26 = mul nsw i32 %25, %24
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 @my_putchar(i8 signext %41)
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = sdiv i32 %44, %43
store i32 %45, i32* %6
br label %28
46: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @my_putnbr_base(i32 %0, i8* %1) {
%3 = tail call i32 @my_strlen(i8* %1)
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @my_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 @my_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
}