#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 digitcount_from_bitlen(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *radix_uint2str(unsigned value, int radix, int bitlen, int use_prefix) {
  static char buffer[80];
  int digitcount = 0;
  if (bitlen > 0)
    digitcount = digitcount_from_bitlen(radix, bitlen);
  if (radix == 10)
    sprintf(buffer, "%0*u", digitcount, value);
  else if (radix == 8)
    sprintf(buffer, "%s%0*o", use_prefix ? "0" : "", digitcount, value);
  else if (radix == 16)
    sprintf(buffer, "%s%0*x", use_prefix ? "0x" : "", digitcount, value);
  else {
    fprintf(stderr, "radix_uint2str(): radix must be 10, 8 or 16\n");
    exit(1);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<radix_uint2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1173 <radix_uint2str+0x33>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <digitcount_from_bitlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xa,-0x8(%rbp)
jne    119d <radix_uint2str+0x5d>
mov    -0x14(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    0x2ec6(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    124c <radix_uint2str+0x10c>
cmpl   $0x8,-0x8(%rbp)
jne    11e0 <radix_uint2str+0xa0>
mov    -0x10(%rbp),%ecx
lea    0xe93(%rip),%rdx
lea    0xe54(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%r8d
lea    0x2e83(%rip),%rdi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1247 <radix_uint2str+0x107>
cmpl   $0x10,-0x8(%rbp)
jne    1223 <radix_uint2str+0xe3>
mov    -0x10(%rbp),%ecx
lea    0xe50(%rip),%rdx
lea    0xe1a(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%r8d
lea    0x2e40(%rip),%rdi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1242 <radix_uint2str+0x102>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1247 <radix_uint2str+0x107>
jmp    124c <radix_uint2str+0x10c>
lea    0x2dfd(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<radix_uint2str>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
test   %edx,%edx
jle    1185 <radix_uint2str+0x45>
mov    %ebx,%edi
mov    %edx,%esi
call   1040 <digitcount_from_bitlen@plt>
mov    %eax,%ecx
cmp    $0x8,%ebx
je     118c <radix_uint2str+0x4c>
cmp    $0x10,%ebx
je     11b0 <radix_uint2str+0x70>
cmp    $0xa,%ebx
jne    11e8 <radix_uint2str+0xa8>
lea    0x2ee0(%rip),%rdi
lea    0xe89(%rip),%rsi
mov    %ecx,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11dc <radix_uint2str+0x9c>
xor    %ecx,%ecx
cmp    $0x8,%ebx
jne    115f <radix_uint2str+0x1f>
test   %ebp,%ebp
lea    0xeaf(%rip),%rax
lea    0xe70(%rip),%rdx
cmove  %rax,%rdx
lea    0x2ea9(%rip),%rdi
lea    0xe57(%rip),%rsi
jmp    11d2 <radix_uint2str+0x92>
test   %ebp,%ebp
lea    0xe8b(%rip),%rax
lea    0xe55(%rip),%rdx
cmove  %rax,%rdx
lea    0x2e85(%rip),%rdi
lea    0xe3c(%rip),%rsi
mov    %r14d,%r8d
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0x2e6d(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@radix_uint2str.buffer = internal global [80 x i8] zeroinitializer
@.str = [5 x i8] c"%0*u\00"
@.str.1 = [7 x i8] c"%s%0*o\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [7 x i8] c"%s%0*x\00"
@.str.5 = [3 x i8] c"0x\00"
@stderr = global i32 0
@.str.6 = [45 x i8] c"radix_uint2str(): radix must be 10, 8 or 16\0A\00"
define i8* @radix_uint2str(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %7
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = call i32 @digitcount_from_bitlen(i32 %13, i32 %14)
store i32 %15, i32* %9
br label %16
16: ; preds = %12, %4
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %9
%21 = load i32, i32* %5
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
br label %51
23: ; preds = %16
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 8
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%31 = load i32, i32* %9
%32 = load i32, i32* %5
%33 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31, i32 %32)
br label %50
34: ; preds = %23
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 16
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i32, i32* %8
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%42 = load i32, i32* %9
%43 = load i32, i32* %5
%44 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %41, i32 %42, i32 %43)
br label %49
45: ; preds = %34
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %37
br label %50
50: ; preds = %49, %26
br label %51
51: ; preds = %50, %19
ret i8* getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@radix_uint2str.buffer = internal global [80 x i8] zeroinitializer
@.str = [5 x i8] c"%0*u\00"
@.str.1 = [7 x i8] c"%s%0*o\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [7 x i8] c"%s%0*x\00"
@.str.5 = [3 x i8] c"0x\00"
@stderr = global i32 0
@.str.6 = [45 x i8] c"radix_uint2str(): radix must be 10, 8 or 16\0A\00"
define i8* @radix_uint2str(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @digitcount_from_bitlen(i32 %1, i32 %2)
br label %8
8: ; preds = %6, %4
%9 = phi i32 [ %7, %6 ], [ 0, %4 ]
switch i32 %1, label %20 [
i32 10, label %10
i32 8, label %12
i32 16, label %16
]
10: ; preds = %8
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %0)
br label %24
12: ; preds = %8
%13 = icmp eq i32 %3, 0
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%15 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %9, i32 %0)
br label %24
16: ; preds = %8
%17 = icmp eq i32 %3, 0
%18 = select i1 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0)
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %18, i32 %9, i32 %0)
br label %24
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %12, %16, %10
ret i8* getelementptr inbounds ([80 x i8], [80 x i8]* @radix_uint2str.buffer, i64 0, i64 0)
}