#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 */
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *make1DArrayFrom2D(char *destination, char **source, int numOfLines) {
  strcpy(destination, source[0]);
  for (unsigned int i = 1; i < numOfLines; i++) {
    strcat(destination, source[i]);
  }
  return destination;
}


x86 assembly (clang, -O0):
<make1DArrayFrom2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1178 <make1DArrayFrom2D+0x58>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <make1DArrayFrom2D+0x2a>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make1DArrayFrom2D>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%rsi
call   1030 <strcpy@plt>
cmp    $0x2,%ebp
jb     1165 <make1DArrayFrom2D+0x45>
mov    %ebp,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,8),%rsi
mov    %r15,%rdi
call   1040 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <make1DArrayFrom2D+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @make1DArrayFrom2D(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @strcpy(i8* %8, i8* %11)
store i32 1, i32* %7
br label %13
13: ; preds = %25, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i8**, i8*** %5
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @strcat(i8* %18, i8* %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %7
%27 = add i32 %26, 1
store i32 %27, i32* %7
br label %13
28: ; preds = %13
%29 = load i8*, i8** %4
ret i8* %29
}

LLVM IR (-O2):
define i8* @make1DArrayFrom2D(i8* returned %0, i8** nocapture %1, i32 %2) {
%4 = load i8*, i8** %1
%5 = tail call i32 @strcpy(i8* %0, i8* %4)
%6 = icmp ugt i32 %2, 1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %10
9: ; preds = %10, %3
ret i8* %0
10: ; preds = %7, %10
%11 = phi i64 [ 1, %7 ], [ %15, %10 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @strcat(i8* %0, i8* %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %9, label %10
}