#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 */
void *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void *object_clone(void *src, size_t size) {
  void *clone = NULL;
  if (src == NULL)
    return NULL;
  if (size <= 0)
    return NULL;
  clone = malloc(size);
  if (clone == NULL)
    return NULL;
  memcpy(clone, src, size);
  return clone;
}


x86 assembly (clang, -O0):
<object_clone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <object_clone+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <object_clone+0x86>
cmpq   $0x0,-0x18(%rbp)
ja     1168 <object_clone+0x48>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <object_clone+0x86>
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118d <object_clone+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <object_clone+0x86>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<object_clone>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1159 <object_clone+0x39>
mov    %rsi,%r14
test   %rsi,%rsi
je     1159 <object_clone+0x39>
mov    %rdi,%r15
mov    %r14,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1157 <object_clone+0x37>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <memcpy@plt>
jmp    1159 <object_clone+0x39>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @object_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 i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* null, i8** %3
br label %26
10: ; preds = %2
%11 = load i64, i64* %5
%12 = icmp ule i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i8* null, i8** %3
br label %26
14: ; preds = %10
%15 = load i64, i64* %5
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
store i8* null, i8** %3
br label %26
20: ; preds = %14
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = load i64, i64* %5
%24 = call i32 @memcpy(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %6
store i8* %25, i8** %3
br label %26
26: ; preds = %20, %19, %13, %9
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
define i8* @object_clone(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i64 %1, 0
%5 = or i1 %3, %4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = tail call i8* @malloc(i64 %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @memcpy(i8* %7, i8* %0, i64 %1)
br label %11
11: ; preds = %6, %2, %9
%12 = phi i8* [ %7, %9 ], [ null, %2 ], [ null, %6 ]
ret i8* %12
}