#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
int *getEnumWidth(int max) {
  int i;
  char buf[15];
  int *numericWidth = malloc(sizeof(int) * max);
  sprintf(buf, "%d", max);
  int max_len = strlen(buf);
  for (i = max; i > 0; i--) {
    sprintf(buf, "%d", i);
    numericWidth[i] = max_len - strlen(buf);
  }
  return numericWidth;
}


x86 assembly (clang, -O0):
<getEnumWidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0x17(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x17(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11bd <getEnumWidth+0x8d>
lea    -0x17(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe75(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x17(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%edx
sub    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1173 <getEnumWidth+0x43>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getEnumWidth>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
lea    0xeaa(%rip),%rsi
lea    0x1(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %r14d,%r14d
jle    11bb <getEnumWidth+0x8b>
mov    %eax,%r12d
mov    %r14d,%ebx
lea    0xe80(%rip),%r14
lea    0x1(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r12d,%ecx
sub    %eax,%ecx
mov    %ecx,(%r15,%rbx,4)
lea    -0x1(%rbx),%rax
cmp    $0x1,%rbx
mov    %rax,%rbx
ja     1190 <getEnumWidth+0x60>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define noalias i32* @getEnumWidth(i32 %0) {
%2 = alloca [15 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%4 = shl i32 %0, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32 @strlen(i8* %3)
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ %10, %9 ], [ %18, %11 ]
%13 = trunc i64 %12 to i32
%14 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @strlen(i8* %3)
%16 = sub nsw i32 %7, %15
%17 = getelementptr inbounds i32, i32* %5, i64 %12
store i32 %16, i32* %17
%18 = add nsw i64 %12, -1
%19 = icmp ugt i64 %12, 1
br i1 %19, label %11, label %20
20: ; preds = %11, %1
ret i32* %5
}