#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 size_t uint64_t;
typedef size_t uint32_t;

/* Variables and functions */
uint8_t _threshold(double *lothres, double *hithres, double *tsdata,
                   uint32_t len) {
  uint64_t i;
  for (i = 0; i < len; i++) {
    if ((lothres != NULL) && (hithres != NULL)) {
      if ((tsdata[i] >= *lothres) && (tsdata[i] <= *hithres))
        return 1;
    } else if (lothres != NULL) {
      if (tsdata[i] >= *lothres)
        return 1;
    } else if (hithres != NULL) {
      if (tsdata[i] <= *hithres)
        return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<_threshold>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    121d <_threshold+0x11d>
cmpq   $0x0,-0x10(%rbp)
je     118b <_threshold+0x8b>
cmpq   $0x0,-0x18(%rbp)
je     118b <_threshold+0x8b>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
ucomisd (%rax),%xmm0
jb     1186 <_threshold+0x86>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jb     1186 <_threshold+0x86>
movl   $0x1,-0x4(%rbp)
jmp    1224 <_threshold+0x124>
jmp    1207 <_threshold+0x107>
cmpq   $0x0,-0x10(%rbp)
je     11c2 <_threshold+0xc2>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
ucomisd (%rax),%xmm0
jb     11bd <_threshold+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    1224 <_threshold+0x124>
jmp    1202 <_threshold+0x102>
cmpq   $0x0,-0x18(%rbp)
je     11fd <_threshold+0xfd>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
jb     11f8 <_threshold+0xf8>
movl   $0x1,-0x4(%rbp)
jmp    1224 <_threshold+0x124>
jmp    11fd <_threshold+0xfd>
jmp    1202 <_threshold+0x102>
jmp    1207 <_threshold+0x107>
jmp    120c <_threshold+0x10c>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    111c <_threshold+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<_threshold>:
test   %rcx,%rcx
je     116b <_threshold+0x6b>
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %r8b
and    %al,%r8b
xor    %eax,%eax
jmp    1139 <_threshold+0x39>
nopl   0x0(%rax)
test   %rdi,%rdi
je     1155 <_threshold+0x55>
movsd  (%rdx,%rax,8),%xmm0
ucomisd (%rdi),%xmm0
jae    1165 <_threshold+0x65>
add    $0x1,%rax
cmp    %rax,%rcx
je     116b <_threshold+0x6b>
test   %r8b,%r8b
je     1120 <_threshold+0x20>
movsd  (%rdx,%rax,8),%xmm0
ucomisd (%rdi),%xmm0
jb     1130 <_threshold+0x30>
movsd  (%rsi),%xmm1
ucomisd %xmm0,%xmm1
jb     1130 <_threshold+0x30>
jmp    1165 <_threshold+0x65>
test   %rsi,%rsi
je     1130 <_threshold+0x30>
movsd  (%rsi),%xmm0
ucomisd (%rdx,%rax,8),%xmm0
jb     1130 <_threshold+0x30>
mov    $0x1,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @_threshold(double* %0, double* %1, double* %2, i64 %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i64
%10 = alloca i64
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store i64 %3, i64* %9
store i64 0, i64* %10
br label %11
11: ; preds = %68, %4
%12 = load i64, i64* %10
%13 = load i64, i64* %9
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %71
15: ; preds = %11
%16 = load double*, double** %6
%17 = icmp ne double* %16, null
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = load double*, double** %7
%20 = icmp ne double* %19, null
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load double*, double** %8
%23 = load i64, i64* %10
%24 = getelementptr inbounds double, double* %22, i64 %23
%25 = load double, double* %24
%26 = load double*, double** %6
%27 = load double, double* %26
%28 = fcmp oge double %25, %27
br i1 %28, label %29, label %38
29: ; preds = %21
%30 = load double*, double** %8
%31 = load i64, i64* %10
%32 = getelementptr inbounds double, double* %30, i64 %31
%33 = load double, double* %32
%34 = load double*, double** %7
%35 = load double, double* %34
%36 = fcmp ole double %33, %35
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 1, i32* %5
br label %72
38: ; preds = %29, %21
br label %67
39: ; preds = %18, %15
%40 = load double*, double** %6
%41 = icmp ne double* %40, null
br i1 %41, label %42, label %52
42: ; preds = %39
%43 = load double*, double** %8
%44 = load i64, i64* %10
%45 = getelementptr inbounds double, double* %43, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %6
%48 = load double, double* %47
%49 = fcmp oge double %46, %48
br i1 %49, label %50, label %51
50: ; preds = %42
store i32 1, i32* %5
br label %72
51: ; preds = %42
br label %66
52: ; preds = %39
%53 = load double*, double** %7
%54 = icmp ne double* %53, null
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load double*, double** %8
%57 = load i64, i64* %10
%58 = getelementptr inbounds double, double* %56, i64 %57
%59 = load double, double* %58
%60 = load double*, double** %7
%61 = load double, double* %60
%62 = fcmp ole double %59, %61
br i1 %62, label %63, label %64
63: ; preds = %55
store i32 1, i32* %5
br label %72
64: ; preds = %55
br label %65
65: ; preds = %64, %52
br label %66
66: ; preds = %65, %51
br label %67
67: ; preds = %66, %38
br label %68
68: ; preds = %67
%69 = load i64, i64* %10
%70 = add i64 %69, 1
store i64 %70, i64* %10
br label %11
71: ; preds = %11
store i32 0, i32* %5
br label %72
72: ; preds = %71, %63, %50, %37
%73 = load i32, i32* %5
ret i32 %73
}

LLVM IR (-O2):
define i32 @_threshold(double* %0, double* %1, double* nocapture %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %35, label %6
6: ; preds = %4
%7 = icmp ne double* %0, null
%8 = icmp ne double* %1, null
%9 = and i1 %7, %8
br label %10
10: ; preds = %6, %32
%11 = phi i64 [ 0, %6 ], [ %33, %32 ]
br i1 %9, label %12, label %20
12: ; preds = %10
%13 = getelementptr inbounds double, double* %2, i64 %11
%14 = load double, double* %13
%15 = load double, double* %0
%16 = fcmp ult double %14, %15
br i1 %16, label %32, label %17
17: ; preds = %12
%18 = load double, double* %1
%19 = fcmp ugt double %14, %18
br i1 %19, label %32, label %35
20: ; preds = %10
br i1 %7, label %21, label %26
21: ; preds = %20
%22 = getelementptr inbounds double, double* %2, i64 %11
%23 = load double, double* %22
%24 = load double, double* %0
%25 = fcmp ult double %23, %24
br i1 %25, label %32, label %35
26: ; preds = %20
br i1 %8, label %27, label %32
27: ; preds = %26
%28 = getelementptr inbounds double, double* %2, i64 %11
%29 = load double, double* %28
%30 = load double, double* %1
%31 = fcmp ugt double %29, %30
br i1 %31, label %32, label %35
32: ; preds = %17, %12, %26, %27, %21
%33 = add nuw i64 %11, 1
%34 = icmp eq i64 %33, %3
br i1 %34, label %35, label %10
35: ; preds = %17, %21, %27, %32, %4
%36 = phi i32 [ 0, %4 ], [ 0, %32 ], [ 1, %27 ], [ 1, %21 ], [ 1, %17 ]
ret i32 %36
}