#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_to_str(int value) {
  static char buff[32];
  char *p;
  int sign;
  p = buff + 31;
  if (value >= 0)
    sign = 0;
  else {
    if (-value == value) {
      sprintf(buff, "%d", value);
      return buff;
    }
    value = -value;
    sign = 1;
  }
  do {
    *--p = value % 10 + '0';
    value /= 10;
  } while (value > 0);
  if (sign)
    *--p = '-';
  return p;
}


x86 assembly (clang, -O0):
<int_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
lea    0x2f1e(%rip),%rax
add    $0x1f,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1140 <int_to_str+0x30>
movl   $0x0,-0x1c(%rbp)
jmp    1183 <int_to_str+0x73>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1174 <int_to_str+0x64>
mov    -0xc(%rbp),%edx
lea    0x2ee8(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2ed5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e7 <int_to_str+0xd7>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
jmp    1188 <int_to_str+0x78>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1188 <int_to_str+0x78>
cmpl   $0x0,-0x1c(%rbp)
je     11df <int_to_str+0xcf>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,-0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_str>:
mov    %edi,%ecx
neg    %ecx
cmovs  %edi,%ecx
lea    0x2f40(%rip),%rax
xchg   %ax,%ax
movslq %ecx,%rdx
imul   $0x66666667,%rdx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rcx
add    %esi,%ecx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%r8d
mov    %edx,%esi
sub    %r8d,%esi
add    $0x30,%sil
mov    %sil,(%rax)
add    $0xffffffffffffffff,%rax
cmp    $0x9,%edx
jg     1110 <int_to_str+0x10>
test   %edi,%edi
js     114c <int_to_str+0x4c>
add    $0x1,%rax
ret
movb   $0x2d,(%rax)
ret

LLVM IR (-O0):
@int_to_str.buff = internal global [32 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @int_to_str(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @int_to_str.buff, i64 0, i64 31), i8** %4
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %5
br label %20
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sub nsw i32 0, %10
%12 = load i32, i32* %3
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @int_to_str.buff, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @int_to_str.buff, i64 0, i64 0), i8** %2
br label %41
17: ; preds = %9
%18 = load i32, i32* %3
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
store i32 1, i32* %5
br label %20
20: ; preds = %17, %8
br label %21
21: ; preds = %30, %20
%22 = load i32, i32* %3
%23 = srem i32 %22, 10
%24 = add nsw i32 %23, 48
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %4
store i8 %25, i8* %27
%28 = load i32, i32* %3
%29 = sdiv i32 %28, 10
store i32 %29, i32* %3
br label %30
30: ; preds = %21
%31 = load i32, i32* %3
%32 = icmp sgt i32 %31, 0
br i1 %32, label %21, label %33
33: ; preds = %30
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %4
store i8 45, i8* %38
br label %39
39: ; preds = %36, %33
%40 = load i8*, i8** %4
store i8* %40, i8** %2
br label %41
41: ; preds = %39, %14
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
@int_to_str.buff = internal global [32 x i8] zeroinitializer
define i8* @int_to_str(i32 %0) {
%2 = icmp sgt i32 %0, -1
%3 = sub nsw i32 0, %0
%4 = select i1 %2, i32 %0, i32 %3
br label %5
5: ; preds = %5, %1
%6 = phi i32 [ %4, %1 ], [ %12, %5 ]
%7 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @int_to_str.buff, i64 0, i64 31), %1 ], [ %11, %5 ]
%8 = srem i32 %6, 10
%9 = trunc i32 %8 to i8
%10 = add nsw i8 %9, 48
%11 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 %10, i8* %11
%12 = sdiv i32 %6, 10
%13 = icmp sgt i32 %6, 9
br i1 %13, label %5, label %14
14: ; preds = %5
br i1 %2, label %17, label %15
15: ; preds = %14
%16 = getelementptr inbounds i8, i8* %7, i64 -2
store i8 45, i8* %16
br label %17
17: ; preds = %14, %15
%18 = phi i8* [ %16, %15 ], [ %11, %14 ]
ret i8* %18
}