#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 cos(double);
double sin(double);
double kern1() {
  double x[20000];
  double y[20000];
  double res = 0.;
  int i;
  for (i = 0; i < 20000; ++i) {
    x[i] = sin((double)i * 3.14159265358979323846);
    y[i] = cos((double)i);
    res += x[i] * y[i];
  }
  return res;
}


x86 assembly (clang, -O0):
<kern1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e210,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x4e208(%rbp)
ff
movl   $0x0,-0x4e20c(%rbp)
cmpl   $0x4e20,-0x4e20c(%rbp)
jge    11e2 <kern1+0xc2>
cvtsi2sdl -0x4e20c(%rbp),%xmm0
ff
movsd  0xea0(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movslq -0x4e20c(%rbp),%rax
movsd  %xmm0,-0x27100(%rbp,%rax,8)
fd ff
cvtsi2sdl -0x4e20c(%rbp),%xmm0
ff
call   1040 <cos@plt>
movslq -0x4e20c(%rbp),%rax
movsd  %xmm0,-0x4e200(%rbp,%rax,8)
fb ff
movslq -0x4e20c(%rbp),%rax
movsd  -0x27100(%rbp,%rax,8),%xmm0
fd ff
movslq -0x4e20c(%rbp),%rax
movsd  -0x4e200(%rbp,%rax,8),%xmm2
fb ff
movsd  -0x4e208(%rbp),%xmm1
ff
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x4e208(%rbp)
ff
mov    -0x4e20c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e20c(%rbp)
jmp    1140 <kern1+0x20>
movsd  -0x4e208(%rbp),%xmm0
ff
add    $0x4e210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kern1>:
push   %rbx
sub    $0x20,%rsp
xorpd  %xmm1,%xmm1
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0xea6(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,(%rsp)
mulsd  0xe68(%rip),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm0
call   1040 <cos@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
addsd  0xe41(%rip),%xmm1
add    $0x2,%ebx
cmp    $0x4e21,%ebx
jne    1140 <kern1+0x20>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @kern1() {
%1 = alloca [20000 x double]
%2 = alloca [20000 x double]
%3 = alloca double
%4 = alloca i32
store double 0.000000e+00, double* %3
store i32 0, i32* %4
br label %5
5: ; preds = %32, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 20000
br i1 %7, label %8, label %35
8: ; preds = %5
%9 = load i32, i32* %4
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 0x400921FB54442D18
%12 = call double @sin(double %11)
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %14
store double %12, double* %15
%16 = load i32, i32* %4
%17 = sitofp i32 %16 to double
%18 = call double @cos(double %17)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %20
store double %18, double* %21
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20000 x double], [20000 x double]* %1, i64 0, i64 %23
%25 = load double, double* %24
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [20000 x double], [20000 x double]* %2, i64 0, i64 %27
%29 = load double, double* %28
%30 = load double, double* %3
%31 = call double @llvm.fmuladd.f64(double %25, double %29, double %30)
store double %31, double* %3
br label %32
32: ; preds = %8
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %5
35: ; preds = %5
%36 = load double, double* %3
ret double %36
}

LLVM IR (-O2):
define double @kern1() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 0, %0 ], [ %15, %1 ]
%3 = phi double [ 0.000000e+00, %0 ], [ %14, %1 ]
%4 = sitofp i32 %2 to double
%5 = fmul double %4, 0x400921FB54442D18
%6 = tail call double @sin(double %5)
%7 = tail call double @cos(double %4)
%8 = tail call double @llvm.fmuladd.f64(double %6, double %7, double %3)
%9 = or i32 %2, 1
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 0x400921FB54442D18
%12 = tail call double @sin(double %11)
%13 = tail call double @cos(double %10)
%14 = tail call double @llvm.fmuladd.f64(double %12, double %13, double %8)
%15 = add nuw nsw i32 %2, 2
%16 = icmp eq i32 %15, 20000
br i1 %16, label %17, label %1
17: ; preds = %1
ret double %14
}