#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 dot_product(double *, double *, int);
double proj_coeff(double v1[], double v2[], int n) {
  double coeff = 0.0;
  int i;
  double temp1, temp2;
  for (i = 0; i < n; i++) {
    temp1 = dot_product(v1, v2, n);
    temp2 = dot_product(v2, v2, n);
    coeff = temp1 / temp2;
  }
  return coeff;
}


x86 assembly (clang, -O0):
<proj_coeff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    1185 <proj_coeff+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <dot_product@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <dot_product@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1132 <proj_coeff+0x22>
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proj_coeff>:
test   %edx,%edx
jle    116e <proj_coeff+0x5e>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <dot_product@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <dot_product@plt>
add    $0xffffffff,%ebp
jne    1130 <proj_coeff+0x20>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @proj_coeff(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
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 %11
11: ; preds = %27, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load double*, double** %4
%17 = load double*, double** %5
%18 = load i32, i32* %6
%19 = call double @dot_product(double* %16, double* %17, i32 %18)
store double %19, double* %9
%20 = load double*, double** %5
%21 = load double*, double** %5
%22 = load i32, i32* %6
%23 = call double @dot_product(double* %20, double* %21, i32 %22)
store double %23, double* %10
%24 = load double, double* %9
%25 = load double, double* %10
%26 = fdiv double %24, %25
store double %26, double* %7
br label %27
27: ; preds = %15
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %11
30: ; preds = %11
%31 = load double, double* %7
ret double %31
}

LLVM IR (-O2):
define double @proj_coeff(double* %0, double* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %13
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ 0, %3 ]
%7 = tail call double @dot_product(double* %0, double* %1, i32 %2)
%8 = tail call double @dot_product(double* %1, double* %1, i32 %2)
%9 = add nuw nsw i32 %6, 1
%10 = icmp eq i32 %9, %2
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = fdiv double %7, %8
br label %13
13: ; preds = %11, %3
%14 = phi double [ %12, %11 ], [ 0.000000e+00, %3 ]
ret double %14
}