#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 const cos(double);
double const sin(double);
double trap_energy(int num_ptcls, const double *x, double kx, double ky,
                   double kz, double theta, double charge, double mass,
                   double omega, double B_z) {
  double energy = 0.0;
  double xr, yr, zr;
  int i;
  for (i = 0; i < num_ptcls; ++i) {
    xr = cos(theta) * x[i * 3 + 0] - sin(theta) * x[i * 3 + 1];
    yr = sin(theta) * x[i * 3 + 0] + cos(theta) * x[i * 3 + 1];
    zr = x[i * 3 + 2];
    energy +=
        0.5 * charge *
        (kz * zr * zr + kx * xr * xr + ky * yr * yr +
         (B_z * omega - 2.0 * mass * omega * omega) * (xr * xr + yr * yr));
  }
  return energy;
}


x86 assembly (clang, -O0):
<trap_energy>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  %xmm4,-0x38(%rbp)
movsd  %xmm5,-0x40(%rbp)
movsd  %xmm6,-0x48(%rbp)
movsd  %xmm7,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1340 <trap_energy+0x220>
movsd  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x10(%rbp),%rax
imul   $0x3,-0x74(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
movsd  -0x98(%rbp),%xmm2
ff
movaps %xmm0,%xmm1
movsd  -0x90(%rbp),%xmm0
ff
mov    -0x10(%rbp),%rax
imul   $0x3,-0x74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x80(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x74(%rbp),%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x88(%rbp),%xmm2
ff
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x74(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x74(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xd8e(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  -0x70(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm3
movsd  -0x18(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm4
movsd  0xd32(%rip),%xmm3
mulsd  -0x40(%rbp),%xmm3
mulsd  -0x48(%rbp),%xmm3
mulsd  -0x48(%rbp),%xmm3
movq   %xmm3,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm3
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
movsd  -0x60(%rbp),%xmm3
movsd  -0x60(%rbp),%xmm5
movsd  -0x68(%rbp),%xmm4
mulsd  -0x68(%rbp),%xmm4
mulsd  %xmm5,%xmm3
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1169 <trap_energy+0x49>
movsd  -0x58(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trap_energy>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
movsd  %xmm4,0x10(%rsp)
test   %edi,%edi
jle    1298 <trap_energy+0x178>
movapd %xmm0,%xmm8
mov    %rsi,%r15
movsd  0x10(%rsp),%xmm0
mulsd  0xeb3(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xead(%rip),%xmm5
mulsd  %xmm6,%xmm5
mulsd  %xmm6,%xmm5
mulsd  %xmm6,%xmm7
addsd  %xmm5,%xmm7
movsd  %xmm7,0x38(%rsp)
mov    %edi,%eax
shl    $0x3,%rax
lea    (%rax,%rax,2),%r14
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm1,0x28(%rsp)
movsd  %xmm8,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x48(%rsp)
movapd %xmm3,%xmm0
call   1040 <cos@plt>
mulsd  (%r15,%rbx,1),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  0x8(%r15,%rbx,1),%xmm0
movsd  0x18(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <sin@plt>
mulsd  (%r15,%rbx,1),%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
movsd  0x20(%rsp),%xmm8
movsd  0x28(%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
mulsd  0x8(%r15,%rbx,1),%xmm0
addsd  0x40(%rsp),%xmm0
movsd  0x10(%r15,%rbx,1),%xmm5
movapd %xmm5,%xmm4
mulsd  %xmm2,%xmm4
movsd  0x18(%rsp),%xmm6
movapd %xmm6,%xmm3
mulsd  %xmm8,%xmm3
mulsd  %xmm6,%xmm3
mulsd  %xmm5,%xmm4
addsd  %xmm3,%xmm4
movsd  0x8(%rsp),%xmm3
movapd %xmm0,%xmm5
mulsd  %xmm1,%xmm5
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
mulsd  %xmm0,%xmm0
movapd %xmm6,%xmm4
mulsd  %xmm6,%xmm4
addsd  %xmm0,%xmm4
movsd  0x48(%rsp),%xmm0
mulsd  0x38(%rsp),%xmm4
addsd  %xmm5,%xmm4
mulsd  0x10(%rsp),%xmm4
addsd  %xmm4,%xmm0
add    $0x18,%rbx
cmp    %rbx,%r14
jne    11a0 <trap_energy+0x80>
jmp    129c <trap_energy+0x17c>
xorpd  %xmm0,%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @trap_energy(i32 %0, double* %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8, double %9) {
%11 = alloca i32
%12 = alloca double*
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca double
%25 = alloca i32
store i32 %0, i32* %11
store double* %1, double** %12
store double %2, double* %13
store double %3, double* %14
store double %4, double* %15
store double %5, double* %16
store double %6, double* %17
store double %7, double* %18
store double %8, double* %19
store double %9, double* %20
store double 0.000000e+00, double* %21
store i32 0, i32* %25
br label %26
26: ; preds = %115, %10
%27 = load i32, i32* %25
%28 = load i32, i32* %11
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %118
30: ; preds = %26
%31 = load double, double* %16
%32 = call double @cos(double %31)
%33 = load double*, double** %12
%34 = load i32, i32* %25
%35 = mul nsw i32 %34, 3
%36 = add nsw i32 %35, 0
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %33, i64 %37
%39 = load double, double* %38
%40 = load double, double* %16
%41 = call double @sin(double %40)
%42 = load double*, double** %12
%43 = load i32, i32* %25
%44 = mul nsw i32 %43, 3
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %42, i64 %46
%48 = load double, double* %47
%49 = fmul double %41, %48
%50 = fneg double %49
%51 = call double @llvm.fmuladd.f64(double %32, double %39, double %50)
store double %51, double* %22
%52 = load double, double* %16
%53 = call double @sin(double %52)
%54 = load double*, double** %12
%55 = load i32, i32* %25
%56 = mul nsw i32 %55, 3
%57 = add nsw i32 %56, 0
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %54, i64 %58
%60 = load double, double* %59
%61 = load double, double* %16
%62 = call double @cos(double %61)
%63 = load double*, double** %12
%64 = load i32, i32* %25
%65 = mul nsw i32 %64, 3
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %63, i64 %67
%69 = load double, double* %68
%70 = fmul double %62, %69
%71 = call double @llvm.fmuladd.f64(double %53, double %60, double %70)
store double %71, double* %23
%72 = load double*, double** %12
%73 = load i32, i32* %25
%74 = mul nsw i32 %73, 3
%75 = add nsw i32 %74, 2
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %72, i64 %76
%78 = load double, double* %77
store double %78, double* %24
%79 = load double, double* %17
%80 = fmul double 5.000000e-01, %79
%81 = load double, double* %15
%82 = load double, double* %24
%83 = fmul double %81, %82
%84 = load double, double* %24
%85 = load double, double* %13
%86 = load double, double* %22
%87 = fmul double %85, %86
%88 = load double, double* %22
%89 = fmul double %87, %88
%90 = call double @llvm.fmuladd.f64(double %83, double %84, double %89)
%91 = load double, double* %14
%92 = load double, double* %23
%93 = fmul double %91, %92
%94 = load double, double* %23
%95 = call double @llvm.fmuladd.f64(double %93, double %94, double %90)
%96 = load double, double* %20
%97 = load double, double* %19
%98 = load double, double* %18
%99 = fmul double 2.000000e+00, %98
%100 = load double, double* %19
%101 = fmul double %99, %100
%102 = load double, double* %19
%103 = fmul double %101, %102
%104 = fneg double %103
%105 = call double @llvm.fmuladd.f64(double %96, double %97, double %104)
%106 = load double, double* %22
%107 = load double, double* %22
%108 = load double, double* %23
%109 = load double, double* %23
%110 = fmul double %108, %109
%111 = call double @llvm.fmuladd.f64(double %106, double %107, double %110)
%112 = call double @llvm.fmuladd.f64(double %105, double %111, double %95)
%113 = load double, double* %21
%114 = call double @llvm.fmuladd.f64(double %80, double %112, double %113)
store double %114, double* %21
br label %115
115: ; preds = %30
%116 = load i32, i32* %25
%117 = add nsw i32 %116, 1
store i32 %117, i32* %25
br label %26
118: ; preds = %26
%119 = load double, double* %21
ret double %119
}

LLVM IR (-O2):
define double @trap_energy(i32 %0, double* nocapture %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8, double %9) {
%11 = icmp sgt i32 %0, 0
br i1 %11, label %12, label %54
12: ; preds = %10
%13 = fmul double %6, 5.000000e-01
%14 = fmul double %7, -2.000000e+00
%15 = fmul double %14, %8
%16 = fmul double %15, %8
%17 = tail call double @llvm.fmuladd.f64(double %9, double %8, double %16)
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %12, %19
%20 = phi i64 [ 0, %12 ], [ %52, %19 ]
%21 = phi double [ 0.000000e+00, %12 ], [ %51, %19 ]
%22 = tail call double @cos(double %5)
%23 = mul nuw nsw i64 %20, 3
%24 = getelementptr inbounds double, double* %1, i64 %23
%25 = load double, double* %24
%26 = tail call double @sin(double %5)
%27 = add nuw nsw i64 %23, 1
%28 = getelementptr inbounds double, double* %1, i64 %27
%29 = load double, double* %28
%30 = fneg double %26
%31 = fmul double %29, %30
%32 = tail call double @llvm.fmuladd.f64(double %22, double %25, double %31)
%33 = tail call double @sin(double %5)
%34 = load double, double* %24
%35 = tail call double @cos(double %5)
%36 = load double, double* %28
%37 = fmul double %35, %36
%38 = tail call double @llvm.fmuladd.f64(double %33, double %34, double %37)
%39 = add nuw nsw i64 %23, 2
%40 = getelementptr inbounds double, double* %1, i64 %39
%41 = load double, double* %40
%42 = fmul double %41, %4
%43 = fmul double %32, %2
%44 = fmul double %32, %43
%45 = tail call double @llvm.fmuladd.f64(double %42, double %41, double %44)
%46 = fmul double %38, %3
%47 = tail call double @llvm.fmuladd.f64(double %46, double %38, double %45)
%48 = fmul double %38, %38
%49 = tail call double @llvm.fmuladd.f64(double %32, double %32, double %48)
%50 = tail call double @llvm.fmuladd.f64(double %17, double %49, double %47)
%51 = tail call double @llvm.fmuladd.f64(double %13, double %50, double %21)
%52 = add nuw nsw i64 %20, 1
%53 = icmp eq i64 %52, %18
br i1 %53, label %54, label %19
54: ; preds = %19, %10
%55 = phi double [ 0.000000e+00, %10 ], [ %51, %19 ]
ret double %55
}