#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 */
char *itoa(unsigned int n, unsigned int base, unsigned int width) {
  if (base < 2 || base > 16) {
    return NULL;
  }
  static const char *digits = "0123456789abcdef";
  static char buffer[65];
  char *s = &buffer[64];
  unsigned int count = 0;
  do {
    *--s = digits[n % base];
    n /= base;
    count++;
  } while (count < width || n != 0);
  return s;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x2,-0x10(%rbp)
jb     1121 <itoa+0x21>
cmpl   $0x10,-0x10(%rbp)
jbe    112e <itoa+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <itoa+0xb6>
lea    0x2f0b(%rip),%rax
add    $0x40,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2ed5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    -0x30(%rbp),%rax
mov    %edx,%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    $0x1,%al
cmp    -0x14(%rbp),%ecx
mov    %al,-0x31(%rbp)
jb     11a3 <itoa+0xa3>
cmpl   $0x0,-0xc(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1144 <itoa+0x44>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
lea    -0x11(%rsi),%ecx
cmp    $0xfffffff1,%ecx
jae    110f <itoa+0xf>
xor    %r11d,%r11d
mov    %r11,%rax
ret
mov    %edx,%r8d
mov    %edi,%eax
lea    0x2f55(%rip),%r11
mov    $0x1,%r10d
lea    0xed8(%rip),%r9
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
xor    %edx,%edx
div    %esi
mov    %r10d,%edi
movzbl (%rdx,%r9,1),%edx
mov    %dl,-0x1(%r11)
add    $0xffffffffffffffff,%r11
lea    0x1(%rdi),%r10d
cmp    %r8d,%edi
jb     1130 <itoa+0x30>
cmp    %esi,%ecx
jae    1130 <itoa+0x30>
mov    %r11,%rax
ret

LLVM IR (-O0):
@itoa.digits = internal global i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0)
@.str = [17 x i8] c"0123456789abcdef\00"
@itoa.buffer = internal global [65 x i8] zeroinitializer
define i8* @itoa(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp ult i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp ugt i32 %13, 16
br i1 %14, label %15, label %16
15: ; preds = %12, %3
store i8* null, i8** %4
br label %43
16: ; preds = %12
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @itoa.buffer, i64 0, i64 64), i8** %8
store i32 0, i32* %9
br label %17
17: ; preds = %39, %16
%18 = load i8*, i8** @itoa.digits
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = urem i32 %19, %20
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i32 -1
store i8* %26, i8** %8
store i8 %24, i8* %26
%27 = load i32, i32* %6
%28 = load i32, i32* %5
%29 = udiv i32 %28, %27
store i32 %29, i32* %5
%30 = load i32, i32* %9
%31 = add i32 %30, 1
store i32 %31, i32* %9
br label %32
32: ; preds = %17
%33 = load i32, i32* %9
%34 = load i32, i32* %7
%35 = icmp ult i32 %33, %34
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* %5
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %36, %32
%40 = phi i1 [ true, %32 ], [ %38, %36 ]
br i1 %40, label %17, label %41
41: ; preds = %39
%42 = load i8*, i8** %8
store i8* %42, i8** %4
br label %43
43: ; preds = %41, %15
%44 = load i8*, i8** %4
ret i8* %44
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@itoa.buffer = internal global [65 x i8] zeroinitializer
define i8* @itoa(i32 %0, i32 %1, i32 %2) {
%4 = add i32 %1, -17
%5 = icmp ult i32 %4, -15
br i1 %5, label %20, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %15, %6 ], [ %0, %3 ]
%8 = phi i8* [ %14, %6 ], [ getelementptr inbounds ([65 x i8], [65 x i8]* @itoa.buffer, i64 0, i64 64), %3 ]
%9 = phi i32 [ %16, %6 ], [ 0, %3 ]
%10 = urem i32 %7, %1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %13, i8* %14
%15 = udiv i32 %7, %1
%16 = add i32 %9, 1
%17 = icmp ult i32 %16, %2
%18 = icmp uge i32 %7, %1
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %6, label %20
20: ; preds = %6, %3
%21 = phi i8* [ null, %3 ], [ %14, %6 ]
ret i8* %21
}