#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 *_chunk(size_t, char const *, char const *, int);
int /*<<< orphan*/ memcpy(void *, void const *, size_t);
void *_chunkdup(const void *ptr, size_t len, const char *name, const char *file,
                int line) {
  void *new;
  if (!ptr || len <= 0)
    return (void *)NULL;
  new = _chunk(len, name, file, line);
  if (!new)
    return (void *)NULL;
  memcpy(new, ptr, len);
  return (new);
}


x86 assembly (clang, -O0):
<_chunkdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1152 <_chunkdup+0x32>
cmpq   $0x0,-0x18(%rbp)
ja     115f <_chunkdup+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <_chunkdup+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <_chunk@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    118f <_chunkdup+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <_chunkdup+0x88>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_chunkdup>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1162 <_chunkdup+0x42>
mov    %rsi,%r14
test   %rsi,%rsi
je     1162 <_chunkdup+0x42>
mov    %rdi,%r15
mov    %r14,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8d,%ecx
call   1030 <_chunk@plt>
test   %rax,%rax
je     1160 <_chunkdup+0x40>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <memcpy@plt>
jmp    1162 <_chunkdup+0x42>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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