#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*/ fcvt(int, int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
void itoa(char *s, int nr) {
  int dec, sign;
  char temp[30];
  strcpy(temp, fcvt(nr, 0, &dec, &sign));
  if (sign == 0) {
    strncpy(s, temp, dec);
    s[dec] = '\0';
  } else {
    s[0] = '-';
    strncpy(s + 1, temp, dec);
    s[dec + 1] = '\0';
  }
}


x86 assembly (clang, -O0):
<itoa>:
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    -0xc(%rbp),%edi
xor    %esi,%esi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1050 <fcvt@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
cmpl   $0x0,-0x14(%rbp)
jne    118f <itoa+0x5f>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11bb <itoa+0x8b>
mov    -0x8(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %esi,%edi
xor    %esi,%esi
call   1050 <fcvt@plt>
lea    0x10(%rsp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
cmpl   $0x0,0xc(%rsp)
je     117c <itoa+0x4c>
movb   $0x2d,(%rbx)
lea    0x1(%rbx),%rdi
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rsi
call   1030 <strncpy@plt>
mov    0x8(%rsp),%eax
add    $0x1,%eax
jmp    1191 <itoa+0x61>
mov    0x8(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    0x8(%rsp),%eax
cltq
movb   $0x0,(%rbx,%rax,1)
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @itoa(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [30 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @fcvt(i32 %9, i32 0, i32* %5, i32* %6)
%11 = call i32 @strcpy(i8* %8, i32 %10)
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %5
%18 = call i32 @strncpy(i8* %15, i8* %16, i32 %17)
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
br label %36
23: ; preds = %2
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 45, i8* %25
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%29 = load i32, i32* %5
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %23, %14
ret void
}

LLVM IR (-O2):
define void @itoa(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [30 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%9 = call i32 @fcvt(i32 %1, i32 0, i32* %3, i32* %4)
%10 = call i32 @strcpy(i8* %8, i32 %9)
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* %3
%15 = call i32 @strncpy(i8* %0, i8* %8, i32 %14)
%16 = load i32, i32* %3
br label %23
17: ; preds = %2
store i8 45, i8* %0
%18 = getelementptr inbounds i8, i8* %0, i64 1
%19 = load i32, i32* %3
%20 = call i32 @strncpy(i8* %18, i8* %8, i32 %19)
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
br label %23
23: ; preds = %17, %13
%24 = phi i32 [ %22, %17 ], [ %16, %13 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 0, i8* %26
ret void
}