#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*/ memcpy(char *, char const *const, int);
int strlen(char const *const);
void _lms_string_array_copy(char **dst, const char *const *src, int count) {
  char *d;
  d = (char *)(dst + count);
  for (; count > 1; count--, dst++, src++) {
    int len;
    len = strlen(*src) + 1;
    *dst = d;
    memcpy(*dst, *src, len);
    d += len;
  }
  *dst = NULL;
}


x86 assembly (clang, -O0):
<_lms_string_array_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11ba <_lms_string_array_copy+0x9a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1146 <_lms_string_array_copy+0x26>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_lms_string_array_copy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
cmp    $0x2,%edx
jl     117a <_lms_string_array_copy+0x5a>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edx,%eax
lea    (%r14,%rax,8),%rbp
add    $0x1,%r15d
mov    (%rbx),%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
lea    0x1(%r12),%edx
mov    %rbp,(%r14)
mov    (%rbx),%rsi
mov    %rbp,%rdi
call   1040 <memcpy@plt>
movslq %r12d,%rax
add    %rax,%rbp
add    $0x1,%rbp
add    $0x8,%r14
add    $0x8,%rbx
add    $0xffffffff,%r15d
cmp    $0x2,%r15d
ja     1140 <_lms_string_array_copy+0x20>
movq   $0x0,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_lms_string_array_copy(i8** %0, i8** %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
%9 = load i8**, i8*** %4
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %9, i64 %11
%13 = bitcast i8** %12 to i8*
store i8* %13, i8** %7
br label %14
14: ; preds = %34, %3
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %41
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
%22 = load i8*, i8** %7
%23 = load i8**, i8*** %4
store i8* %22, i8** %23
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = load i32, i32* %8
%29 = call i32 @memcpy(i8* %25, i8* %27, i32 %28)
%30 = load i32, i32* %8
%31 = load i8*, i8** %7
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %7
br label %34
34: ; preds = %17
%35 = load i32, i32* %6
%36 = add nsw i32 %35, -1
store i32 %36, i32* %6
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i32 1
store i8** %38, i8*** %4
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i32 1
store i8** %40, i8*** %5
br label %14
41: ; preds = %14
%42 = load i8**, i8*** %4
store i8* null, i8** %42
ret void
}

LLVM IR (-O2):
define void @_lms_string_array_copy(i8** %0, i8** nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %25
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = getelementptr inbounds i8*, i8** %0, i64 %6
%8 = bitcast i8** %7 to i8*
br label %9
9: ; preds = %5, %9
%10 = phi i8** [ %22, %9 ], [ %0, %5 ]
%11 = phi i8* [ %20, %9 ], [ %8, %5 ]
%12 = phi i32 [ %21, %9 ], [ %2, %5 ]
%13 = phi i8** [ %23, %9 ], [ %1, %5 ]
%14 = load i8*, i8** %13
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
store i8* %11, i8** %10
%17 = load i8*, i8** %13
%18 = tail call i32 @memcpy(i8* %11, i8* %17, i32 %16)
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds i8, i8* %11, i64 %19
%21 = add nsw i32 %12, -1
%22 = getelementptr inbounds i8*, i8** %10, i64 1
%23 = getelementptr inbounds i8*, i8** %13, i64 1
%24 = icmp ugt i32 %12, 2
br i1 %24, label %9, label %25
25: ; preds = %9, %3
%26 = phi i8** [ %0, %3 ], [ %22, %9 ]
store i8* null, i8** %26
ret void
}