#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 */
size_t LONG_MAX;
int /*<<< orphan*/ __softboundmpx_abort();
__attribute__((__weak__, __always___)) void
__softboundmpx_memcopy_check(void *dest, void *src, size_t size,
                             void *dest_base, void *dest_bound, void *src_base,
                             void *src_bound) {
  if (size >= LONG_MAX)
    __softboundmpx_abort();
  if (dest < dest_base || ((char *)dest > ((char *)dest_bound - size)) ||
      (size > (size_t)dest_bound))
    __softboundmpx_abort();
  if (src < src_base || ((char *)src > ((char *)src_bound - size)) ||
      (size > (size_t)dest_bound))
    __softboundmpx_abort();
}


x86 assembly (clang, -O0):
<__softboundmpx_memcopy_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ea1(%rip),%rcx
cmp    (%rcx),%rax
jb     114f <__softboundmpx_memcopy_check+0x3f>
mov    $0x0,%al
call   1030 <__softboundmpx_abort@plt>
mov    -0x8(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1188 <__softboundmpx_memcopy_check+0x78>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
xor    %edx,%edx
sub    -0x18(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
ja     1188 <__softboundmpx_memcopy_check+0x78>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    %rcx,%rax
jbe    118f <__softboundmpx_memcopy_check+0x7f>
mov    $0x0,%al
call   1030 <__softboundmpx_abort@plt>
mov    -0x10(%rbp),%rax
cmp    -0x30(%rbp),%rax
jb     11c8 <__softboundmpx_memcopy_check+0xb8>
mov    -0x10(%rbp),%rax
mov    0x10(%rbp),%rcx
xor    %edx,%edx
sub    -0x18(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
ja     11c8 <__softboundmpx_memcopy_check+0xb8>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    %rcx,%rax
jbe    11cf <__softboundmpx_memcopy_check+0xbf>
mov    $0x0,%al
call   1030 <__softboundmpx_abort@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__softboundmpx_memcopy_check>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8,%r12
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r13
mov    0x40(%rsp),%r15
mov    0x2ea6(%rip),%rax
cmp    %rdx,(%rax)
ja     1146 <__softboundmpx_memcopy_check+0x36>
xor    %eax,%eax
call   1030 <__softboundmpx_abort@plt>
mov    %r12,%rax
sub    %rbx,%rax
jb     115f <__softboundmpx_memcopy_check+0x4f>
cmp    %rbp,%r13
jb     115f <__softboundmpx_memcopy_check+0x4f>
cmp    %r13,%rax
jb     115f <__softboundmpx_memcopy_check+0x4f>
cmp    %rbx,%r12
jae    116b <__softboundmpx_memcopy_check+0x5b>
jmp    118b <__softboundmpx_memcopy_check+0x7b>
xor    %eax,%eax
call   1030 <__softboundmpx_abort@plt>
cmp    %rbx,%r12
jb     118b <__softboundmpx_memcopy_check+0x7b>
cmp    (%rsp),%r14
jb     118b <__softboundmpx_memcopy_check+0x7b>
neg    %rbx
add    %rbx,%r15
cmp    %r14,%r15
jb     118b <__softboundmpx_memcopy_check+0x7b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <__softboundmpx_abort@plt>

LLVM IR (-O0):
@LONG_MAX = global i64 0
define weak void @__softboundmpx_memcopy_check(i8* %0, i8* %1, i64 %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%15 = load i64, i64* %10
%16 = load i64, i64* @LONG_MAX
%17 = icmp uge i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = call i32 (...) @__softboundmpx_abort()
br label %20
20: ; preds = %18, %7
%21 = load i8*, i8** %8
%22 = load i8*, i8** %11
%23 = icmp ult i8* %21, %22
br i1 %23, label %36, label %24
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = load i8*, i8** %12
%27 = load i64, i64* %10
%28 = sub i64 0, %27
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = icmp ugt i8* %25, %29
br i1 %30, label %36, label %31
31: ; preds = %24
%32 = load i64, i64* %10
%33 = load i8*, i8** %12
%34 = ptrtoint i8* %33 to i64
%35 = icmp ugt i64 %32, %34
br i1 %35, label %36, label %38
36: ; preds = %31, %24, %20
%37 = call i32 (...) @__softboundmpx_abort()
br label %38
38: ; preds = %36, %31
%39 = load i8*, i8** %9
%40 = load i8*, i8** %13
%41 = icmp ult i8* %39, %40
br i1 %41, label %54, label %42
42: ; preds = %38
%43 = load i8*, i8** %9
%44 = load i8*, i8** %14
%45 = load i64, i64* %10
%46 = sub i64 0, %45
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = icmp ugt i8* %43, %47
br i1 %48, label %54, label %49
49: ; preds = %42
%50 = load i64, i64* %10
%51 = load i8*, i8** %12
%52 = ptrtoint i8* %51 to i64
%53 = icmp ugt i64 %50, %52
br i1 %53, label %54, label %56
54: ; preds = %49, %42, %38
%55 = call i32 (...) @__softboundmpx_abort()
br label %56
56: ; preds = %54, %49
ret void
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
define weak void @__softboundmpx_memcopy_check(i8* %0, i8* %1, i64 %2, i8* %3, i8* %4, i8* %5, i8* %6) {
%8 = load i64, i64* @LONG_MAX
%9 = icmp ugt i64 %8, %2
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 (...) @__softboundmpx_abort()
br label %12
12: ; preds = %10, %7
%13 = icmp ult i8* %0, %3
%14 = sub i64 0, %2
%15 = getelementptr inbounds i8, i8* %4, i64 %14
%16 = icmp ult i8* %15, %0
%17 = select i1 %13, i1 true, i1 %16
%18 = ptrtoint i8* %4 to i64
%19 = icmp ult i64 %18, %2
%20 = or i1 %19, %17
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = tail call i32 (...) @__softboundmpx_abort()
br label %23
23: ; preds = %12, %21
%24 = icmp ult i8* %1, %5
%25 = getelementptr inbounds i8, i8* %6, i64 %14
%26 = icmp ult i8* %25, %1
%27 = select i1 %24, i1 true, i1 %26
%28 = or i1 %19, %27
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = tail call i32 (...) @__softboundmpx_abort()
br label %31
31: ; preds = %23, %29
ret void
}