#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *pca_group_heapsort_flatten(char **memb, unsigned long n) {
  unsigned long i, len;
  char *flat;
  for (len = 2, i = 0; i < n; i++)
    len += 4 + strlen(memb[i]);
  flat = (char *)malloc(sizeof(char) * len);
  strcpy(flat, "");
  for (i = 0; i < n; i++) {
    strcat(flat, "'");
    strcat(flat, memb[i]);
    strcat(flat, "'");
    if (i < n - 1)
      strcat(flat, ",");
  }
  return flat;
}


x86 assembly (clang, -O0):
<pca_group_heapsort_flatten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x2,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    119c <pca_group_heapsort_flatten+0x5c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
add    $0x4,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <pca_group_heapsort_flatten+0x20>
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1030 <strcpy@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1245 <pca_group_heapsort_flatten+0x105>
mov    -0x28(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    122f <pca_group_heapsort_flatten+0xef>
mov    -0x28(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1060 <strcat@plt>
jmp    1234 <pca_group_heapsort_flatten+0xf4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c7 <pca_group_heapsort_flatten+0x87>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pca_group_heapsort_flatten>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
test   %rsi,%rsi
je     117b <pca_group_heapsort_flatten+0x3b>
mov    $0x2,%ebx
xor    %ebp,%ebp
nopl   (%rax)
mov    (%r14,%rbp,8),%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
add    $0x4,%rbx
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1160 <pca_group_heapsort_flatten+0x20>
jmp    1180 <pca_group_heapsort_flatten+0x40>
mov    $0x2,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe70(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
test   %r15,%r15
je     11f1 <pca_group_heapsort_flatten+0xb1>
lea    -0x1(%r15),%rbp
xor    %r13d,%r13d
lea    0xe54(%rip),%r12
jmp    11b9 <pca_group_heapsort_flatten+0x79>
xchg   %ax,%ax
add    $0x1,%r13
cmp    %r13,%r15
je     11f1 <pca_group_heapsort_flatten+0xb1>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
mov    (%r14,%r13,8),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
cmp    %rbp,%r13
jae    11b0 <pca_group_heapsort_flatten+0x70>
mov    %rbx,%rdi
lea    0xe18(%rip),%rsi
call   1060 <strcat@plt>
jmp    11b0 <pca_group_heapsort_flatten+0x70>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"'\00"
@.str.2 = [2 x i8] c",\00"
define i8* @pca_group_heapsort_flatten(i8** nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %12, %4 ], [ 0, %2 ]
%6 = phi i64 [ %11, %4 ], [ 2, %2 ]
%7 = getelementptr inbounds i8*, i8** %0, i64 %5
%8 = load i8*, i8** %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = add i64 %6, 4
%11 = add i64 %10, %9
%12 = add nuw i64 %5, 1
%13 = icmp eq i64 %12, %1
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = trunc i64 %11 to i32
br label %16
16: ; preds = %14, %2
%17 = phi i32 [ 2, %2 ], [ %15, %14 ]
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br i1 %3, label %36, label %21
21: ; preds = %16
%22 = add i64 %1, -1
br label %23
23: ; preds = %21, %33
%24 = phi i64 [ 0, %21 ], [ %34, %33 ]
%25 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds i8*, i8** %0, i64 %24
%27 = load i8*, i8** %26
%28 = tail call i32 @strcat(i8* %19, i8* %27)
%29 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ult i64 %24, %22
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %23, %31
%34 = add nuw i64 %24, 1
%35 = icmp eq i64 %34, %1
br i1 %35, label %36, label %23
36: ; preds = %33, %16
ret i8* %19
}