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


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)
jne    116e <utarray_str_cpy+0x3e>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
jmp    11ad <utarray_str_cpy+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
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     116c <utarray_str_cpy+0x3c>
mov    %rsi,%rbx
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r15
mov    %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
mov    (%rbx),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
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**
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = bitcast i8* %8 to i8**
store i8** %9, i8*** %5
%10 = load i8*, i8** %3
%11 = bitcast i8* %10 to i8**
store i8** %11, i8*** %6
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i8**, i8*** %6
store i8* null, i8** %16
br label %32
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = call i8* @malloc(i64 %23)
%25 = load i8**, i8*** %6
store i8* %24, i8** %25
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = load i64, i64* %7
%31 = call i32 @memcpy(i8* %27, i8* %29, i64 %30)
br label %32
32: ; preds = %17, %15
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 %7, label %8
7: ; preds = %2
store i8* null, i8** %4
br label %15
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %5)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = tail call i8* @malloc(i64 %11)
store i8* %12, i8** %4
%13 = load i8*, i8** %3
%14 = tail call i32 @memcpy(i8* %12, i8* %13, i64 %11)
br label %15
15: ; preds = %8, %7
ret void
}