#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*/ strcat(char *, char *);
char *joinStringsStringArray(char *strings[], int count) {
  char *result = malloc(sizeof(char) * count * 2);
  strcat(result, "{");
  int i;
  for (i = 0; i < count; ++i) {
    strcat(result, strings[i]);
    if (i != count - 1)
      strcat(result, ", ");
  }
  strcat(result, "}");
  return result;
}


x86 assembly (clang, -O0):
<joinStringsStringArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <strcat@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b2 <joinStringsStringArray+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     119f <joinStringsStringArray+0x7f>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1040 <strcat@plt>
jmp    11a4 <joinStringsStringArray+0x84>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <joinStringsStringArray+0x3d>
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinStringsStringArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    (%r15,%r15,1),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
lea    0xebc(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcat@plt>
test   %r15d,%r15d
jle    1197 <joinStringsStringArray+0x77>
lea    -0x1(%r15),%r12d
mov    %r15d,%r13d
xor    %ebp,%ebp
lea    0xea1(%rip),%r15
jmp    1179 <joinStringsStringArray+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%r13
je     1197 <joinStringsStringArray+0x77>
mov    (%r14,%rbp,8),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
cmp    %rbp,%r12
je     1170 <joinStringsStringArray+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
jmp    1170 <joinStringsStringArray+0x50>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%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", \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 i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 1, %8
%10 = mul i64 %9, 2
%11 = trunc i64 %10 to i32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %15
15: ; preds = %35, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i8**, i8*** %3
%22 = load i32, i32* %6
%23 = sext 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 i32, i32* %6
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1
%30 = icmp ne i32 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = load i8*, i8** %5
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %19
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %15
38: ; preds = %15
%39 = load i8*, i8** %5
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, 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", \00"
@.str.2 = [2 x i8] c"}\00"
define i8* @joinStringsStringArray(i8** nocapture %0, i32 %1) {
%3 = shl i32 %1, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %22
7: ; preds = %2
%8 = add nsw i32 %1, -1
%9 = zext i32 %8 to i64
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %7, %19
%12 = phi i64 [ 0, %7 ], [ %20, %19 ]
%13 = getelementptr inbounds i8*, i8** %0, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @strcat(i8* %4, i8* %14)
%16 = icmp eq i64 %12, %9
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %11, %17
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %11
22: ; preds = %19, %2
%23 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i8* %4
}