#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 *malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *plainnum(const void *a) {
  size_t len;
  int i;
  char *num;
  i = *(int *)a;
  len = 1;
  while ((i /= 10))
    ++len;
  if (!(num = malloc(len + 1)))
    return NULL;
  sprintf(num, "%d", *(int *)a);
  return num;
}


x86 assembly (clang, -O0):
<plainnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1165 <plainnum+0x45>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <plainnum+0x1d>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    118d <plainnum+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11ab <plainnum+0x8b>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plainnum>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%r14d
lea    0x9(%r14),%eax
mov    $0x2,%edi
cmp    $0x13,%eax
jb     1165 <plainnum+0x45>
mov    $0x2,%edi
mov    %r14d,%eax
nopl   (%rax)
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
lea    (%rcx,%rdx,1),%eax
add    $0x1,%rdi
add    %edx,%ecx
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1140 <plainnum+0x20>
call   1030 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1184 <plainnum+0x64>
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @plainnum(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %5
store i64 1, i64* %4
br label %10
10: ; preds = %14, %1
%11 = load i32, i32* %5
%12 = sdiv i32 %11, 10
store i32 %12, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i64, i64* %4
%16 = add i64 %15, 1
store i64 %16, i64* %4
br label %10
17: ; preds = %10
%18 = load i64, i64* %4
%19 = add i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %17
store i8* null, i8** %2
br label %30
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = load i8*, i8** %3
%26 = bitcast i8* %25 to i32*
%27 = load i32, i32* %26
%28 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %6
store i8* %29, i8** %2
br label %30
30: ; preds = %23, %22
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define noalias i8* @plainnum(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = add i32 %3, 9
%5 = icmp ult i32 %4, 19
br i1 %5, label %13, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %9, %6 ], [ %3, %1 ]
%8 = phi i64 [ %10, %6 ], [ 2, %1 ]
%9 = sdiv i32 %7, 10
%10 = add i64 %8, 1
%11 = add nsw i32 %9, 9
%12 = icmp ult i32 %11, 19
br i1 %12, label %13, label %6
13: ; preds = %6, %1
%14 = phi i64 [ 2, %1 ], [ %10, %6 ]
%15 = tail call i8* @malloc(i64 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %19
19: ; preds = %13, %17
ret i8* %15
}