#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(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
void utarray_str_cpy(void *dst, const void *src) {
  char **_src = (char **)src, **_dst = (char **)dst;
  if (*_src != NULL) {
    *_dst = (char *)malloc(strlen(*_src) + 1);
    memcpy(*_dst, *_src, strlen(*_src) + 1);
  } else {
    *_dst = NULL;
  }
}


x86 assembly (clang, -O0):
<utarray_str_cpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11bb <utarray_str_cpy+0x8b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
jmp    11c6 <utarray_str_cpy+0x96>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utarray_str_cpy>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rsi),%rdi
test   %rdi,%rdi
je     1176 <utarray_str_cpy+0x46>
mov    %rsi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,(%r14)
mov    (%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <memcpy@plt>
movq   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @utarray_str_cpy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to i8**
store i8** %8, i8*** %5
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to i8**
store i8** %10, i8*** %6
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %31
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
%21 = load i8**, i8*** %6
store i8* %20, i8** %21
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = call i64 @strlen(i8* %27)
%29 = add nsw i64 %28, 1
%30 = call i32 @memcpy(i8* %23, i8* %25, i64 %29)
br label %33
31: ; preds = %2
%32 = load i8**, i8*** %6
store i8* null, i8** %32
br label %33
33: ; preds = %31, %14
ret void
}

LLVM IR (-O2):
define void @utarray_str_cpy(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = bitcast i8* %1 to i8**
%4 = bitcast i8* %0 to i8**
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = tail call i64 @strlen(i8* %5)
%9 = add nsw i64 %8, 1
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %4
%12 = load i8*, i8** %3
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = add nsw i64 %13, 1
%15 = tail call i32 @memcpy(i8* %11, i8* %12, i64 %14)
br label %17
16: ; preds = %2
store i8* null, i8** %4
br label %17
17: ; preds = %16, %7
ret void
}