#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 */
void convolutions_convolve(const double first[], size_t first_len,
                           const double second[], size_t second_len,
                           double convolved[]) {
  size_t n;
  for (n = 0; n < first_len + second_len - 1; n++) {
    size_t kmin, kmax, k;
    convolved[n] = 0;
    kmin = (n >= second_len - 1) ? n - (second_len - 1) : 0;
    kmax = (n < first_len - 1) ? n : first_len - 1;
    for (k = kmin; k <= kmax; k++) {
      convolved[n] += first[k] * second[n - k];
    }
  }
}


x86 assembly (clang, -O0):
<convolutions_convolve>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    1234 <convolutions_convolve+0x134>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     1176 <convolutions_convolve+0x76>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
jmp    1181 <convolutions_convolve+0x81>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    1181 <convolutions_convolve+0x81>
mov    -0x50(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jae    11ab <convolutions_convolve+0xab>
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    11b7 <convolutions_convolve+0xb7>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
ja     121e <convolutions_convolve+0x11e>
mov    -0x8(%rbp),%rax
mov    -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11c7 <convolutions_convolve+0xc7>
jmp    1223 <convolutions_convolve+0x123>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1120 <convolutions_convolve+0x20>
pop    %rbp
ret

x86 assembly (clang, -O2):
<convolutions_convolve>:
push   %r14
push   %rbx
add    $0xffffffffffffffff,%rsi
mov    %rsi,%r9
add    %rcx,%r9
je     1182 <convolutions_convolve+0x82>
add    $0xffffffffffffffff,%rcx
xor    %r10d,%r10d
jmp    1129 <convolutions_convolve+0x29>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r10
cmp    %r9,%r10
je     1182 <convolutions_convolve+0x82>
mov    %r10,%rbx
sub    %rcx,%rbx
mov    %rcx,%r14
cmovb  %r10,%r14
movq   $0x0,(%r8,%r10,8)
mov    $0x0,%eax
cmovae %rbx,%rax
cmp    %rsi,%r10
mov    %rsi,%r11
cmovb  %r10,%r11
cmp    %r11,%rax
ja     1120 <convolutions_convolve+0x20>
lea    (%rdx,%r14,8),%rbx
xorpd  %xmm0,%xmm0
xchg   %ax,%ax
movsd  (%rdi,%rax,8),%xmm1
mulsd  (%rbx),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r8,%r10,8)
add    $0x1,%rax
add    $0xfffffffffffffff8,%rbx
cmp    %r11,%rax
jbe    1160 <convolutions_convolve+0x60>
jmp    1120 <convolutions_convolve+0x20>
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @convolutions_convolve(double* %0, i64 %1, double* %2, i64 %3, double* %4) {
%6 = alloca double*
%7 = alloca i64
%8 = alloca double*
%9 = alloca i64
%10 = alloca double*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
store double* %0, double** %6
store i64 %1, i64* %7
store double* %2, double** %8
store i64 %3, i64* %9
store double* %4, double** %10
store i64 0, i64* %11
br label %15
15: ; preds = %74, %5
%16 = load i64, i64* %11
%17 = load i64, i64* %7
%18 = load i64, i64* %9
%19 = add i64 %17, %18
%20 = sub i64 %19, 1
%21 = icmp ult i64 %16, %20
br i1 %21, label %22, label %77
22: ; preds = %15
%23 = load double*, double** %10
%24 = load i64, i64* %11
%25 = getelementptr inbounds double, double* %23, i64 %24
store double 0.000000e+00, double* %25
%26 = load i64, i64* %11
%27 = load i64, i64* %9
%28 = sub i64 %27, 1
%29 = icmp uge i64 %26, %28
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i64, i64* %11
%32 = load i64, i64* %9
%33 = sub i64 %32, 1
%34 = sub i64 %31, %33
br label %36
35: ; preds = %22
br label %36
36: ; preds = %35, %30
%37 = phi i64 [ %34, %30 ], [ 0, %35 ]
store i64 %37, i64* %12
%38 = load i64, i64* %11
%39 = load i64, i64* %7
%40 = sub i64 %39, 1
%41 = icmp ult i64 %38, %40
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = load i64, i64* %11
br label %47
44: ; preds = %36
%45 = load i64, i64* %7
%46 = sub i64 %45, 1
br label %47
47: ; preds = %44, %42
%48 = phi i64 [ %43, %42 ], [ %46, %44 ]
store i64 %48, i64* %13
%49 = load i64, i64* %12
store i64 %49, i64* %14
br label %50
50: ; preds = %70, %47
%51 = load i64, i64* %14
%52 = load i64, i64* %13
%53 = icmp ule i64 %51, %52
br i1 %53, label %54, label %73
54: ; preds = %50
%55 = load double*, double** %6
%56 = load i64, i64* %14
%57 = getelementptr inbounds double, double* %55, i64 %56
%58 = load double, double* %57
%59 = load double*, double** %8
%60 = load i64, i64* %11
%61 = load i64, i64* %14
%62 = sub i64 %60, %61
%63 = getelementptr inbounds double, double* %59, i64 %62
%64 = load double, double* %63
%65 = load double*, double** %10
%66 = load i64, i64* %11
%67 = getelementptr inbounds double, double* %65, i64 %66
%68 = load double, double* %67
%69 = call double @llvm.fmuladd.f64(double %58, double %64, double %68)
store double %69, double* %67
br label %70
70: ; preds = %54
%71 = load i64, i64* %14
%72 = add i64 %71, 1
store i64 %72, i64* %14
br label %50
73: ; preds = %50
br label %74
74: ; preds = %73
%75 = load i64, i64* %11
%76 = add i64 %75, 1
store i64 %76, i64* %11
br label %15
77: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @convolutions_convolve(double* nocapture %0, i64 %1, double* nocapture %2, i64 %3, double* nocapture %4) {
%6 = add i64 %1, -1
%7 = add i64 %6, %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %5
%10 = add i64 %3, -1
br label %11
11: ; preds = %9, %29
%12 = phi i64 [ 0, %9 ], [ %30, %29 ]
%13 = getelementptr inbounds double, double* %4, i64 %12
store double 0.000000e+00, double* %13
%14 = tail call i64 @llvm.usub.sat.i64(i64 %12, i64 %10)
%15 = icmp ult i64 %12, %6
%16 = select i1 %15, i64 %12, i64 %6
%17 = icmp ugt i64 %14, %16
br i1 %17, label %29, label %18
18: ; preds = %11, %18
%19 = phi double [ %26, %18 ], [ 0.000000e+00, %11 ]
%20 = phi i64 [ %27, %18 ], [ %14, %11 ]
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = sub i64 %12, %20
%24 = getelementptr inbounds double, double* %2, i64 %23
%25 = load double, double* %24
%26 = tail call double @llvm.fmuladd.f64(double %22, double %25, double %19)
store double %26, double* %13
%27 = add i64 %20, 1
%28 = icmp ugt i64 %27, %16
br i1 %28, label %29, label %18
29: ; preds = %18, %11
%30 = add nuw i64 %12, 1
%31 = icmp eq i64 %30, %7
br i1 %31, label %32, label %11
32: ; preds = %29, %5
ret void
}