#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 */
scalar_t__ floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(double);
char *malloc(int);
char *numStr_int(int number) {
  int len = (int)floor(log10((double)number)) + 1;
  char *out = malloc(len * sizeof(char));
  while (number) {
    len--;
    out[len] = number % 10 + 48;
    number = number / 10;
  }
  return out;
}


x86 assembly (clang, -O0):
<numStr_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
call   1040 <log10@plt>
mov    %eax,%edi
call   1050 <floor@plt>
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11a4 <numStr_int+0x74>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1165 <numStr_int+0x35>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numStr_int>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
cvtsi2sd %edi,%xmm0
call   1040 <log10@plt>
mov    %eax,%edi
call   1050 <floor@plt>
mov    %rax,%r14
add    $0x1,%r14d
mov    %r14d,%edi
call   1030 <malloc@plt>
test   %ebx,%ebx
je     11a4 <numStr_int+0x74>
movslq %r14d,%rcx
add    %rax,%rcx
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebx,%rdx
imul   $0x66666667,%rdx,%rbx
mov    %rbx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rbx
add    %esi,%ebx
lea    (%rbx,%rbx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
add    $0x30,%dil
mov    %dil,(%rcx)
add    $0x9,%edx
add    $0xffffffffffffffff,%rcx
cmp    $0x12,%edx
ja     1170 <numStr_int+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @numStr_int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sitofp i32 %5 to double
%7 = call i32 @log10(double %6)
%8 = call i64 @floor(i32 %7)
%9 = trunc i64 %8 to i32
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %4
br label %16
16: ; preds = %19, %1
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
%22 = load i32, i32* %2
%23 = srem i32 %22, 10
%24 = add nsw i32 %23, 48
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i32, i32* %2
%31 = sdiv i32 %30, 10
store i32 %31, i32* %2
br label %16
32: ; preds = %16
%33 = load i8*, i8** %4
ret i8* %33
}

LLVM IR (-O2):
define noalias i8* @numStr_int(i32 %0) {
%2 = sitofp i32 %0 to double
%3 = tail call i32 @log10(double %2)
%4 = tail call i64 @floor(i32 %3)
%5 = trunc i64 %4 to i32
%6 = add nsw i32 %5, 1
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i32 %0, 0
br i1 %8, label %22, label %9
9: ; preds = %1
%10 = sext i32 %6 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ %10, %9 ], [ %14, %11 ]
%13 = phi i32 [ %0, %9 ], [ %19, %11 ]
%14 = add i64 %12, -1
%15 = srem i32 %13, 10
%16 = trunc i32 %15 to i8
%17 = add nsw i8 %16, 48
%18 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 %17, i8* %18
%19 = sdiv i32 %13, 10
%20 = add i32 %13, 9
%21 = icmp ult i32 %20, 19
br i1 %21, label %22, label %11
22: ; preds = %11, %1
ret i8* %7
}