#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 */
scalar_t__ pow(double, int);
double sqrt(double);
double calc_theta_error(double *theta, double *theta_exact, int N) {
  double theta_error = 0.0;
  int i;
  for (i = 0; i < N; i++)
    theta_error += pow(theta_exact[i] - theta[i], 2);
  theta_error /= N;
  theta_error = sqrt(theta_error);
  return theta_error;
}


x86 assembly (clang, -O0):
<calc_theta_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118f <calc_theta_error+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1142 <calc_theta_error+0x22>
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_theta_error>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
test   %edx,%edx
jle    1204 <calc_theta_error+0xe4>
mov    %rsi,%rbp
mov    %rdi,%r12
mov    %r14d,%r15d
cmp    $0x1,%r14d
jne    1155 <calc_theta_error+0x35>
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
jmp    11ca <calc_theta_error+0xaa>
mov    %r15d,%r13d
and    $0xfffffffe,%r13d
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm2,(%rsp)
movsd  0x0(%rbp,%rbx,8),%xmm0
subsd  (%r12,%rbx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rbp,%rbx,8),%xmm0
subsd  0x8(%r12,%rbx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
addsd  (%rsp),%xmm2
add    $0x2,%rbx
cmp    %rbx,%r13
jne    1170 <calc_theta_error+0x50>
test   $0x1,%r15b
xorpd  %xmm1,%xmm1
je     1204 <calc_theta_error+0xe4>
movsd  0x0(%rbp,%rbx,8),%xmm0
subsd  (%r12,%rbx,8),%xmm0
mov    $0x2,%edi
movsd  %xmm2,(%rsp)
call   1030 <pow@plt>
movsd  (%rsp),%xmm2
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
jb     122c <calc_theta_error+0x10c>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movapd %xmm2,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @calc_theta_error(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %7
store i32 0, i32* %8
br label %9
9: ; preds = %29, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load double*, double** %5
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = load double*, double** %4
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fsub double %18, %23
%25 = call i64 @pow(double %24, i32 2)
%26 = sitofp i64 %25 to double
%27 = load double, double* %7
%28 = fadd double %27, %26
store double %28, double* %7
br label %29
29: ; preds = %13
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %9
32: ; preds = %9
%33 = load i32, i32* %6
%34 = sitofp i32 %33 to double
%35 = load double, double* %7
%36 = fdiv double %35, %34
store double %36, double* %7
%37 = load double, double* %7
%38 = call double @sqrt(double %37)
store double %38, double* %7
%39 = load double, double* %7
ret double %39
}

LLVM IR (-O2):
define double @calc_theta_error(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %49
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = and i64 %6, 1
%8 = icmp eq i32 %2, 1
br i1 %8, label %35, label %9
9: ; preds = %5
%10 = and i64 %6, 4294967294
br label %11
11: ; preds = %11, %9
%12 = phi i64 [ 0, %9 ], [ %32, %11 ]
%13 = phi double [ 0.000000e+00, %9 ], [ %31, %11 ]
%14 = phi i64 [ 0, %9 ], [ %33, %11 ]
%15 = getelementptr inbounds double, double* %1, i64 %12
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %0, i64 %12
%18 = load double, double* %17
%19 = fsub double %16, %18
%20 = tail call i64 @pow(double %19, i32 2)
%21 = sitofp i64 %20 to double
%22 = fadd double %13, %21
%23 = or i64 %12, 1
%24 = getelementptr inbounds double, double* %1, i64 %23
%25 = load double, double* %24
%26 = getelementptr inbounds double, double* %0, i64 %23
%27 = load double, double* %26
%28 = fsub double %25, %27
%29 = tail call i64 @pow(double %28, i32 2)
%30 = sitofp i64 %29 to double
%31 = fadd double %22, %30
%32 = add nuw nsw i64 %12, 2
%33 = add i64 %14, 2
%34 = icmp eq i64 %33, %10
br i1 %34, label %35, label %11
35: ; preds = %11, %5
%36 = phi double [ undef, %5 ], [ %31, %11 ]
%37 = phi i64 [ 0, %5 ], [ %32, %11 ]
%38 = phi double [ 0.000000e+00, %5 ], [ %31, %11 ]
%39 = icmp eq i64 %7, 0
br i1 %39, label %49, label %40
40: ; preds = %35
%41 = getelementptr inbounds double, double* %1, i64 %37
%42 = load double, double* %41
%43 = getelementptr inbounds double, double* %0, i64 %37
%44 = load double, double* %43
%45 = fsub double %42, %44
%46 = tail call i64 @pow(double %45, i32 2)
%47 = sitofp i64 %46 to double
%48 = fadd double %38, %47
br label %49
49: ; preds = %40, %35, %3
%50 = phi double [ 0.000000e+00, %3 ], [ %36, %35 ], [ %48, %40 ]
%51 = sitofp i32 %2 to double
%52 = fdiv double %50, %51
%53 = tail call double @sqrt(double %52)
ret double %53
}