#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*/ umax(int /*<<< orphan*/, int);
void *vec_alloc(size_t, int /*<<< orphan*/);
int /*<<< orphan*/ vec_free(void *);
scalar_t__ vec_join(void **, void const *, size_t);
int /*<<< orphan*/ vec_len(void const *);
void *vec_clone(void const *vec, size_t size) {
  void *ret = 0x0;
  ret = vec_alloc(size, umax(vec_len(vec), 8));
  if (!ret)
    return 0;
  if (vec_join(&ret, vec, size)) {
    vec_free(ret);
    return 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<vec_clone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <vec_len@plt>
mov    %eax,%edi
mov    $0x8,%esi
call   1060 <umax@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <vec_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ac <vec_clone+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <vec_clone+0x95>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
call   1030 <vec_join@plt>
cmp    $0x0,%rax
je     11dd <vec_clone+0x8d>
mov    -0x20(%rbp),%rdi
call   1040 <vec_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <vec_clone+0x95>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_clone>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <vec_len@plt>
mov    %eax,%edi
mov    $0x8,%esi
call   1060 <umax@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <vec_alloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     11a0 <vec_clone+0x50>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <vec_join@plt>
mov    %rax,%rcx
mov    (%rsp),%rax
test   %rcx,%rcx
je     11a2 <vec_clone+0x52>
mov    %rax,%rdi
call   1040 <vec_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @vec_clone(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @vec_len(i8* %0)
%6 = tail call i32 @umax(i32 %5, i32 8)
%7 = tail call i8* @vec_alloc(i64 %1, i32 %6)
store i8* %7, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = call i64 @vec_join(i8** %3, i8* %0, i64 %1)
%11 = icmp eq i64 %10, 0
%12 = load i8*, i8** %3
br i1 %11, label %15, label %13
13: ; preds = %9
%14 = call i32 @vec_free(i8* %12)
br label %15
15: ; preds = %9, %2, %13
%16 = phi i8* [ null, %13 ], [ null, %2 ], [ %12, %9 ]
ret i8* %16
}