#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(size_t);
char *realloc(char *, size_t);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
char *join_strings(char *output_str_array[]) {
  char *final_str = malloc(strlen(output_str_array[0]));
  final_str = output_str_array[0];
  size_t length_of_prev_strings = strlen(output_str_array[0]);
  for (int i = 1; i < 1000; i++) {
    final_str =
        realloc(final_str, strlen(final_str) + strlen(output_str_array[i]));
    if (final_str && output_str_array[i] != NULL) {
      strcat(final_str, output_str_array[i]);
    }
  }
  return final_str;
}


x86 assembly (clang, -O0):
<join_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    1213 <join_strings+0xd3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
add    %rax,%rsi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1200 <join_strings+0xc0>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1200 <join_strings+0xc0>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
jmp    1205 <join_strings+0xc5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1186 <join_strings+0x46>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_strings>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%r15
mov    $0x1,%ebx
jmp    115d <join_strings+0x2d>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    $0x3e8,%rbx
je     119a <join_strings+0x6a>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    (%r14,%rbx,8),%rdi
call   1030 <strlen@plt>
add    %rax,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <realloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1150 <join_strings+0x20>
mov    (%r14,%rbx,8),%rsi
test   %rsi,%rsi
je     1150 <join_strings+0x20>
mov    %r15,%rdi
call   1050 <strcat@plt>
jmp    1150 <join_strings+0x20>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @join_strings(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8** %0, i8*** %2
%6 = load i8**, i8*** %2
%7 = getelementptr inbounds i8*, i8** %6, i64 0
%8 = load i8*, i8** %7
%9 = call i64 @strlen(i8* %8)
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %3
%11 = load i8**, i8*** %2
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %3
%14 = load i8**, i8*** %2
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %4
store i32 1, i32* %5
br label %18
18: ; preds = %51, %1
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 1000
br i1 %20, label %21, label %54
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i64 @strlen(i8* %23)
%25 = load i8**, i8*** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strlen(i8* %29)
%31 = add i64 %24, %30
%32 = call i8* @realloc(i8* %22, i64 %31)
store i8* %32, i8** %3
%33 = load i8*, i8** %3
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %50
35: ; preds = %21
%36 = load i8**, i8*** %2
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i8*, i8** %3
%44 = load i8**, i8*** %2
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @strcat(i8* %43, i8* %48)
br label %50
50: ; preds = %42, %35, %21
br label %51
51: ; preds = %50
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %18
54: ; preds = %18
%55 = load i8*, i8** %3
ret i8* %55
}

LLVM IR (-O2):
define i8* @join_strings(i8** nocapture %0) {
%2 = load i8*, i8** %0
br label %4
3: ; preds = %19
ret i8* %12
4: ; preds = %1, %19
%5 = phi i64 [ 1, %1 ], [ %20, %19 ]
%6 = phi i8* [ %2, %1 ], [ %12, %19 ]
%7 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%8 = getelementptr inbounds i8*, i8** %0, i64 %5
%9 = load i8*, i8** %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%11 = add i64 %10, %7
%12 = tail call i8* @realloc(i8* %6, i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @strcat(i8* %12, i8* %15)
br label %19
19: ; preds = %4, %14, %17
%20 = add nuw nsw i64 %5, 1
%21 = icmp eq i64 %20, 1000
br i1 %21, label %3, label %4
}