#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__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *const, size_t);
int strlen(char *const);
int __string_clone_array(char *const *p, char **q, int elements) {
  int element;
  for (element = 0; element < elements; element++) {
    size_t len = strlen(p[element]) + 1;
    q[element] = (char *)malloc(len);
    memcpy(q[element], p[element], len);
  }
  return 0;
}


x86 assembly (clang, -O0):
<__string_clone_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <__string_clone_array+0x87>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <__string_clone_array+0x1a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__string_clone_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %edx,%edx
jle    1183 <__string_clone_array+0x53>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r13
mov    %r13,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
mov    (%r15,%rbx,8),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   1040 <memcpy@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <__string_clone_array+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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