#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*/ memcpy(double *, double const *, int const);
void extract_spikes(double *out, const double *samples, int nsamples,
                    const int *times, int ntimes, int windowstart,
                    int windowstop) {
  const int window = windowstart + windowstop;
  int i, event;
  for (i = 0; i < ntimes; ++i) {
    event = times[i];
    if ((event - windowstart < 0) || (event + windowstop > nsamples))
      continue;
    memcpy(out + (i * window), samples + event - windowstart,
           window * sizeof(double));
  }
}


x86 assembly (clang, -O0):
<extract_spikes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11cf <extract_spikes+0xbf>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
sub    -0x28(%rbp),%eax
cmp    $0x0,%eax
jl     117a <extract_spikes+0x6a>
mov    -0x34(%rbp),%eax
add    0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    117f <extract_spikes+0x6f>
jmp    11c1 <extract_spikes+0xb1>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
movslq -0x28(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
shl    $0x3,%rax
add    %rax,%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1142 <extract_spikes+0x32>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_spikes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,0x10(%rsp)
test   %r8d,%r8d
jle    1197 <extract_spikes+0x87>
mov    %r9d,%ebx
mov    %rcx,%r14
mov    %rdi,%rbp
mov    0x50(%rsp),%eax
lea    (%rax,%rbx,1),%ecx
movslq %r9d,%rax
movslq %ecx,%r15
shl    $0x3,%ecx
mov    %ecx,0x8(%rsp)
mov    %r8d,%r13d
shl    $0x3,%rax
sub    %rax,0x10(%rsp)
shl    $0x3,%r15
xor    %r12d,%r12d
jmp    116c <extract_spikes+0x5c>
xchg   %ax,%ax
add    $0x1,%r12
add    %r15,%rbp
cmp    %r12,%r13
je     1197 <extract_spikes+0x87>
movslq (%r14,%r12,4),%rax
cmp    %ebx,%eax
jl     1160 <extract_spikes+0x50>
mov    0x50(%rsp),%ecx
add    %eax,%ecx
cmp    0xc(%rsp),%ecx
jg     1160 <extract_spikes+0x50>
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,8),%rsi
mov    %rbp,%rdi
mov    0x8(%rsp),%edx
call   1030 <memcpy@plt>
jmp    1160 <extract_spikes+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @extract_spikes(double* %0, double* %1, i32 %2, i32* %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store double* %0, double** %8
store double* %1, double** %9
store i32 %2, i32* %10
store i32* %3, i32** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%18 = load i32, i32* %13
%19 = load i32, i32* %14
%20 = add nsw i32 %18, %19
store i32 %20, i32* %15
store i32 0, i32* %16
br label %21
21: ; preds = %62, %7
%22 = load i32, i32* %16
%23 = load i32, i32* %12
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %65
25: ; preds = %21
%26 = load i32*, i32** %11
%27 = load i32, i32* %16
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
store i32 %30, i32* %17
%31 = load i32, i32* %17
%32 = load i32, i32* %13
%33 = sub nsw i32 %31, %32
%34 = icmp slt i32 %33, 0
br i1 %34, label %41, label %35
35: ; preds = %25
%36 = load i32, i32* %17
%37 = load i32, i32* %14
%38 = add nsw i32 %36, %37
%39 = load i32, i32* %10
%40 = icmp sgt i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %35, %25
br label %62
42: ; preds = %35
%43 = load double*, double** %8
%44 = load i32, i32* %16
%45 = load i32, i32* %15
%46 = mul nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %43, i64 %47
%49 = load double*, double** %9
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = sub i64 0, %54
%56 = getelementptr inbounds double, double* %52, i64 %55
%57 = load i32, i32* %15
%58 = sext i32 %57 to i64
%59 = mul i64 %58, 8
%60 = trunc i64 %59 to i32
%61 = call i32 @memcpy(double* %48, double* %56, i32 %60)
br label %62
62: ; preds = %42, %41
%63 = load i32, i32* %16
%64 = add nsw i32 %63, 1
store i32 %64, i32* %16
br label %21
65: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @extract_spikes(double* %0, double* %1, i32 %2, i32* nocapture %3, i32 %4, i32 %5, i32 %6) {
%8 = add nsw i32 %6, %5
%9 = icmp sgt i32 %4, 0
br i1 %9, label %10, label %34
10: ; preds = %7
%11 = sext i32 %5 to i64
%12 = sub nsw i64 0, %11
%13 = shl i32 %8, 3
%14 = sext i32 %8 to i64
%15 = zext i32 %4 to i64
%16 = getelementptr inbounds double, double* %1, i64 %12
br label %17
17: ; preds = %10, %31
%18 = phi i64 [ 0, %10 ], [ %32, %31 ]
%19 = getelementptr inbounds i32, i32* %3, i64 %18
%20 = load i32, i32* %19
%21 = icmp slt i32 %20, %5
%22 = add nsw i32 %20, %6
%23 = icmp sgt i32 %22, %2
%24 = select i1 %21, i1 true, i1 %23
br i1 %24, label %31, label %25
25: ; preds = %17
%26 = mul nsw i64 %18, %14
%27 = getelementptr inbounds double, double* %0, i64 %26
%28 = sext i32 %20 to i64
%29 = getelementptr inbounds double, double* %16, i64 %28
%30 = tail call i32 @memcpy(double* %27, double* %29, i32 %13)
br label %31
31: ; preds = %17, %25
%32 = add nuw nsw i64 %18, 1
%33 = icmp eq i64 %32, %15
br i1 %33, label %34, label %17
34: ; preds = %31, %7
ret void
}