#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*/ __softboundcets_abort();
int /*<<< orphan*/ __softboundcets_printf(char *, void *, void *, void *,
                                          size_t, char *);
__attribute__((__weak__, __always___)) void
__softboundcets_spatial_store_dereference_check(void *base, void *bound,
                                                void *ptr,
                                                size_t size_of_type) {
  if ((ptr < base) || ((void *)((char *)ptr + size_of_type) > bound)) {
    __softboundcets_printf("In Store Dereference Check, base=%p, bound=%p, "
                           "ptr=%p, size_of_type=%zx, ptr+size=%p\n",
                           base, bound, ptr, size_of_type,
                           (char *)ptr + size_of_type);
    __softboundcets_abort();
  }
}


x86 assembly (clang, -O0):
<__softboundcets_spatial_store_dereference_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1158 <__softboundcets_spatial_store_dereference_check+0x38>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    1183 <__softboundcets_spatial_store_dereference_check+0x63>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
add    -0x20(%rbp),%r9
lea    0xe89(%rip),%rdi
call   1030 <__softboundcets_printf@plt>
mov    $0x0,%al
call   1040 <__softboundcets_abort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__softboundcets_spatial_store_dereference_check>:
mov    %rcx,%r8
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%rsi
lea    (%rcx,%r8,1),%r9
cmp    %rdi,%rcx
jb     113b <__softboundcets_spatial_store_dereference_check+0x1b>
cmp    %rdx,%r9
ja     113b <__softboundcets_spatial_store_dereference_check+0x1b>
ret
push   %rax
lea    0xebd(%rip),%rdi
call   1030 <__softboundcets_printf@plt>
xor    %eax,%eax
pop    %rcx
jmp    1040 <__softboundcets_abort@plt>

LLVM IR (-O0):
@.str = [86 x i8] c"In Store Dereference Check, base=%p, bound=%p, ptr=%p, size_of_type=%zx, ptr+size=%p\0A\00"
define weak void @__softboundcets_spatial_store_dereference_check(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = load i8*, i8** %7
%10 = load i8*, i8** %5
%11 = icmp ult i8* %9, %10
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = load i8*, i8** %7
%14 = load i64, i64* %8
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8*, i8** %6
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %28
18: ; preds = %12, %4
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = load i8*, i8** %7
%24 = load i64, i64* %8
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = call i32 @__softboundcets_printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20, i8* %21, i64 %22, i8* %25)
%27 = call i32 (...) @__softboundcets_abort()
br label %28
28: ; preds = %18, %12
ret void
}

LLVM IR (-O2):
@.str = [86 x i8] c"In Store Dereference Check, base=%p, bound=%p, ptr=%p, size_of_type=%zx, ptr+size=%p\0A\00"
define weak void @__softboundcets_spatial_store_dereference_check(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = icmp ult i8* %2, %0
%6 = getelementptr inbounds i8, i8* %2, i64 %3
%7 = icmp ugt i8* %6, %1
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @__softboundcets_printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i64 %3, i8* %6)
%11 = tail call i32 (...) @__softboundcets_abort()
br label %12
12: ; preds = %4, %9
ret void
}