#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);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *array2StringInt(int *array, size_t sz) {
  char *result = malloc(sz * 10);
  strcpy(result, "[");
  char buff[15];
  for (size_t i = 0; i < sz; ++i) {
    sprintf(buff, "%d", array[i]);
    strcat(result, buff);
    strcat(result, ", ");
  }
  result[strlen(result) - 2] = '\0';
  strcat(result, "]");
  return result;
}


x86 assembly (clang, -O0):
<array2StringInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
imul   $0xa,-0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11dd <array2StringInt+0x8d>
lea    -0x27(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe58(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x27(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1186 <array2StringInt+0x36>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array2StringInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    (%rsi,%rsi,1),%rax
lea    (%rax,%rax,4),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
test   %r14,%r14
je     11d2 <array2StringInt+0x82>
xor    %r12d,%r12d
lea    0x9(%rsp),%r13
lea    0xe6e(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    (%r15,%r12,4),%edx
mov    %r13,%rdi
lea    0xe54(%rip),%rsi
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    11a0 <array2StringInt+0x50>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
call   1060 <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* @array2StringInt(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca [15 x i8]
%7 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = mul i64 %8, 10
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %7
br label %13
13: ; preds = %29, %2
%14 = load i64, i64* %7
%15 = load i64, i64* %4
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = load i64, i64* %7
%21 = getelementptr inbounds i32, i32* %19, i64 %20
%22 = load i32, i32* %21
%23 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %5
%25 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %17
%30 = load i64, i64* %7
%31 = add i64 %30, 1
store i64 %31, i64* %7
br label %13
32: ; preds = %13
%33 = load i8*, i8** %5
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %33, i64 %37
store i8 0, i8* %38
%39 = load i8*, i8** %5
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%41 = load i8*, i8** %5
ret i8* %41
}

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* @array2StringInt(i32* nocapture %0, i64 %1) {
%3 = alloca [15 x i8]
%4 = mul i64 %1, 10
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%8 = icmp eq i64 %1, 0
br i1 %8, label %9, label %15
9: ; preds = %15, %2
%10 = call i32 @strlen(i8* %5)
%11 = add nsw i32 %10, -2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %5, i64 %12
store i8 0, i8* %13
%14 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i8* %5
15: ; preds = %2, %15
%16 = phi i64 [ %22, %15 ], [ 0, %2 ]
%17 = getelementptr inbounds i32, i32* %0, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @strcat(i8* %5, i8* %7)
%21 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = add nuw i64 %16, 1
%23 = icmp eq i64 %22, %1
br i1 %23, label %9, label %15
}