#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 amesh_LogGrid();
double log_amesh_LogGrid();
double pow(double, double);
double *r_LogGrid();
double sqrt(double);
double Norm(int M, double gamma, double *u) {
  int i;
  double r0, sum, amesh, log_amesh, *r;
  amesh = amesh_LogGrid();
  log_amesh = log_amesh_LogGrid();
  r = r_LogGrid();
  r0 = r[0] / sqrt(amesh);
  sum = pow(r0, (2.0 * gamma + 1.0)) / (2.0 * gamma + 1.0);
  for (i = 0; i <= (M - 3); ++i)
    sum += log_amesh * r[i] * (u[i] * u[i]);
  sum +=
      log_amesh *
      (23.0 * r[M - 2] * (u[M - 2] * u[M - 2]) +
       28.0 * r[M - 1] * (u[M - 1] * u[M - 1]) + 9.0 * r[M] * (u[M] * u[M])) /
      24.0;
  return sum;
}


x86 assembly (clang, -O0):
<Norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1070 <amesh_LogGrid@plt>
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <log_amesh_LogGrid@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <r_LogGrid@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe3b(%rip),%xmm2
addsd  %xmm2,%xmm1
call   1050 <pow@plt>
movsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xe21(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jg     1250 <Norm+0x100>
movsd  -0x40(%rbp),%xmm0
mov    -0x48(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f3 <Norm+0xa3>
movsd  -0x40(%rbp),%xmm0
mov    -0x48(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  0xdb6(%rip),%xmm2
mulsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm3
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm3
mov    -0x48(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xd70(%rip),%xmm1
mulsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm4
mov    -0x18(%rbp),%rax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm4
mulsd  %xmm4,%xmm1
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
mov    -0x48(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  0xd23(%rip),%xmm1
mulsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm3
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xce8(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Norm>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r15
movsd  %xmm0,0x10(%rsp)
mov    %edi,%r14d
xor    %eax,%eax
call   1070 <amesh_LogGrid@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <log_amesh_LogGrid@plt>
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1040 <r_LogGrid@plt>
mov    %rax,%rbx
movsd  (%rax),%xmm3
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm2
ucomisd %xmm0,%xmm2
movapd %xmm2,%xmm0
jb     11a7 <Norm+0x57>
sqrtsd %xmm0,%xmm0
jmp    11b8 <Norm+0x68>
movsd  %xmm3,0x8(%rsp)
call   1060 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
divsd  %xmm0,%xmm3
movsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  0xe32(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
movapd %xmm3,%xmm0
call   1050 <pow@plt>
divsd  0x10(%rsp),%xmm0
lea    -0x2(%r14),%eax
cmp    $0x3,%r14d
jge    11f8 <Norm+0xa8>
movsd  0x18(%rsp),%xmm6
jmp    1285 <Norm+0x135>
mov    %eax,%ecx
cmp    $0x1,%eax
movsd  0x18(%rsp),%xmm6
jne    1209 <Norm+0xb9>
xor    %edx,%edx
jmp    1265 <Norm+0x115>
mov    %ecx,%esi
and    $0xfffffffe,%esi
xor    %edx,%edx
movapd %xmm0,%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rbx,%rdx,8),%xmm2
mulsd  %xmm6,%xmm2
movsd  (%r15,%rdx,8),%xmm3
movsd  0x8(%r15,%rdx,8),%xmm0
mulsd  %xmm3,%xmm3
mulsd  %xmm2,%xmm3
addsd  %xmm1,%xmm3
movsd  0x8(%rbx,%rdx,8),%xmm1
mulsd  %xmm6,%xmm1
mulsd  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
add    $0x2,%rdx
movapd %xmm0,%xmm1
cmp    %rdx,%rsi
jne    1220 <Norm+0xd0>
test   $0x1,%cl
je     1285 <Norm+0x135>
movsd  (%rbx,%rdx,8),%xmm1
mulsd  %xmm6,%xmm1
movsd  (%r15,%rdx,8),%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
cltq
movsd  (%rbx,%rax,8),%xmm1
mulsd  0xd74(%rip),%xmm1
movsd  (%r15,%rax,8),%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm1,%xmm2
movslq %r14d,%rax
movsd  -0x8(%rbx,%rax,8),%xmm1
movsd  (%rbx,%rax,8),%xmm3
mulsd  0xd58(%rip),%xmm1
movsd  -0x8(%r15,%rax,8),%xmm4
movsd  (%r15,%rax,8),%xmm5
mulsd  %xmm4,%xmm4
mulsd  %xmm1,%xmm4
mulsd  0xd43(%rip),%xmm3
addsd  %xmm2,%xmm4
mulsd  %xmm5,%xmm5
mulsd  %xmm3,%xmm5
addsd  %xmm4,%xmm5
mulsd  %xmm5,%xmm6
divsd  0xd2f(%rip),%xmm6
addsd  %xmm0,%xmm6
movapd %xmm6,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @Norm(i32 %0, double %1, double* nocapture %2) {
%4 = tail call double (...) @amesh_LogGrid()
%5 = tail call double (...) @log_amesh_LogGrid()
%6 = tail call double* (...) @r_LogGrid()
%7 = load double, double* %6
%8 = tail call double @sqrt(double %4)
%9 = fdiv double %7, %8
%10 = tail call double @llvm.fmuladd.f64(double %1, double 2.000000e+00, double 1.000000e+00)
%11 = tail call double @pow(double %9, double %10)
%12 = fdiv double %11, %10
%13 = icmp slt i32 %0, 3
%14 = add nsw i32 %0, -2
br i1 %13, label %56, label %15
15: ; preds = %3
%16 = zext i32 %14 to i64
%17 = and i64 %16, 1
%18 = icmp eq i32 %14, 1
br i1 %18, label %43, label %19
19: ; preds = %15
%20 = and i64 %16, 4294967294
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %40, %21 ]
%23 = phi double [ %12, %19 ], [ %39, %21 ]
%24 = phi i64 [ 0, %19 ], [ %41, %21 ]
%25 = getelementptr inbounds double, double* %6, i64 %22
%26 = load double, double* %25
%27 = fmul double %5, %26
%28 = getelementptr inbounds double, double* %2, i64 %22
%29 = load double, double* %28
%30 = fmul double %29, %29
%31 = tail call double @llvm.fmuladd.f64(double %27, double %30, double %23)
%32 = or i64 %22, 1
%33 = getelementptr inbounds double, double* %6, i64 %32
%34 = load double, double* %33
%35 = fmul double %5, %34
%36 = getelementptr inbounds double, double* %2, i64 %32
%37 = load double, double* %36
%38 = fmul double %37, %37
%39 = tail call double @llvm.fmuladd.f64(double %35, double %38, double %31)
%40 = add nuw nsw i64 %22, 2
%41 = add i64 %24, 2
%42 = icmp eq i64 %41, %20
br i1 %42, label %43, label %21
43: ; preds = %21, %15
%44 = phi double [ undef, %15 ], [ %39, %21 ]
%45 = phi i64 [ 0, %15 ], [ %40, %21 ]
%46 = phi double [ %12, %15 ], [ %39, %21 ]
%47 = icmp eq i64 %17, 0
br i1 %47, label %56, label %48
48: ; preds = %43
%49 = getelementptr inbounds double, double* %6, i64 %45
%50 = load double, double* %49
%51 = fmul double %5, %50
%52 = getelementptr inbounds double, double* %2, i64 %45
%53 = load double, double* %52
%54 = fmul double %53, %53
%55 = tail call double @llvm.fmuladd.f64(double %51, double %54, double %46)
br label %56
56: ; preds = %48, %43, %3
%57 = phi double [ %12, %3 ], [ %44, %43 ], [ %55, %48 ]
%58 = sext i32 %14 to i64
%59 = getelementptr inbounds double, double* %6, i64 %58
%60 = load double, double* %59
%61 = fmul double %60, 2.300000e+01
%62 = getelementptr inbounds double, double* %2, i64 %58
%63 = load double, double* %62
%64 = fmul double %63, %63
%65 = add nsw i32 %0, -1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %6, i64 %66
%68 = load double, double* %67
%69 = fmul double %68, 2.800000e+01
%70 = getelementptr inbounds double, double* %2, i64 %66
%71 = load double, double* %70
%72 = fmul double %71, %71
%73 = fmul double %69, %72
%74 = tail call double @llvm.fmuladd.f64(double %61, double %64, double %73)
%75 = sext i32 %0 to i64
%76 = getelementptr inbounds double, double* %6, i64 %75
%77 = load double, double* %76
%78 = fmul double %77, 9.000000e+00
%79 = getelementptr inbounds double, double* %2, i64 %75
%80 = load double, double* %79
%81 = fmul double %80, %80
%82 = tail call double @llvm.fmuladd.f64(double %78, double %81, double %74)
%83 = fmul double %5, %82
%84 = fdiv double %83, 2.400000e+01
%85 = fadd double %57, %84
ret double %85
}