#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 *);
int my_putnbr_base(int nbr, char *base) {
  int re;
  int d;
  int len;
  len = my_strlen(base);
  if (nbr < 0) {
    my_putchar('-');
    nbr = -1 * nbr;
  }
  for (d = 1; (nbr / d) >= len; d = d * len)
    ;
  for (; d > 0; re = (nbr / d) % len, my_putchar(base[re]), d = d / len)
    ;
  return (re);
}


x86 assembly (clang, -O0):
<my_putnbr_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1159 <my_putnbr_base+0x39>
mov    $0x2d,%edi
call   1040 <my_putchar@plt>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    -0x1c(%rbp),%eax
jl     1184 <my_putnbr_base+0x64>
jmp    1175 <my_putnbr_base+0x55>
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1160 <my_putnbr_base+0x40>
jmp    1189 <my_putnbr_base+0x69>
cmpl   $0x0,-0x18(%rbp)
jle    11c6 <my_putnbr_base+0xa6>
jmp    1198 <my_putnbr_base+0x78>
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    -0x18(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x18(%rbp)
jmp    1189 <my_putnbr_base+0x69>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_putnbr_base>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%r12d
test   %r15d,%r15d
jns    114b <my_putnbr_base+0x2b>
mov    $0x2d,%edi
call   1040 <my_putchar@plt>
neg    %r15d
mov    $0x1,%ebp
cmp    %r12d,%r15d
jl     1180 <my_putnbr_base+0x60>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
imul   %r12d,%ebp
mov    %r15d,%eax
cltd
idiv   %ebp
cmp    %r12d,%eax
jge    1160 <my_putnbr_base+0x40>
test   %ebp,%ebp
jle    11a7 <my_putnbr_base+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%eax
cltd
idiv   %ebp
cltd
idiv   %r12d
mov    %edx,%ebx
movslq %edx,%rax
movsbl (%r14,%rax,1),%edi
call   1040 <my_putchar@plt>
mov    %ebp,%eax
cltd
idiv   %r12d
mov    %eax,%ebp
test   %eax,%eax
jg     1180 <my_putnbr_base+0x60>
jmp    11a7 <my_putnbr_base+0x87>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @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
%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 = mul nsw i32 -1, %14
store i32 %15, i32* %3
br label %16
16: ; preds = %12, %2
store i32 1, i32* %6
br label %17
17: ; preds = %24, %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 %28
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = mul nsw i32 %25, %26
store i32 %27, i32* %6
br label %17
28: ; preds = %17
br label %29
29: ; preds = %33, %28
%30 = load i32, i32* %6
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %48
32: ; preds = %29
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = load i32, i32* %6
%36 = sdiv i32 %34, %35
%37 = load i32, i32* %7
%38 = srem i32 %36, %37
store i32 %38, i32* %5
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = call i32 @my_putchar(i8 signext %43)
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = sdiv i32 %45, %46
store i32 %47, i32* %6
br label %29
48: ; preds = %29
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
define i32 @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
%31 = phi i32 [ undef, %11 ], [ %23, %20 ]
ret i32 %31
}