#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*/ m4errx(int, char *, int);
int /*<<< orphan*/ pushback(char);
void pbnumbase(int n, int base, int d) {
  static char digits[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
  int num;
  int printed = 0;
  if (base > 36)
    m4errx(1, "base %d > 36: not supported.", base);
  if (base < 2)
    m4errx(1, "bad base %d for conversion.", base);
  num = (n < 0) ? -n : n;
  do {
    pushback(digits[num % base]);
    printed++;
  } while ((num /= base) > 0);
  if (n < 0)
    printed++;
  while (printed++ < d)
    pushback('0');
  if (n < 0)
    pushback('-');
}


x86 assembly (clang, -O0):
<pbnumbase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x24,-0x8(%rbp)
jle    1156 <pbnumbase+0x36>
mov    -0x8(%rbp),%edx
mov    $0x1,%edi
lea    0xeaf(%rip),%rsi
call   1030 <m4errx@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1174 <pbnumbase+0x54>
mov    -0x8(%rbp),%edx
mov    $0x1,%edi
lea    0xeae(%rip),%rsi
call   1030 <m4errx@plt>
cmpl   $0x0,-0x4(%rbp)
jge    118b <pbnumbase+0x6b>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1191 <pbnumbase+0x71>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
movslq %edx,%rcx
lea    0x2e98(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1040 <pushback@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jg     1197 <pbnumbase+0x77>
cmpl   $0x0,-0x4(%rbp)
jge    11e2 <pbnumbase+0xc2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e7 <pbnumbase+0xc7>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cmp    -0xc(%rbp),%eax
jge    120a <pbnumbase+0xea>
mov    $0x30,%edi
call   1040 <pushback@plt>
jmp    11e7 <pbnumbase+0xc7>
cmpl   $0x0,-0x4(%rbp)
jge    121e <pbnumbase+0xfe>
mov    $0x2d,%edi
call   1040 <pushback@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbnumbase>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r15d
mov    %edi,%r14d
cmp    $0x24,%esi
jle    1142 <pbnumbase+0x22>
lea    0xee4(%rip),%rsi
jmp    114f <pbnumbase+0x2f>
cmp    $0x1,%r15d
jg     115c <pbnumbase+0x3c>
lea    0xef2(%rip),%rsi
mov    $0x1,%edi
mov    %r15d,%edx
call   1030 <m4errx@plt>
mov    %r14d,%ebp
neg    %ebp
cmovs  %r14d,%ebp
mov    $0x1,%ebx
lea    0xe8f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
cltd
idiv   %r15d
movslq %edx,%rcx
movsbl (%rcx,%r13,1),%edi
mov    %eax,%ebp
call   1040 <pushback@plt>
add    $0x1,%ebx
test   %ebp,%ebp
jg     1180 <pbnumbase+0x60>
lea    -0x1(%rbx),%eax
test   %r14d,%r14d
cmovs  %ebx,%eax
cmp    %r12d,%eax
jge    11c0 <pbnumbase+0xa0>
sub    %eax,%r12d
nopl   (%rax)
mov    $0x30,%edi
call   1040 <pushback@plt>
add    $0xffffffff,%r12d
jne    11b0 <pbnumbase+0x90>
test   %r14d,%r14d
js     11d4 <pbnumbase+0xb4>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <pushback@plt>

LLVM IR (-O0):
@pbnumbase.digits = internal global [36 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz"
@.str = [29 x i8] c"base %d > 36: not supported.\00"
@.str.1 = [28 x i8] c"bad base %d for conversion.\00"
define void @pbnumbase(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 36
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %5
%13 = call i32 @m4errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %3
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %5
%19 = call i32 @m4errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %14
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %4
%25 = sub nsw i32 0, %24
br label %28
26: ; preds = %20
%27 = load i32, i32* %4
br label %28
28: ; preds = %26, %23
%29 = phi i32 [ %25, %23 ], [ %27, %26 ]
store i32 %29, i32* %7
br label %30
30: ; preds = %40, %28
%31 = load i32, i32* %7
%32 = load i32, i32* %5
%33 = srem i32 %31, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [36 x i8], [36 x i8]* @pbnumbase.digits, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @pushback(i8 signext %36)
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %40
40: ; preds = %30
%41 = load i32, i32* %5
%42 = load i32, i32* %7
%43 = sdiv i32 %42, %41
store i32 %43, i32* %7
%44 = icmp sgt i32 %43, 0
br i1 %44, label %30, label %45
45: ; preds = %40
%46 = load i32, i32* %4
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %57, %51
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
%55 = load i32, i32* %6
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @pushback(i8 signext 48)
br label %52
59: ; preds = %52
%60 = load i32, i32* %4
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 @pushback(i8 signext 45)
br label %64
64: ; preds = %62, %59
ret void
}

LLVM IR (-O2):
@pbnumbase.digits = internal unnamed_addr constant [36 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz"
@.str = [29 x i8] c"base %d > 36: not supported.\00"
@.str.1 = [28 x i8] c"bad base %d for conversion.\00"
define void @pbnumbase(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 36
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = icmp slt i32 %1, 2
br i1 %6, label %7, label %10
7: ; preds = %5, %3
%8 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %5 ]
%9 = tail call i32 @m4errx(i32 1, i8* %8, i32 %1)
br label %10
10: ; preds = %7, %5
%11 = icmp slt i32 %0, 0
%12 = sub nsw i32 0, %0
%13 = select i1 %11, i32 %12, i32 %0
br label %14
14: ; preds = %14, %10
%15 = phi i32 [ %13, %10 ], [ %23, %14 ]
%16 = phi i32 [ 0, %10 ], [ %22, %14 ]
%17 = srem i32 %15, %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [36 x i8], [36 x i8]* @pbnumbase.digits, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @pushback(i8 signext %20)
%22 = add nuw nsw i32 %16, 1
%23 = sdiv i32 %15, %1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %14, label %25
25: ; preds = %14
%26 = add nuw nsw i32 %16, 2
%27 = select i1 %11, i32 %26, i32 %22
%28 = icmp slt i32 %27, %2
br i1 %28, label %29, label %34
29: ; preds = %25, %29
%30 = phi i32 [ %31, %29 ], [ %27, %25 ]
%31 = add i32 %30, 1
%32 = tail call i32 @pushback(i8 signext 48)
%33 = icmp eq i32 %31, %2
br i1 %33, label %34, label %29
34: ; preds = %29, %25
br i1 %11, label %35, label %37
35: ; preds = %34
%36 = tail call i32 @pushback(i8 signext 45)
br label %37
37: ; preds = %35, %34
ret void
}