#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 /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
int strlen(char *);
char *flatten_array_to_string(char **array, const unsigned int size) {
  unsigned int i;
  char *out, *tmp;
  out = malloc((size_t)(200 * size) * sizeof(char));
  out[0] = '\0';
  for (i = 0; i < size; i++) {
    strcat(out, array[i]);
    strcat(out, ",");
  }
  if (out[0] != '\0')
    out[strlen(out) - 1] = '\0';
  tmp = strdup(out);
  free(out);
  return tmp;
}


x86 assembly (clang, -O0):
<flatten_array_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
imul   $0xc8,-0xc(%rbp),%eax
mov    %eax,%eax
mov    %eax,%edi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11c3 <flatten_array_to_string+0x73>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <flatten_array_to_string+0x35>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f4 <flatten_array_to_string+0xa4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flatten_array_to_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
imul   $0xc8,%esi,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %ebp,%ebp
je     11b4 <flatten_array_to_string+0x64>
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xe82(%rip),%r15
xchg   %ax,%ax
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1180 <flatten_array_to_string+0x30>
cmpb   $0x0,(%rbx)
je     11b4 <flatten_array_to_string+0x64>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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