#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 *arrToStr(char **arr) {
  char *str = malloc(sizeof(char) * 256);
  int i = 0;
  while (arr[i] != NULL) {
    strcat(str, arr[i]);
    if (arr[i + 1] != NULL) {
      strcat(str, " ");
    }
    i++;
  }
  return str;
}


x86 assembly (clang, -O0):
<arrToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x100,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     119f <arrToStr+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1191 <arrToStr+0x71>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <arrToStr+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrToStr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x100,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1175 <arrToStr+0x55>
add    $0x8,%rbx
lea    0xeb8(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <strcat@plt>
cmpq   $0x0,(%rbx)
je     1175 <arrToStr+0x55>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1150 <arrToStr+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @arrToStr(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call i8* @malloc(i32 256)
store i8* %5, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %31, %1
%7 = load i8**, i8*** %2
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %7, i64 %9
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %34
13: ; preds = %6
%14 = load i8*, i8** %3
%15 = load i8**, i8*** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @strcat(i8* %14, i8* %19)
%21 = load i8**, i8*** %2
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %13
%29 = load i8*, i8** %3
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %28, %13
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %6
34: ; preds = %6
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @arrToStr(i8** nocapture %0) {
%2 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %1, %13
%6 = phi i64 [ %9, %13 ], [ 0, %1 ]
%7 = phi i8* [ %15, %13 ], [ %3, %1 ]
%8 = tail call i32 @strcat(i8* %2, i8* %7)
%9 = add nuw i64 %6, 1
%10 = getelementptr inbounds i8*, i8** %0, i64 %9
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %5
%14 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %10
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %5
17: ; preds = %5, %13, %1
ret i8* %2
}