#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 *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *joinStringsStringArray(char *strings[], int count) {
  char *result = malloc(strlen(strings[0]) * count);
  strcpy(result, "{");
  char temp[100];
  for (int i = 0; i < count; ++i) {
    sprintf(temp, "'%s',", strings[i]);
    strcat(result, temp);
  }
  result[strlen(result) - 1] = '\0';
  strcat(result, "}");
  return result;
}


x86 assembly (clang, -O0):
<joinStringsStringArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
imul   -0xc(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <joinStringsStringArray+0x96>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe42(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1197 <joinStringsStringArray+0x47>
mov    -0x18(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinStringsStringArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1040 <strlen@plt>
imul   %ebp,%eax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    0xe81(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
test   %ebp,%ebp
jle    11c3 <joinStringsStringArray+0x73>
mov    %ebp,%r13d
xor    %ebx,%ebx
lea    0xe6b(%rip),%r15
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <joinStringsStringArray+0x50>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
lea    0xe2e(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcat@plt>
mov    %r12,%rax
add    $0x68,%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 = [6 x i8] c"'%s',\00"
@.str.2 = [2 x i8] c"}\00"
define i8* @joinStringsStringArray(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [100 x i8]
%7 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%8 = load i8**, i8*** %3
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
%12 = load i32, i32* %4
%13 = mul nsw i32 %11, %12
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%23 = load i8**, i8*** %3
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %5
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%31 = call i32 @strcat(i8* %29, i8* %30)
br label %32
32: ; preds = %21
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %17
35: ; preds = %17
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %36, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %5
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %5
ret i8* %44
}

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