#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 *);
__attribute__((__weak__, __always___)) void
__softboundcets_spatial_load_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 LDC, base=%zx, bound=%zx, ptr=%zx\n", base,
                           bound, ptr);
    __softboundcets_abort();
  }
}


x86 assembly (clang, -O0):
<__softboundcets_spatial_load_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_load_dereference_check+0x38>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    1177 <__softboundcets_spatial_load_dereference_check+0x57>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe95(%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_load_dereference_check>:
mov    %rdx,%rax
mov    %rsi,%rdx
mov    %rdi,%rsi
cmp    %rdi,%rax
jb     1137 <__softboundcets_spatial_load_dereference_check+0x17>
add    %rax,%rcx
cmp    %rdx,%rcx
ja     1137 <__softboundcets_spatial_load_dereference_check+0x17>
ret
push   %rax
lea    0xec1(%rip),%rdi
mov    %rax,%rcx
call   1030 <__softboundcets_printf@plt>
xor    %eax,%eax
pop    %rcx
jmp    1040 <__softboundcets_abort@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"In LDC, base=%zx, bound=%zx, ptr=%zx\0A\00"
define weak void @__softboundcets_spatial_load_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 %24
18: ; preds = %12, %4
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = call i32 @__softboundcets_printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20, i8* %21)
%23 = call i32 (...) @__softboundcets_abort()
br label %24
24: ; preds = %18, %12
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"In LDC, base=%zx, bound=%zx, ptr=%zx\0A\00"
define weak void @__softboundcets_spatial_load_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 ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%11 = tail call i32 (...) @__softboundcets_abort()
br label %12
12: ; preds = %4, %9
ret void
}