#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 */
char *calloc(unsigned int, int);
int get_number_count_digits(long long);
int /*<<< orphan*/ sprintf(char *, char *, long long);
char *number_itoa(long long int number) {
  unsigned int len;
  if (number < 0) {
    len = get_number_count_digits(number) + 1;
  } else if (number == 0)
    len = 1;
  else
    len = get_number_count_digits(number);
  char *buffer = calloc(len, sizeof(char));
  sprintf(buffer, "%lli", number);
  return buffer;
}


x86 assembly (clang, -O0):
<number_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    115b <number_itoa+0x2b>
mov    -0x8(%rbp),%rdi
call   1040 <get_number_count_digits@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1183 <number_itoa+0x53>
cmpq   $0x0,-0x8(%rbp)
jne    1172 <number_itoa+0x42>
movl   $0x1,-0xc(%rbp)
jmp    117e <number_itoa+0x4e>
mov    -0x8(%rbp),%rdi
call   1040 <get_number_count_digits@plt>
mov    %eax,-0xc(%rbp)
jmp    1183 <number_itoa+0x53>
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_itoa>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
js     114a <number_itoa+0x1a>
je     1159 <number_itoa+0x29>
mov    %r14,%rdi
call   1040 <get_number_count_digits@plt>
mov    %eax,%edi
jmp    115e <number_itoa+0x2e>
mov    %r14,%rdi
call   1040 <get_number_count_digits@plt>
mov    %eax,%edi
add    $0x1,%edi
jmp    115e <number_itoa+0x2e>
mov    $0x1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lli\00"
define i8* @number_itoa(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8*
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i64, i64* %2
%9 = call i32 @get_number_count_digits(i64 %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
br label %19
11: ; preds = %1
%12 = load i64, i64* %2
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %3
br label %18
15: ; preds = %11
%16 = load i64, i64* %2
%17 = call i32 @get_number_count_digits(i64 %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %15, %14
br label %19
19: ; preds = %18, %7
%20 = load i32, i32* %3
%21 = call i8* @calloc(i32 %20, i32 1)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = load i64, i64* %2
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lli\00"
define noalias i8* @number_itoa(i64 %0) {
%2 = icmp slt i64 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @get_number_count_digits(i64 %0)
%5 = add nsw i32 %4, 1
br label %10
6: ; preds = %1
%7 = icmp eq i64 %0, 0
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 @get_number_count_digits(i64 %0)
br label %10
10: ; preds = %6, %8, %3
%11 = phi i32 [ %5, %3 ], [ %9, %8 ], [ 1, %6 ]
%12 = tail call i8* @calloc(i32 %11, i32 1)
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %0)
ret i8* %12
}