#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int int16_t;

/* Variables and functions */
int getImmediateValue(int /*<<< orphan*/);
int getR1(int /*<<< orphan*/);
int getR2(int /*<<< orphan*/);
int /*<<< orphan*/ printSegmentationFaultMessage();
int checkIfLoadAndStoreAreValid(uint32_t ins) {
  uint8_t r1 = getR1(ins);
  uint8_t r2 = getR2(ins);
  int16_t iVal = getImmediateValue(ins);
  if (r1 < 0 || r2 < 0 || r1 >= 32 || r2 >= 32 || r2 + iVal < 0 ||
      r2 + iVal >= 65536) {
    printSegmentationFaultMessage();
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<checkIfLoadAndStoreAreValid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <getR1@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <getR2@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <getImmediateValue@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11b4 <checkIfLoadAndStoreAreValid+0x74>
cmpl   $0x0,-0x10(%rbp)
jl     11b4 <checkIfLoadAndStoreAreValid+0x74>
cmpl   $0x20,-0xc(%rbp)
jge    11b4 <checkIfLoadAndStoreAreValid+0x74>
cmpl   $0x20,-0x10(%rbp)
jge    11b4 <checkIfLoadAndStoreAreValid+0x74>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0x0,%eax
jl     11b4 <checkIfLoadAndStoreAreValid+0x74>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    $0x10000,%eax
jl     11c7 <checkIfLoadAndStoreAreValid+0x87>
mov    $0x0,%al
call   1060 <printSegmentationFaultMessage@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <checkIfLoadAndStoreAreValid+0x8e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkIfLoadAndStoreAreValid>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
call   1050 <getR1@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <getR2@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1030 <getImmediateValue@plt>
cmp    $0x1f,%ebp
jg     1181 <checkIfLoadAndStoreAreValid+0x41>
test   %ebp,%ebp
js     1181 <checkIfLoadAndStoreAreValid+0x41>
test   %r14d,%r14d
js     1181 <checkIfLoadAndStoreAreValid+0x41>
cmp    $0x1f,%r14d
jg     1181 <checkIfLoadAndStoreAreValid+0x41>
add    %r14d,%eax
mov    $0x1,%ebx
cmp    $0x10000,%eax
jb     118a <checkIfLoadAndStoreAreValid+0x4a>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printSegmentationFaultMessage@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @checkIfLoadAndStoreAreValid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @getR1(i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %3
%10 = call i32 @getR2(i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %3
%12 = call i32 @getImmediateValue(i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %34, label %15
15: ; preds = %1
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 0
br i1 %17, label %34, label %18
18: ; preds = %15
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 32
br i1 %20, label %34, label %21
21: ; preds = %18
%22 = load i32, i32* %5
%23 = icmp sge i32 %22, 32
br i1 %23, label %34, label %24
24: ; preds = %21
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = add nsw i32 %25, %26
%28 = icmp slt i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = add nsw i32 %30, %31
%33 = icmp sge i32 %32, 65536
br i1 %33, label %34, label %36
34: ; preds = %29, %24, %21, %18, %15, %1
%35 = call i32 (...) @printSegmentationFaultMessage()
store i32 0, i32* %2
br label %37
36: ; preds = %29
store i32 1, i32* %2
br label %37
37: ; preds = %36, %34
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @checkIfLoadAndStoreAreValid(i32 %0) {
%2 = tail call i32 @getR1(i32 %0)
%3 = tail call i32 @getR2(i32 %0)
%4 = tail call i32 @getImmediateValue(i32 %0)
%5 = icmp slt i32 %2, 0
%6 = icmp slt i32 %3, 0
%7 = select i1 %5, i1 true, i1 %6
%8 = icmp sgt i32 %2, 31
%9 = or i1 %8, %7
%10 = icmp sgt i32 %3, 31
%11 = select i1 %9, i1 true, i1 %10
%12 = add nsw i32 %4, %3
%13 = icmp ugt i32 %12, 65535
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = tail call i32 (...) @printSegmentationFaultMessage()
br label %17
17: ; preds = %1, %15
%18 = phi i32 [ 0, %15 ], [ 1, %1 ]
ret i32 %18
}