#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 pow(double, int);
double sqrt(double);
double weight(double *v_q, double *v_c) {
  int i;
  double w = 0, norm_q = 0, norm_c = 0;
  for (i = 0; i < 4; i++) {
    norm_q += pow(v_q[i], 2);
    norm_c += pow(v_c[i], 2);
  }
  norm_q = sqrt(norm_q);
  norm_c = sqrt(norm_c);
  for (i = 0; i < 4; i++)
    w += v_q[i] * v_c[i];
  w /= pow(norm_q, 4) * norm_c;
  return w;
}


x86 assembly (clang, -O0):
<weight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11a9 <weight+0x89>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <weight+0x2f>
movsd  -0x28(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1212 <weight+0xf2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ce <weight+0xae>
movsd  -0x28(%rbp),%xmm0
mov    $0x4,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weight>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0xea0(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rbx),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rbx),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x10(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rbx),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%r14),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x10(%rsp),%xmm1
addsd  0x8(%rsp),%xmm0
ucomisd 0xded(%rip),%xmm1
jb     1236 <weight+0x116>
sqrtsd %xmm1,%xmm3
ucomisd 0xddf(%rip),%xmm0
jae    1259 <weight+0x139>
movsd  %xmm3,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm3
jmp    125d <weight+0x13d>
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
call   1040 <sqrt@plt>
movapd %xmm0,%xmm3
movsd  0x8(%rsp),%xmm0
ucomisd 0xda9(%rip),%xmm0
jb     1223 <weight+0x103>
sqrtsd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
mulsd  (%r14),%xmm0
xorpd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
mulsd  0x8(%r14),%xmm1
addsd  %xmm2,%xmm1
movsd  0x10(%rbx),%xmm0
mulsd  0x10(%r14),%xmm0
addsd  %xmm1,%xmm0
movsd  0x18(%rbx),%xmm1
mulsd  0x18(%r14),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm3,%xmm0
mov    $0x4,%edi
call   1030 <pow@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @weight(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double* %0, double** %3
store double* %1, double** %4
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %5
br label %9
9: ; preds = %29, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load double*, double** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = call double @pow(double %17, i32 2)
%19 = load double, double* %7
%20 = fadd double %19, %18
store double %20, double* %7
%21 = load double*, double** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = call double @pow(double %25, i32 2)
%27 = load double, double* %8
%28 = fadd double %27, %26
store double %28, double* %8
br label %29
29: ; preds = %12
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %9
32: ; preds = %9
%33 = load double, double* %7
%34 = call double @sqrt(double %33)
store double %34, double* %7
%35 = load double, double* %8
%36 = call double @sqrt(double %35)
store double %36, double* %8
store i32 0, i32* %5
br label %37
37: ; preds = %53, %32
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 4
br i1 %39, label %40, label %56
40: ; preds = %37
%41 = load double*, double** %3
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = load double*, double** %4
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double, double* %6
%52 = call double @llvm.fmuladd.f64(double %45, double %50, double %51)
store double %52, double* %6
br label %53
53: ; preds = %40
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %37
56: ; preds = %37
%57 = load double, double* %7
%58 = call double @pow(double %57, i32 4)
%59 = load double, double* %8
%60 = fmul double %58, %59
%61 = load double, double* %6
%62 = fdiv double %61, %60
store double %62, double* %6
%63 = load double, double* %6
ret double %63
}

LLVM IR (-O2):
define double @weight(double* nocapture %0, double* nocapture %1) {
%3 = load double, double* %0
%4 = tail call double @pow(double %3, i32 2)
%5 = fadd double %4, 0.000000e+00
%6 = load double, double* %1
%7 = tail call double @pow(double %6, i32 2)
%8 = fadd double %7, 0.000000e+00
%9 = getelementptr inbounds double, double* %0, i64 1
%10 = load double, double* %9
%11 = tail call double @pow(double %10, i32 2)
%12 = fadd double %5, %11
%13 = getelementptr inbounds double, double* %1, i64 1
%14 = load double, double* %13
%15 = tail call double @pow(double %14, i32 2)
%16 = fadd double %8, %15
%17 = getelementptr inbounds double, double* %0, i64 2
%18 = load double, double* %17
%19 = tail call double @pow(double %18, i32 2)
%20 = fadd double %12, %19
%21 = getelementptr inbounds double, double* %1, i64 2
%22 = load double, double* %21
%23 = tail call double @pow(double %22, i32 2)
%24 = fadd double %16, %23
%25 = getelementptr inbounds double, double* %0, i64 3
%26 = load double, double* %25
%27 = tail call double @pow(double %26, i32 2)
%28 = fadd double %20, %27
%29 = getelementptr inbounds double, double* %1, i64 3
%30 = load double, double* %29
%31 = tail call double @pow(double %30, i32 2)
%32 = fadd double %24, %31
%33 = tail call double @sqrt(double %28)
%34 = tail call double @sqrt(double %32)
%35 = load double, double* %0
%36 = load double, double* %1
%37 = tail call double @llvm.fmuladd.f64(double %35, double %36, double 0.000000e+00)
%38 = load double, double* %9
%39 = load double, double* %13
%40 = tail call double @llvm.fmuladd.f64(double %38, double %39, double %37)
%41 = load double, double* %17
%42 = load double, double* %21
%43 = tail call double @llvm.fmuladd.f64(double %41, double %42, double %40)
%44 = load double, double* %25
%45 = load double, double* %29
%46 = tail call double @llvm.fmuladd.f64(double %44, double %45, double %43)
%47 = tail call double @pow(double %33, i32 4)
%48 = fmul double %34, %47
%49 = fdiv double %46, %48
ret double %49
}