#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ reverse(char *);
int /*<<< orphan*/ stderr;
void itob(int n, char *s, int b) {
  char *digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int i, sign;
  if (b < 2 || b > 36) {
    fprintf(stderr, "can not support  base %d\n", b);
    exit(EXIT_FAILURE);
  }
  if ((sign = 0) < 0) {
    n = -n;
  }
  do {
    s[i++] = digits[n % b];
  } while ((n /= b) > 0);
  if (sign < 0) {
    s[i++] = '-';
  }
  s[i] = '\0';
  reverse(s);
}


x86 assembly (clang, -O0):
<itob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xeb7(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     1161 <itob+0x31>
cmpl   $0x24,-0x14(%rbp)
jle    1187 <itob+0x57>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xeb1(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movl   $0x0,-0x28(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    119d <itob+0x6d>
jmp    11a5 <itob+0x75>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <itob+0x7a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jg     11aa <itob+0x7a>
cmpl   $0x0,-0x28(%rbp)
jge    120d <itob+0xdd>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itob>:
push   %rax
mov    %edx,%r10d
lea    -0x25(%r10),%ecx
cmp    $0xffffffdd,%ecx
jb     118a <itob+0x5a>
mov    %edi,%eax
xor    %edi,%edi
lea    0xeb8(%rip),%r8
movabs $0x100000000,%r9
mov    %rsi,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
cltd
idiv   %r10d
movslq %edx,%rdx
movzbl (%rdx,%r8,1),%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
add    %r9,%rdi
test   %eax,%eax
jg     1160 <itob+0x30>
sar    $0x20,%rdi
movb   $0x0,(%rsi,%rdi,1)
mov    %rsi,%rdi
pop    %rax
jmp    1030 <reverse@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %r10d,%edx
call   1040 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"can not support base %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @itob(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp sgt i32 %13, 36
br i1 %14, label %15, label %21
15: ; preds = %12, %3
%16 = load i32, i32* @stderr
%17 = load i32, i32* %6
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %12
store i32 0, i32* %9
br i1 false, label %22, label %25
22: ; preds = %21
%23 = load i32, i32* %4
%24 = sub nsw i32 0, %23
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %21
br label %26
26: ; preds = %39, %25
%27 = load i8*, i8** %7
%28 = load i32, i32* %4
%29 = load i32, i32* %6
%30 = srem i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %5
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
br label %39
39: ; preds = %26
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = sdiv i32 %41, %40
store i32 %42, i32* %4
%43 = icmp sgt i32 %42, 0
br i1 %43, label %26, label %44
44: ; preds = %39
%45 = load i32, i32* %9
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = load i8*, i8** %5
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
store i8 45, i8* %52
br label %53
53: ; preds = %47, %44
%54 = load i8*, i8** %5
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %5
%59 = call i32 @reverse(i8* %58)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"can not support base %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @itob(i32 %0, i8* %1, i32 %2) {
%4 = add i32 %2, -37
%5 = icmp ult i32 %4, -35
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3, %11
%12 = phi i64 [ %18, %11 ], [ 0, %3 ]
%13 = phi i32 [ %20, %11 ], [ %0, %3 ]
%14 = srem i32 %13, %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [37 x i8], [37 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = add i64 %12, 1
%19 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %17, i8* %19
%20 = sdiv i32 %13, %2
%21 = icmp sgt i32 %20, 0
br i1 %21, label %11, label %22
22: ; preds = %11
%23 = shl i64 %18, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @reverse(i8* %1)
ret void
}