#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*/ size_multiply(int, size_t);
char **xmalloc(int /*<<< orphan*/);
char *xstrdup(char *);
char **copy_string_array(char **src, size_t count) {
  char **dst = xmalloc(size_multiply(sizeof(char *), (count + 1)));
  for (size_t i = 0; i < count; i++) {
    dst[i] = xstrdup(src[i]);
  }
  dst[count] = NULL;
  return dst;
}


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
add    $0x1,%rsi
mov    $0x8,%edi
call   1050 <size_multiply@plt>
mov    %eax,%edi
call   1030 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a4 <copy_string_array+0x74>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <xstrdup@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    1165 <copy_string_array+0x35>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
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
add    $0x1,%rsi
mov    $0x8,%edi
call   1050 <size_multiply@plt>
mov    %eax,%edi
call   1030 <xmalloc@plt>
mov    %rax,%r12
test   %r15,%r15
je     1176 <copy_string_array+0x46>
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
call   1040 <xstrdup@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <copy_string_array+0x30>
movq   $0x0,(%r12,%r15,8)
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 = add i64 %7, 1
%9 = call i32 @size_multiply(i32 8, i64 %8)
%10 = call i8** @xmalloc(i32 %9)
store i8** %10, i8*** %5
store i64 0, i64* %6
br label %11
11: ; preds = %24, %2
%12 = load i64, i64* %6
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8**, i8*** %3
%17 = load i64, i64* %6
%18 = getelementptr inbounds i8*, i8** %16, i64 %17
%19 = load i8*, i8** %18
%20 = call i8* @xstrdup(i8* %19)
%21 = load i8**, i8*** %5
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
store i8* %20, i8** %23
br label %24
24: ; preds = %15
%25 = load i64, i64* %6
%26 = add i64 %25, 1
store i64 %26, i64* %6
br label %11
27: ; preds = %11
%28 = load i8**, i8*** %5
%29 = load i64, i64* %4
%30 = getelementptr inbounds i8*, i8** %28, i64 %29
store i8* null, i8** %30
%31 = load i8**, i8*** %5
ret i8** %31
}

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