#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 /*<<< orphan*/ input_b;
typedef int /*<<< orphan*/ input_a;
typedef int clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int clock();
int /*<<< orphan*/ convolution(double *, int, double *, int, double *);
double cos(double);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
int main() {
  double input_a[5000] = {0.0};
  double input_b[5000] = {0.0};
  double output[(sizeof(input_a) / sizeof(input_a[0])) +
                (sizeof(input_b) / sizeof(input_b[0])) - 1];
  clock_t start;
  clock_t diff;
  for (int i = 0; i < 5000; i++) {
    input_a[i] = sin((double)i / 8.0);
    input_b[i] = cos((double)i / 8.0);
  }
  printf("Start\n");
  start = clock();
  convolution(input_a, (sizeof(input_a) / sizeof(input_a[0])), input_b,
              (sizeof(input_b) / sizeof(input_b[0])), output);
  diff = clock() - start;
  printf("Done.\n");
  int msec = diff * 1000 / CLOCKS_PER_SEC;
  printf("Time taken %d seconds %d milliseconds\n", msec / 1000, msec % 1000);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9c50(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c40,%edx
call   1050 <memset@plt>
lea    -0x13890(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c40,%edx
call   1050 <memset@plt>
movl   $0x0,-0x2711c(%rbp)
cmpl   $0x1388,-0x2711c(%rbp)
jge    1218 <main+0xb8>
cvtsi2sdl -0x2711c(%rbp),%xmm0
ff
movsd  0xe3e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <sin@plt>
movslq -0x2711c(%rbp),%rax
movsd  %xmm0,-0x9c50(%rbp,%rax,8)
ff ff
cvtsi2sdl -0x2711c(%rbp),%xmm0
ff
movsd  0xe15(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1070 <cos@plt>
movslq -0x2711c(%rbp),%rax
movsd  %xmm0,-0x13890(%rbp,%rax,8)
fe ff
mov    -0x2711c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2711c(%rbp)
jmp    11a2 <main+0x42>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x27114(%rbp)
lea    -0x9c50(%rbp),%rdi
lea    -0x13890(%rbp),%rdx
lea    -0x27110(%rbp),%r8
mov    $0x1388,%ecx
mov    %ecx,%esi
call   1080 <convolution@plt>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x27114(%rbp),%eax
mov    %eax,-0x27118(%rbp)
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
imul   $0x3e8,-0x27118(%rbp),%eax
mov    0x2d62(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x27120(%rbp)
mov    -0x27120(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x27120(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x27120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x27108,%rsp
lea    0x9c50(%rsp),%rdi
xor    %ebx,%ebx
mov    $0x9c40,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x9c40,%edx
xor    %esi,%esi
call   1060 <memset@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1070 <sin@plt>
movsd  %xmm0,0x9c50(%rsp,%rbx,8)
movsd  0x8(%rsp),%xmm0
call   1080 <cos@plt>
movsd  %xmm0,0x10(%rsp,%rbx,8)
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe12(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1070 <sin@plt>
movsd  %xmm0,0x9c58(%rsp,%rbx,8)
movsd  0x8(%rsp),%xmm0
call   1080 <cos@plt>
movsd  %xmm0,0x18(%rsp,%rbx,8)
add    $0x2,%rbx
cmp    $0x1388,%rbx
jne    11a0 <main+0x30>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebx
lea    0x9c50(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0x13890(%rsp),%r8
mov    $0x1388,%esi
mov    $0x1388,%ecx
call   1090 <convolution@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%ebp
sub    %ebx,%ebp
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
imul   $0x3e8,%ebp,%eax
mov    0x2d6b(%rip),%rcx
cltd
idivl  (%rcx)
movslq %eax,%rdx
imul   $0x10624dd3,%rdx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
imul   $0x3e8,%esi,%eax
sub    %eax,%edx
lea    0xd62(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x27108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Start\0A\00"
@.str.1 = [7 x i8] c"Done.\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.2 = [39 x i8] c"Time taken %d seconds %d milliseconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5000 x double]
%3 = alloca [5000 x double]
%4 = alloca [9999 x double]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [5000 x double]* %2 to i8*
%10 = bitcast [5000 x double]* %3 to i8*
store i32 0, i32* %7
br label %11
11: ; preds = %29, %0
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 5000
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i32, i32* %7
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 8.000000e+00
%18 = call double @sin(double %17)
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [5000 x double], [5000 x double]* %2, i64 0, i64 %20
store double %18, double* %21
%22 = load i32, i32* %7
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, 8.000000e+00
%25 = call double @cos(double %24)
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [5000 x double], [5000 x double]* %3, i64 0, i64 %27
store double %25, double* %28
br label %29
29: ; preds = %14
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %11
32: ; preds = %11
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%34 = call i32 (...) @clock()
store i32 %34, i32* %5
%35 = getelementptr inbounds [5000 x double], [5000 x double]* %2, i64 0, i64 0
%36 = getelementptr inbounds [5000 x double], [5000 x double]* %3, i64 0, i64 0
%37 = getelementptr inbounds [9999 x double], [9999 x double]* %4, i64 0, i64 0
%38 = call i32 @convolution(double* %35, i32 5000, double* %36, i32 5000, double* %37)
%39 = call i32 (...) @clock()
%40 = load i32, i32* %5
%41 = sub nsw i32 %39, %40
store i32 %41, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = mul nsw i32 %43, 1000
%45 = load i32, i32* @CLOCKS_PER_SEC
%46 = sdiv i32 %44, %45
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = sdiv i32 %47, 1000
%49 = load i32, i32* %8
%50 = srem i32 %49, 1000
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %50)
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
@.str.2 = [39 x i8] c"Time taken %d seconds %d milliseconds\0A\00"
@str = [6 x i8] c"Start\00"
@str.3 = [6 x i8] c"Done.\00"
define i32 @main() {
%1 = alloca [5000 x double]
%2 = alloca [5000 x double]
%3 = alloca [9999 x double]
%4 = bitcast [5000 x double]* %1 to i8*
%5 = bitcast [5000 x double]* %2 to i8*
%6 = bitcast [9999 x double]* %3 to i8*
br label %23
7: ; preds = %23
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (...) @clock()
%10 = getelementptr inbounds [5000 x double], [5000 x double]* %1, i64 0, i64 0
%11 = getelementptr inbounds [5000 x double], [5000 x double]* %2, i64 0, i64 0
%12 = getelementptr inbounds [9999 x double], [9999 x double]* %3, i64 0, i64 0
%13 = call i32 @convolution(double* %10, i32 5000, double* %11, i32 5000, double* %12)
%14 = call i32 (...) @clock()
%15 = sub nsw i32 %14, %9
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
%17 = mul nsw i32 %15, 1000
%18 = load i32, i32* @CLOCKS_PER_SEC
%19 = sdiv i32 %17, %18
%20 = sdiv i32 %19, 1000
%21 = srem i32 %19, 1000
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21)
ret i32 0
23: ; preds = %23, %0
%24 = phi i64 [ 0, %0 ], [ %40, %23 ]
%25 = trunc i64 %24 to i32
%26 = sitofp i32 %25 to double
%27 = fmul double %26, 1.250000e-01
%28 = tail call double @sin(double %27)
%29 = getelementptr inbounds [5000 x double], [5000 x double]* %1, i64 0, i64 %24
store double %28, double* %29
%30 = tail call double @cos(double %27)
%31 = getelementptr inbounds [5000 x double], [5000 x double]* %2, i64 0, i64 %24
store double %30, double* %31
%32 = or i64 %24, 1
%33 = trunc i64 %32 to i32
%34 = sitofp i32 %33 to double
%35 = fmul double %34, 1.250000e-01
%36 = tail call double @sin(double %35)
%37 = getelementptr inbounds [5000 x double], [5000 x double]* %1, i64 0, i64 %32
store double %36, double* %37
%38 = tail call double @cos(double %35)
%39 = getelementptr inbounds [5000 x double], [5000 x double]* %2, i64 0, i64 %32
store double %38, double* %39
%40 = add nuw nsw i64 %24, 2
%41 = icmp eq i64 %40, 5000
br i1 %41, label %7, label %23
}