#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 **reallocarray(int /*<<< orphan*/ *, size_t, int);
char *strdup(char *);
char **copy_string_array(char **array, size_t len) {
  char **result = reallocarray(NULL, len, sizeof(char *));
  size_t i;
  for (i = 0U; i < len; ++i) {
    result[i] = strdup(array[i]);
  }
  return result;
}


x86 assembly (clang, -O0):
<copy_string_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8,%edx
call   1030 <reallocarray@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118d <copy_string_array+0x6d>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <copy_string_array+0x2e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_string_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
mov    $0x8,%edx
call   1030 <reallocarray@plt>
mov    %rax,%r12
test   %r15,%r15
je     1166 <copy_string_array+0x46>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
call   1040 <strdup@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <copy_string_array+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8** @copy_string_array(i8** nocapture %0, i64 %1) {
%3 = tail call i8** @reallocarray(i32* null, i64 %1, i32 8)
%4 = icmp eq i64 %1, 0
br i1 %4, label %13, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %11, %5 ], [ 0, %2 ]
%7 = getelementptr inbounds i8*, i8** %0, i64 %6
%8 = load i8*, i8** %7
%9 = tail call i8* @strdup(i8* %8)
%10 = getelementptr inbounds i8*, i8** %3, i64 %6
store i8* %9, i8** %10
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %11, %1
br i1 %12, label %13, label %5
13: ; preds = %5, %2
ret i8** %3
}