#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_printnbr(unsigned long, char *, unsigned int);
int /*<<< orphan*/ my_putchar(char);
int my_ptrprintnbr(unsigned long nb, char *base, unsigned int bs) {
  if (nb < bs) {
    my_putchar(base[nb]);
    return (0);
  }
  my_printnbr(nb / bs, base, bs);
  my_putchar(base[nb % bs]);
  return (0);
}


x86 assembly (clang, -O0):
<my_ptrprintnbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmp    %rcx,%rax
jae    1160 <my_ptrprintnbr+0x40>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <my_putchar@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <my_ptrprintnbr+0x83>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <my_printnbr@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    -0x28(%rbp),%rax
movsbl (%rax,%rdx,1),%edi
call   1030 <my_putchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_ptrprintnbr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%esi
cmp    %rdi,%rsi
ja     115e <my_ptrprintnbr+0x3e>
mov    %edx,%ecx
mov    %rbx,%rax
shr    $0x20,%rax
je     1149 <my_ptrprintnbr+0x29>
mov    %rbx,%rax
xor    %edx,%edx
div    %rsi
mov    %rdx,%rbx
jmp    1151 <my_ptrprintnbr+0x31>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
mov    %edx,%ebx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ecx,%edx
call   1040 <my_printnbr@plt>
movsbl (%r14,%rbx,1),%edi
call   1030 <my_putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @my_ptrprintnbr(i64 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i64, i64* %5
%9 = load i32, i32* %7
%10 = zext i32 %9 to i64
%11 = icmp ult i64 %8, %10
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @my_putchar(i8 signext %16)
store i32 0, i32* %4
br label %34
18: ; preds = %3
%19 = load i64, i64* %5
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = udiv i64 %19, %21
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @my_printnbr(i64 %22, i8* %23, i32 %24)
%26 = load i8*, i8** %6
%27 = load i64, i64* %5
%28 = load i32, i32* %7
%29 = zext i32 %28 to i64
%30 = urem i64 %27, %29
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @my_putchar(i8 signext %32)
store i32 0, i32* %4
br label %34
34: ; preds = %18, %12
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @my_ptrprintnbr(i64 %0, i8* %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = icmp ugt i64 %4, %0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = udiv i64 %0, %4
%8 = tail call i32 @my_printnbr(i64 %7, i8* %1, i32 %2)
%9 = urem i64 %0, %4
br label %10
10: ; preds = %3, %6
%11 = phi i64 [ %9, %6 ], [ %0, %3 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @my_putchar(i8 signext %13)
ret i32 0
}