#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,
                 int step) {
  if ((x_len < 1) || (h_len < 1) || (y_len < 1) || (len < 1) || (step < 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    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     115e <bounds_check+0x4e>
cmpl   $0x1,-0xc(%rbp)
jl     115e <bounds_check+0x4e>
cmpl   $0x1,-0x10(%rbp)
jl     115e <bounds_check+0x4e>
cmpl   $0x1,-0x18(%rbp)
jl     115e <bounds_check+0x4e>
cmpl   $0x1,-0x1c(%rbp)
jge    1181 <bounds_check+0x71>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <bounds_check+0xed>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11a8 <bounds_check+0x98>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11a8 <bounds_check+0x98>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f6 <bounds_check+0xe6>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e1a(%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    0xe57(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fd <bounds_check+0xed>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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    118f <bounds_check+0x7f>
mov    %esi,%r15d
test   %esi,%esi
jle    118f <bounds_check+0x7f>
mov    %edx,%r12d
test   %edx,%edx
jle    118f <bounds_check+0x7f>
mov    %r8d,%ebx
test   %r8d,%r8d
jle    118f <bounds_check+0x7f>
test   %r9d,%r9d
jle    118f <bounds_check+0x7f>
mov    %ecx,%r14d
mov    %edi,%ebp
cmp    %r15d,%edi
jb     1153 <bounds_check+0x43>
cmp    %r12d,%ebx
ja     1153 <bounds_check+0x43>
lea    (%rbx,%r14,1),%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
jle    11ab <bounds_check+0x9b>
mov    0x2e86(%rip),%r13
mov    0x0(%r13),%edi
lea    0xeb4(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %r12d,(%rsp)
lea    0xebc(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r15d,%r9d
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a6 <bounds_check+0x96>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%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, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 1
br i1 %15, label %28, label %16
16: ; preds = %6
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 1
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 1
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32, i32* %12
%24 = icmp slt i32 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %13
%27 = icmp slt i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25, %22, %19, %16, %6
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %7
br label %56
31: ; preds = %25
%32 = load i32, i32* %11
%33 = load i32, i32* %12
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %8
%36 = icmp sgt i32 %34, %35
br i1 %36, label %45, label %37
37: ; preds = %31
%38 = load i32, i32* %12
%39 = load i32, i32* %10
%40 = icmp sgt i32 %38, %39
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %55
45: ; preds = %41, %37, %31
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32, i32* @stderr
%49 = load i32, i32* %11
%50 = load i32, i32* %12
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %50, i32 %51, i32 %52, i32 %53)
store i32 -1, i32* %7
br label %56
55: ; preds = %41
store i32 0, i32* %7
br label %56
56: ; preds = %55, %45, %28
%57 = load i32, i32* %7
ret i32 %57
}

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, i32 %5) {
%7 = icmp slt i32 %0, 1
%8 = icmp slt i32 %1, 1
%9 = or i1 %7, %8
%10 = icmp slt i32 %2, 1
%11 = or i1 %9, %10
%12 = icmp slt i32 %4, 1
%13 = or i1 %11, %12
%14 = icmp slt i32 %5, 1
%15 = or i1 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %6
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %31
19: ; preds = %6
%20 = add nsw i32 %4, %3
%21 = icmp sgt i32 %20, %0
%22 = icmp ugt i32 %4, %2
%23 = or i1 %22, %21
%24 = icmp ult i32 %0, %1
%25 = or i1 %24, %23
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, 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 %31
31: ; preds = %19, %26, %16
%32 = phi i32 [ -1, %16 ], [ -1, %26 ], [ 0, %19 ]
ret i32 %32
}