#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 */
double NAN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memcpy(double *, double const *, int);
int /*<<< orphan*/ stderr;
void extract_subthreshold(double *out, const double *samples, int nsamples,
                          const int *times, int ntimes, double vthresh,
                          double dvthresh, int skip) {
  int i, j, spikestart, spikestop;
  memcpy(out, samples, nsamples * sizeof(double));
  for (i = 0; i < ntimes; ++i) {
    if (samples[times[i]] < vthresh) {
      fprintf(stderr, "Spike peak at %d is below threshold; skipping\n", i);
      continue;
    }
    for (spikestart = times[i], j = 0; spikestart >= 0; --spikestart, ++j) {
      if ((j > skip) &&
          ((samples[spikestart + 1] - samples[spikestart] < dvthresh) ||
           (samples[spikestart] < vthresh)))
        break;
      out[spikestart] = NAN;
    }
    for (spikestop = times[i], j = 0; spikestop < nsamples; ++spikestop, ++j) {
      if ((j > skip) &&
          ((samples[spikestop - 1] - samples[spikestop] < dvthresh) ||
           (samples[spikestop] < vthresh)))
        break;
      out[spikestop] = NAN;
    }
  }
}


x86 assembly (clang, -O0):
<extract_subthreshold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
mov    %r9d,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    131b <extract_subthreshold+0x1fb>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x40(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b4 <extract_subthreshold+0x94>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%edx
lea    0xe56(%rip),%rsi
call   1030 <fprintf@plt>
jmp    130d <extract_subthreshold+0x1ed>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x0,-0x48(%rbp)
jl     125d <extract_subthreshold+0x13d>
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    122e <extract_subthreshold+0x10e>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1229 <extract_subthreshold+0x109>
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    122e <extract_subthreshold+0x10e>
jmp    125d <extract_subthreshold+0x13d>
mov    0x2dc3(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11c9 <extract_subthreshold+0xa9>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1308 <extract_subthreshold+0x1e8>
mov    -0x44(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    12d9 <extract_subthreshold+0x1b9>
mov    -0x10(%rbp),%rax
mov    -0x4c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     12d4 <extract_subthreshold+0x1b4>
mov    -0x10(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12d9 <extract_subthreshold+0x1b9>
jmp    1308 <extract_subthreshold+0x1e8>
mov    0x2d18(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1272 <extract_subthreshold+0x152>
jmp    130d <extract_subthreshold+0x1ed>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1167 <extract_subthreshold+0x47>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_subthreshold>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%ebx
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %r8d,%ebp
mov    %rcx,0x20(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rdx,0x18(%rsp)
lea    0x0(,%rdx,8),%edx
call   1040 <memcpy@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
test   %ebp,%ebp
jle    126e <extract_subthreshold+0x14e>
mov    %ebp,%r15d
xor    %ebp,%ebp
mov    0x2e7c(%rip),%r14
jmp    11b0 <extract_subthreshold+0x90>
xchg   %ax,%ax
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    %ebp,%edx
call   1030 <fprintf@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
add    $0x1,%rbp
cmp    %r15,%rbp
je     126e <extract_subthreshold+0x14e>
mov    0x20(%rsp),%rax
movslq (%rax,%rbp,4),%rax
ucomisd (%r12,%rax,8),%xmm3
ja     1180 <extract_subthreshold+0x60>
mov    %eax,%ecx
test   %ecx,%ecx
js     1210 <extract_subthreshold+0xf0>
xor    %edx,%edx
mov    %rcx,%rsi
jmp    11e8 <extract_subthreshold+0xc8>
xchg   %ax,%ax
movsd  (%r14),%xmm0
movsd  %xmm0,0x0(%r13,%rsi,8)
add    $0xffffffffffffffff,%rsi
add    $0x1,%edx
cmp    $0xffffffff,%esi
je     1210 <extract_subthreshold+0xf0>
cmp    %ebx,%edx
jle    11d0 <extract_subthreshold+0xb0>
movsd  (%r12,%rsi,8),%xmm0
ucomisd %xmm0,%xmm3
ja     1210 <extract_subthreshold+0xf0>
movsd  0x8(%r12,%rsi,8),%xmm1
subsd  %xmm0,%xmm1
ucomisd %xmm1,%xmm2
jbe    11d0 <extract_subthreshold+0xb0>
nopl   0x0(%rax)
cmp    0x18(%rsp),%ecx
jge    11a3 <extract_subthreshold+0x83>
mov    0x18(%rsp),%rcx
sub    %eax,%ecx
lea    0x0(,%rax,8),%rdx
add    %r13,%rdx
lea    (%r12,%rax,8),%rax
xor    %esi,%esi
jmp    1246 <extract_subthreshold+0x126>
movsd  (%r14),%xmm0
movsd  %xmm0,(%rdx,%rsi,8)
add    $0x1,%rsi
cmp    %esi,%ecx
je     11a3 <extract_subthreshold+0x83>
cmp    %ebx,%esi
jle    1230 <extract_subthreshold+0x110>
movsd  (%rax,%rsi,8),%xmm0
ucomisd %xmm0,%xmm3
ja     11a3 <extract_subthreshold+0x83>
movsd  -0x8(%rax,%rsi,8),%xmm1
subsd  %xmm0,%xmm1
ucomisd %xmm1,%xmm2
jbe    1230 <extract_subthreshold+0x110>
jmp    11a3 <extract_subthreshold+0x83>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"Spike peak at %d is below threshold; skipping\0A\00"
@NAN = global double 0.000000e+00
define void @extract_subthreshold(double* %0, double* %1, i32 %2, i32* %3, i32 %4, double %5, double %6, i32 %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store double* %0, double** %9
store double* %1, double** %10
store i32 %2, i32* %11
store i32* %3, i32** %12
store i32 %4, i32* %13
store double %5, double* %14
store double %6, double* %15
store i32 %7, i32* %16
%21 = load double*, double** %9
%22 = load double*, double** %10
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i32 @memcpy(double* %21, double* %22, i32 %26)
store i32 0, i32* %17
br label %28
28: ; preds = %146, %8
%29 = load i32, i32* %17
%30 = load i32, i32* %13
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %149
32: ; preds = %28
%33 = load double*, double** %10
%34 = load i32*, i32** %12
%35 = load i32, i32* %17
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %33, i64 %39
%41 = load double, double* %40
%42 = load double, double* %14
%43 = fcmp olt double %41, %42
br i1 %43, label %44, label %48
44: ; preds = %32
%45 = load i32, i32* @stderr
%46 = load i32, i32* %17
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %46)
br label %146
48: ; preds = %32
%49 = load i32*, i32** %12
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = load i32, i32* %52
store i32 %53, i32* %19
store i32 0, i32* %18
br label %54
54: ; preds = %91, %48
%55 = load i32, i32* %19
%56 = icmp sge i32 %55, 0
br i1 %56, label %57, label %96
57: ; preds = %54
%58 = load i32, i32* %18
%59 = load i32, i32* %16
%60 = icmp sgt i32 %58, %59
br i1 %60, label %61, label %85
61: ; preds = %57
%62 = load double*, double** %10
%63 = load i32, i32* %19
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %62, i64 %65
%67 = load double, double* %66
%68 = load double*, double** %10
%69 = load i32, i32* %19
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %68, i64 %70
%72 = load double, double* %71
%73 = fsub double %67, %72
%74 = load double, double* %15
%75 = fcmp olt double %73, %74
br i1 %75, label %84, label %76
76: ; preds = %61
%77 = load double*, double** %10
%78 = load i32, i32* %19
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = load double, double* %14
%83 = fcmp olt double %81, %82
br i1 %83, label %84, label %85
84: ; preds = %76, %61
br label %96
85: ; preds = %76, %57
%86 = load double, double* @NAN
%87 = load double*, double** %9
%88 = load i32, i32* %19
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds double, double* %87, i64 %89
store double %86, double* %90
br label %91
91: ; preds = %85
%92 = load i32, i32* %19
%93 = add nsw i32 %92, -1
store i32 %93, i32* %19
%94 = load i32, i32* %18
%95 = add nsw i32 %94, 1
store i32 %95, i32* %18
br label %54
96: ; preds = %84, %54
%97 = load i32*, i32** %12
%98 = load i32, i32* %17
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32, i32* %97, i64 %99
%101 = load i32, i32* %100
store i32 %101, i32* %20
store i32 0, i32* %18
br label %102
102: ; preds = %140, %96
%103 = load i32, i32* %20
%104 = load i32, i32* %11
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %145
106: ; preds = %102
%107 = load i32, i32* %18
%108 = load i32, i32* %16
%109 = icmp sgt i32 %107, %108
br i1 %109, label %110, label %134
110: ; preds = %106
%111 = load double*, double** %10
%112 = load i32, i32* %20
%113 = sub nsw i32 %112, 1
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds double, double* %111, i64 %114
%116 = load double, double* %115
%117 = load double*, double** %10
%118 = load i32, i32* %20
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds double, double* %117, i64 %119
%121 = load double, double* %120
%122 = fsub double %116, %121
%123 = load double, double* %15
%124 = fcmp olt double %122, %123
br i1 %124, label %133, label %125
125: ; preds = %110
%126 = load double*, double** %10
%127 = load i32, i32* %20
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %126, i64 %128
%130 = load double, double* %129
%131 = load double, double* %14
%132 = fcmp olt double %130, %131
br i1 %132, label %133, label %134
133: ; preds = %125, %110
br label %145
134: ; preds = %125, %106
%135 = load double, double* @NAN
%136 = load double*, double** %9
%137 = load i32, i32* %20
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds double, double* %136, i64 %138
store double %135, double* %139
br label %140
140: ; preds = %134
%141 = load i32, i32* %20
%142 = add nsw i32 %141, 1
store i32 %142, i32* %20
%143 = load i32, i32* %18
%144 = add nsw i32 %143, 1
store i32 %144, i32* %18
br label %102
145: ; preds = %133, %102
br label %146
146: ; preds = %145, %44
%147 = load i32, i32* %17
%148 = add nsw i32 %147, 1
store i32 %148, i32* %17
br label %28
149: ; preds = %28
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"Spike peak at %d is below threshold; skipping\0A\00"
@NAN = global double 0.000000e+00
define void @extract_subthreshold(double* %0, double* %1, i32 %2, i32* nocapture %3, i32 %4, double %5, double %6, i32 %7) {
%9 = shl i32 %2, 3
%10 = tail call i32 @memcpy(double* %0, double* %1, i32 %9)
%11 = icmp sgt i32 %4, 0
br i1 %11, label %12, label %77
12: ; preds = %8
%13 = zext i32 %4 to i64
br label %14
14: ; preds = %12, %74
%15 = phi i64 [ 0, %12 ], [ %75, %74 ]
%16 = getelementptr inbounds i32, i32* %3, i64 %15
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %1, i64 %18
%20 = load double, double* %19
%21 = fcmp olt double %20, %5
br i1 %21, label %26, label %22
22: ; preds = %14
%23 = icmp sgt i32 %17, -1
br i1 %23, label %24, label %50
24: ; preds = %22
%25 = zext i32 %17 to i64
br label %30
26: ; preds = %14
%27 = load i32, i32* @stderr
%28 = trunc i64 %15 to i32
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %74
30: ; preds = %24, %44
%31 = phi i64 [ %25, %24 ], [ %47, %44 ]
%32 = phi i32 [ 0, %24 ], [ %48, %44 ]
%33 = icmp sgt i32 %32, %7
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = add nuw nsw i64 %31, 1
%36 = getelementptr inbounds double, double* %1, i64 %35
%37 = load double, double* %36
%38 = getelementptr inbounds double, double* %1, i64 %31
%39 = load double, double* %38
%40 = fsub double %37, %39
%41 = fcmp olt double %40, %6
%42 = fcmp olt double %39, %5
%43 = or i1 %42, %41
br i1 %43, label %50, label %44
44: ; preds = %34, %30
%45 = load double, double* @NAN
%46 = getelementptr inbounds double, double* %0, i64 %31
store double %45, double* %46
%47 = add nsw i64 %31, -1
%48 = add nuw i32 %32, 1
%49 = icmp eq i32 %32, %17
br i1 %49, label %50, label %30
50: ; preds = %44, %34, %22
%51 = icmp slt i32 %17, %2
br i1 %51, label %52, label %74
52: ; preds = %50
%53 = sub i32 %2, %17
br label %54
54: ; preds = %52, %68
%55 = phi i64 [ %18, %52 ], [ %71, %68 ]
%56 = phi i32 [ 0, %52 ], [ %72, %68 ]
%57 = icmp sgt i32 %56, %7
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = add nsw i64 %55, -1
%60 = getelementptr inbounds double, double* %1, i64 %59
%61 = load double, double* %60
%62 = getelementptr inbounds double, double* %1, i64 %55
%63 = load double, double* %62
%64 = fsub double %61, %63
%65 = fcmp olt double %64, %6
%66 = fcmp olt double %63, %5
%67 = or i1 %66, %65
br i1 %67, label %74, label %68
68: ; preds = %58, %54
%69 = load double, double* @NAN
%70 = getelementptr inbounds double, double* %0, i64 %55
store double %69, double* %70
%71 = add nsw i64 %55, 1
%72 = add nuw i32 %56, 1
%73 = icmp eq i32 %72, %53
br i1 %73, label %74, label %54
74: ; preds = %58, %68, %50, %26
%75 = add nuw nsw i64 %15, 1
%76 = icmp eq i64 %75, %13
br i1 %76, label %77, label %14
77: ; preds = %74, %8
ret void
}