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


x86 assembly (clang, -O0):
<array2StringLongLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11e1 <array2StringLongLong+0x91>
lea    -0x22(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe52(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1189 <array2StringLongLong+0x39>
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    0xdfa(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array2StringLongLong>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rsi,8),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
test   %r14,%r14
je     11d2 <array2StringLongLong+0x82>
xor    %r12d,%r12d
lea    0xe(%rsp),%r13
lea    0xe6e(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    (%r15,%r12,8),%rdx
mov    %r13,%rdi
lea    0xe52(%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 <array2StringLongLong+0x50>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
lea    0xe1f(%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 = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [3 x i8] c", \00"
define i8* @array2StringLongLong(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca [10 x i8]
%7 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = mul i64 %8, 8
%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 ([1 x i8], [1 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 [10 x i8], [10 x i8]* %6, i64 0, i64 0
%19 = load i64*, i64** %3
%20 = load i64, i64* %7
%21 = getelementptr inbounds i64, i64* %19, i64 %20
%22 = load i64, i64* %21
%23 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = load i8*, i8** %5
%25 = getelementptr inbounds [10 x i8], [10 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 ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%41 = load i8*, i8** %5
ret i8* %41
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [3 x i8] c", \00"
define i8* @array2StringLongLong(i64* nocapture %0, i64 %1) {
%3 = alloca [10 x i8]
%4 = shl i64 %1, 3
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i8], [10 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 ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
ret i8* %5
15: ; preds = %2, %15
%16 = phi i64 [ %22, %15 ], [ 0, %2 ]
%17 = getelementptr inbounds i64, i64* %0, i64 %16
%18 = load i64, i64* %17
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %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
}