#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*/ sprintf(char *, char *, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *itoa(unsigned int value, char *string, int radix, int len) {
  int z;
  char sTemp[255];
  strcpy(string, "");
  for (z = 0; z < len; z++) {
    if ((value % radix) < 10) {
      sprintf(sTemp, "%c%s", 48 + value % radix, string);
      strcpy(string, sTemp);
    } else {
      sprintf(sTemp, "%c%s", 55 + value % radix, string);
      strcpy(string, sTemp);
    }
    value = value / radix;
  }
  return string;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ee <itoa+0xce>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
cmp    $0xa,%edx
jae    11a3 <itoa+0x83>
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
add    $0x30,%edx
mov    -0x10(%rbp),%rcx
lea    0xe77(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11d5 <itoa+0xb5>
lea    -0x120(%rbp),%rdi
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
add    $0x37,%edx
mov    -0x10(%rbp),%rcx
lea    0xe40(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <itoa+0x2f>
mov    -0x10(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xec2(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
test   %ebx,%ebx
jle    1195 <itoa+0x75>
lea    0xeab(%rip),%r12
mov    %rsp,%r13
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
xor    %edx,%edx
div    %r15d
lea    0x37(%rdx),%esi
lea    0x30(%rdx),%ecx
cmp    $0xa,%edx
cmovae %esi,%ecx
mov    %eax,%ebp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ecx,%edx
mov    %r14,%rcx
call   1040 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
add    $0xffffffff,%ebx
jne    1160 <itoa+0x40>
mov    %r14,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%c%s\00"
define i8* @itoa(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [255 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %6
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %13
13: ; preds = %48, %4
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %51
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = urem i32 %18, %19
%21 = icmp ult i32 %20, 10
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = urem i32 %24, %25
%27 = add i32 48, %26
%28 = load i8*, i8** %6
%29 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %28)
%30 = load i8*, i8** %6
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%32 = call i32 @strcpy(i8* %30, i8* %31)
br label %44
33: ; preds = %17
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%35 = load i32, i32* %5
%36 = load i32, i32* %7
%37 = urem i32 %35, %36
%38 = add i32 55, %37
%39 = load i8*, i8** %6
%40 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %39)
%41 = load i8*, i8** %6
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
br label %44
44: ; preds = %33, %22
%45 = load i32, i32* %5
%46 = load i32, i32* %7
%47 = udiv i32 %45, %46
store i32 %47, i32* %5
br label %48
48: ; preds = %44
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %13
51: ; preds = %13
%52 = load i8*, i8** %6
ret i8* %52
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%c%s\00"
define i8* @itoa(i32 %0, i8* returned %1, i32 %2, i32 %3) {
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %21
9: ; preds = %4, %9
%10 = phi i32 [ %19, %9 ], [ 0, %4 ]
%11 = phi i32 [ %18, %9 ], [ %0, %4 ]
%12 = urem i32 %11, %2
%13 = icmp ult i32 %12, 10
%14 = select i1 %13, i32 48, i32 55
%15 = add i32 %12, %14
%16 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %1)
%17 = call i32 @strcpy(i8* %1, i8* %6)
%18 = udiv i32 %11, %2
%19 = add nuw nsw i32 %10, 1
%20 = icmp eq i32 %19, %3
br i1 %20, label %21, label %9
21: ; preds = %9, %4
ret i8* %1
}