#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(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *arrayDisplay(int *array, int array_size) {
  int loop_counter = 0;
  int number_of_elements = array_size;
  char *buffer, item[10];
  int number_of_elements_on_buffer = (number_of_elements * 2) + 2 + 1;
  buffer = malloc(number_of_elements_on_buffer * 5 * sizeof(char));
  buffer[0] = '\0';
  strcat(buffer, "{");
  while (loop_counter < number_of_elements) {
    sprintf(item, "%d", array[loop_counter]);
    strcat(buffer, item);
    strcat(buffer, ", ");
    loop_counter++;
  }
  buffer[strlen(buffer) - 2] = '\0';
  strcat(buffer, "}");
  return buffer;
}


x86 assembly (clang, -O0):
<arrayDisplay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
imul   $0x5,-0x30(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e9 <arrayDisplay+0xa9>
lea    -0x2a(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe49(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x2a(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1197 <arrayDisplay+0x57>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayDisplay>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
lea    (%r15,%r15,4),%eax
lea    (%rax,%rax,1),%edi
add    $0xf,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe90(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcat@plt>
test   %r15d,%r15d
jle    11c2 <arrayDisplay+0x82>
mov    %r15d,%ebp
xor    %r15d,%r15d
lea    0xe(%rsp),%r12
lea    0xe76(%rip),%r13
nop
mov    (%r14,%r15,4),%edx
mov    %r12,%rdi
lea    0xe64(%rip),%rsi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1190 <arrayDisplay+0x50>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
lea    0xe30(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"{\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [2 x i8] c"}\00"
define i8* @arrayDisplay(i32* nocapture %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = mul i32 %1, 10
%6 = add i32 %5, 15
%7 = tail call i8* @malloc(i32 %6)
store i8 0, i8* %7
%8 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @strcat(i8* %7, i8* %4)
%18 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %2
%22 = call i32 @strlen(i8* %7)
%23 = add nsw i32 %22, -2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %7, i64 %24
store i8 0, i8* %25
%26 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i8* %7
}