#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int bounds_check(int x_len, int h_len, int y_len, int start, int len) {
  if ((x_len < 1) || (h_len < 1) || (y_len < 1) || (len < 1)) {
    fprintf(stderr, "Convolve: Invalid input\n");
    return -1;
  }
  if ((start + len > x_len) || (len > y_len) || (x_len < h_len)) {
    fprintf(stderr, "Convolve: Boundary exception\n");
    fprintf(stderr, "start: %i, len: %i, x: %i, h: %i, y: %i\n", start, len,
            x_len, h_len, y_len);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bounds_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     1150 <bounds_check+0x40>
cmpl   $0x1,-0xc(%rbp)
jl     1150 <bounds_check+0x40>
cmpl   $0x1,-0x10(%rbp)
jl     1150 <bounds_check+0x40>
cmpl   $0x1,-0x18(%rbp)
jge    1173 <bounds_check+0x63>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <bounds_check+0xdf>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     119a <bounds_check+0x8a>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     119a <bounds_check+0x8a>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e8 <bounds_check+0xd8>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    -0x10(%rbp),%eax
lea    0xe65(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <bounds_check+0xdf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bounds_check>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1189 <bounds_check+0x79>
mov    %esi,%r12d
test   %esi,%esi
jle    1189 <bounds_check+0x79>
mov    %edx,%ebp
test   %edx,%edx
jle    1189 <bounds_check+0x79>
mov    %r8d,%r15d
test   %r8d,%r8d
jle    1189 <bounds_check+0x79>
mov    %ecx,%r14d
mov    %edi,%ebx
cmp    %r12d,%edi
jb     114d <bounds_check+0x3d>
cmp    %ebp,%r15d
ja     114d <bounds_check+0x3d>
lea    (%r15,%r14,1),%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
jle    11a5 <bounds_check+0x95>
mov    0x2e8c(%rip),%r13
mov    0x0(%r13),%edi
lea    0xeba(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %ebp,(%rsp)
lea    0xec3(%rip),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a0 <bounds_check+0x90>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Convolve: Invalid input\0A\00"
@.str.1 = [30 x i8] c"Convolve: Boundary exception\0A\00"
@.str.2 = [41 x i8] c"start: %i, len: %i, x: %i, h: %i, y: %i\0A\00"
define i32 @bounds_check(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 1
br i1 %13, label %23, label %14
14: ; preds = %5
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 1
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %20, %17, %14, %5
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %51
26: ; preds = %20
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = add nsw i32 %27, %28
%30 = load i32, i32* %7
%31 = icmp sgt i32 %29, %30
br i1 %31, label %40, label %32
32: ; preds = %26
%33 = load i32, i32* %11
%34 = load i32, i32* %9
%35 = icmp sgt i32 %33, %34
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %50
40: ; preds = %36, %32, %26
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = load i32, i32* %9
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45, i32 %46, i32 %47, i32 %48)
store i32 -1, i32* %6
br label %51
50: ; preds = %36
store i32 0, i32* %6
br label %51
51: ; preds = %50, %40, %23
%52 = load i32, i32* %6
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Convolve: Invalid input\0A\00"
@.str.1 = [30 x i8] c"Convolve: Boundary exception\0A\00"
@.str.2 = [41 x i8] c"start: %i, len: %i, x: %i, h: %i, y: %i\0A\00"
define i32 @bounds_check(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp slt i32 %0, 1
%7 = icmp slt i32 %1, 1
%8 = or i1 %6, %7
%9 = icmp slt i32 %2, 1
%10 = or i1 %8, %9
%11 = icmp slt i32 %4, 1
%12 = or i1 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %28
16: ; preds = %5
%17 = add nsw i32 %4, %3
%18 = icmp sgt i32 %17, %0
%19 = icmp ugt i32 %4, %2
%20 = or i1 %19, %18
%21 = icmp ult i32 %0, %1
%22 = or i1 %21, %20
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %4, i32 %0, i32 %1, i32 %2)
br label %28
28: ; preds = %16, %23, %13
%29 = phi i32 [ -1, %13 ], [ -1, %23 ], [ 0, %16 ]
ret i32 %29
}