#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__ emalloc(int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *join_string(char **string_list) {
  int len = 0;
  char **cur_string = string_list;
  char *outstr;
  int first = 1;
  char *quote_char = "\"";
  while (*cur_string) {
    char *str = *cur_string;
    len += strlen(str) + 3;
    cur_string++;
  }
  outstr = (char *)emalloc(len + 1);
  outstr[0] = '\0';
  while (*string_list) {
    if (!first) {
      strcat(outstr, " ");
      strcat(outstr, quote_char);
      strcat(outstr, *string_list);
      strcat(outstr, quote_char);
    } else {
      strcat(outstr, *string_list);
    }
    first = 0;
    string_list++;
  }
  return outstr;
}


x86 assembly (clang, -O0):
<join_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xea7(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a1 <join_string+0x71>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x3,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    115d <join_string+0x2d>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1040 <emalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1236 <join_string+0x106>
cmpl   $0x0,-0x24(%rbp)
jne    120e <join_string+0xde>
mov    -0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <strcat@plt>
jmp    121e <join_string+0xee>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <join_string+0x87>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
je     116e <join_string+0x3e>
lea    0x8(%r14),%rbx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
call   1030 <strlen@plt>
add    %eax,%r15d
add    $0x3,%r15d
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1150 <join_string+0x20>
add    $0x1,%r15d
jmp    1174 <join_string+0x44>
mov    $0x1,%r15d
mov    %r15d,%edi
call   1040 <emalloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    (%r14),%rsi
test   %rsi,%rsi
je     11e7 <join_string+0xb7>
mov    %rbx,%rdi
call   1050 <strcat@plt>
cmpq   $0x0,0x8(%r14)
je     11e7 <join_string+0xb7>
add    $0x10,%r14
lea    0xe5e(%rip),%r15
lea    0xe55(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
mov    -0x8(%r14),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
cmpq   $0x0,(%r14)
lea    0x8(%r14),%r14
jne    11b0 <join_string+0x80>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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