#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*/ __bound_check(void const *, size_t);
int /*<<< orphan*/ bound_error(char *);
void *memcpy(void *, void const *, size_t);
void *__bound_memcpy(void *dst, const void *src, size_t size) {
  __bound_check(dst, size);
  __bound_check(src, size);
  if (src >= dst && src < dst + size)
    bound_error("overlapping regions in memcpy()");
  return memcpy(dst, src, size);
}


x86 assembly (clang, -O0):
<__bound_memcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <__bound_check@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <__bound_check@plt>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     118d <__bound_memcpy+0x5d>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    118d <__bound_memcpy+0x5d>
lea    0xe78(%rip),%rdi
call   1050 <bound_error@plt>
mov    -0x8(%rbp),%rdi
mov    %rdi,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__bound_memcpy>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rsi
call   1040 <__bound_check@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <__bound_check@plt>
cmp    %rbx,%r15
jb     116b <__bound_memcpy+0x3b>
lea    (%rbx,%r14,1),%rax
cmp    %r15,%rax
jbe    116b <__bound_memcpy+0x3b>
lea    0xe9a(%rip),%rdi
call   1050 <bound_error@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"overlapping regions in memcpy()\00"
define i8* @__bound_memcpy(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i8*, i8** %4
%8 = load i64, i64* %6
%9 = call i32 @__bound_check(i8* %7, i64 %8)
%10 = load i8*, i8** %5
%11 = load i64, i64* %6
%12 = call i32 @__bound_check(i8* %10, i64 %11)
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = icmp uge i8* %13, %14
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = getelementptr i8, i8* %18, i64 %19
%21 = icmp ult i8* %17, %20
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @bound_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %16, %3
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
ret i8* %25
}

LLVM IR (-O2):
@.str = [32 x i8] c"overlapping regions in memcpy()\00"
define i8* @__bound_memcpy(i8* returned %0, i8* %1, i64 %2) {
%4 = tail call i32 @__bound_check(i8* %0, i64 %2)
%5 = tail call i32 @__bound_check(i8* %1, i64 %2)
%6 = icmp uge i8* %1, %0
%7 = getelementptr i8, i8* %0, i64 %2
%8 = icmp ugt i8* %7, %1
%9 = and i1 %6, %8
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @bound_error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %3
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 %1, i64 %2, i1 false)
ret i8* %0
}