#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, int *, int);
char itos(char *d, uint32_t x) {
  uint8_t t[11], *p = t;
  p += 11;
  *--p = 0;
  do {
    *--p = '0' + x % 10;
    x /= 10;
  } while (x);
  memcpy(d, p, 11 - (p - t));
  return 11 - (p - t);
}


x86 assembly (clang, -O0):
<itos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x2c,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x48(%rbp)
movl   $0x0,-0x4(%rax)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x48(%rbp)
mov    %edx,-0x4(%rax)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1149 <itos+0x39>
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    $0xb,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x48(%rbp),%rcx
lea    -0x40(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    $0xb,%eax
sub    %rcx,%rax
movsbl %al,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itos>:
push   %rbx
sub    $0x30,%rsp
movl   $0x0,0x28(%rsp)
mov    $0x28,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %esi,%rcx
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rbx
shr    $0x3f,%rbx
sar    $0x22,%rdx
add    %ebx,%edx
lea    (%rdx,%rdx,1),%ebx
lea    (%rbx,%rbx,4),%ebx
neg    %ebx
add    %ebx,%esi
add    $0x30,%esi
mov    %esi,-0x4(%rsp,%rax,1)
add    $0x9,%ecx
add    $0xfffffffffffffffc,%rax
mov    %edx,%esi
cmp    $0x12,%ecx
ja     1130 <itos+0x20>
lea    (%rsp,%rax,1),%rsi
sar    $0x2,%rax
mov    $0xb,%ebx
sub    %rax,%rbx
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @itos(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [11 x i32]
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 0
store i32* %7, i32** %6
%8 = load i32*, i32** %6
%9 = getelementptr inbounds i32, i32* %8, i64 11
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = getelementptr inbounds i32, i32* %10, i32 -1
store i32* %11, i32** %6
store i32 0, i32* %11
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %4
%14 = srem i32 %13, 10
%15 = add nsw i32 48, %14
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i32 -1
store i32* %17, i32** %6
store i32 %15, i32* %17
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 10
store i32 %19, i32* %4
br label %20
20: ; preds = %12
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %12, label %23
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i32*, i32** %6
%26 = load i32*, i32** %6
%27 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 0
%28 = ptrtoint i32* %26 to i64
%29 = ptrtoint i32* %27 to i64
%30 = sub i64 %28, %29
%31 = sdiv exact i64 %30, 4
%32 = sub nsw i64 11, %31
%33 = trunc i64 %32 to i32
%34 = call i32 @memcpy(i8* %24, i32* %25, i32 %33)
%35 = load i32*, i32** %6
%36 = getelementptr inbounds [11 x i32], [11 x i32]* %5, i64 0, i64 0
%37 = ptrtoint i32* %35 to i64
%38 = ptrtoint i32* %36 to i64
%39 = sub i64 %37, %38
%40 = sdiv exact i64 %39, 4
%41 = sub nsw i64 11, %40
%42 = trunc i64 %41 to i8
ret i8 %42
}

LLVM IR (-O2):
define signext i8 @itos(i8* %0, i32 %1) {
%3 = alloca [11 x i32]
%4 = bitcast [11 x i32]* %3 to i8*
%5 = getelementptr inbounds [11 x i32], [11 x i32]* %3, i64 0, i64 10
store i32 0, i32* %5
br label %6
6: ; preds = %6, %2
%7 = phi i32 [ %1, %2 ], [ %12, %6 ]
%8 = phi i32* [ %5, %2 ], [ %11, %6 ]
%9 = srem i32 %7, 10
%10 = add nsw i32 %9, 48
%11 = getelementptr inbounds i32, i32* %8, i64 -1
store i32 %10, i32* %11
%12 = sdiv i32 %7, 10
%13 = add i32 %7, 9
%14 = icmp ult i32 %13, 19
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = ptrtoint i32* %11 to i64
%17 = ptrtoint [11 x i32]* %3 to i64
%18 = sub i64 %16, %17
%19 = ashr exact i64 %18, 2
%20 = sub nsw i64 11, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @memcpy(i8* %0, i32* %11, i32 %21)
%23 = trunc i64 %20 to i8
ret i8 %23
}