#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 */
int /*<<< orphan*/ assert(int);
double math_vector_dot_product(const double *vec_i, const double *vec_j,
                               size_t size) {
  assert(vec_i && vec_j);
  double product = 0.0;
  for (size_t i = 0; i != size; ++i) {
    product += vec_i[i] * vec_j[i];
  }
  return product;
}


x86 assembly (clang, -O0):
<math_vector_dot_product>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
je     113f <math_vector_dot_product+0x2f>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11a7 <math_vector_dot_product+0x97>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115c <math_vector_dot_product+0x4c>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<math_vector_dot_product>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
test   %r15,%r15
je     1151 <math_vector_dot_product+0x41>
lea    -0x1(%r15),%rcx
mov    %r15d,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    115a <math_vector_dot_product+0x4a>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
jmp    11bb <math_vector_dot_product+0xab>
xorpd  %xmm0,%xmm0
jmp    11e7 <math_vector_dot_product+0xd7>
and    $0xfffffffffffffffc,%r15
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%rbx,%rcx,8),%xmm1
movsd  0x8(%rbx,%rcx,8),%xmm2
mulsd  (%r14,%rcx,8),%xmm1
mulsd  0x8(%r14,%rcx,8),%xmm2
addsd  %xmm0,%xmm1
movsd  0x10(%rbx,%rcx,8),%xmm3
mulsd  0x10(%r14,%rcx,8),%xmm3
addsd  %xmm1,%xmm2
movsd  0x18(%rbx,%rcx,8),%xmm0
mulsd  0x18(%r14,%rcx,8),%xmm0
addsd  %xmm2,%xmm3
addsd  %xmm3,%xmm0
add    $0x4,%rcx
cmp    %rcx,%r15
jne    1170 <math_vector_dot_product+0x60>
test   %rax,%rax
je     11e7 <math_vector_dot_product+0xd7>
lea    (%r14,%rcx,8),%rdx
lea    (%rbx,%rcx,8),%rcx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
movsd  (%rcx,%rsi,8),%xmm1
mulsd  (%rdx,%rsi,8),%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rsi
cmp    %rsi,%rax
jne    11d0 <math_vector_dot_product+0xc0>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @math_vector_dot_product(double* %0, double* %1, i64 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i64
%7 = alloca double
%8 = alloca i64
store double* %0, double** %4
store double* %1, double** %5
store i64 %2, i64* %6
%9 = load double*, double** %4
%10 = icmp ne double* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load double*, double** %5
%13 = icmp ne double* %12, null
br label %14
14: ; preds = %11, %3
%15 = phi i1 [ false, %3 ], [ %13, %11 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store double 0.000000e+00, double* %7
store i64 0, i64* %8
br label %18
18: ; preds = %33, %14
%19 = load i64, i64* %8
%20 = load i64, i64* %6
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load double*, double** %4
%24 = load i64, i64* %8
%25 = getelementptr inbounds double, double* %23, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %5
%28 = load i64, i64* %8
%29 = getelementptr inbounds double, double* %27, i64 %28
%30 = load double, double* %29
%31 = load double, double* %7
%32 = call double @llvm.fmuladd.f64(double %26, double %30, double %31)
store double %32, double* %7
br label %33
33: ; preds = %22
%34 = load i64, i64* %8
%35 = add i64 %34, 1
store i64 %35, i64* %8
br label %18
36: ; preds = %18
%37 = load double, double* %7
ret double %37
}

LLVM IR (-O2):
define double @math_vector_dot_product(double* %0, double* %1, i64 %2) {
%4 = icmp ne double* %0, null
%5 = icmp ne double* %1, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp eq i64 %2, 0
br i1 %9, label %33, label %10
10: ; preds = %3
%11 = add i64 %2, -1
%12 = and i64 %2, 3
%13 = icmp ult i64 %11, 3
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = and i64 %2, -4
br label %35
16: ; preds = %35, %10
%17 = phi double [ undef, %10 ], [ %61, %35 ]
%18 = phi i64 [ 0, %10 ], [ %62, %35 ]
%19 = phi double [ 0.000000e+00, %10 ], [ %61, %35 ]
%20 = icmp eq i64 %12, 0
br i1 %20, label %33, label %21
21: ; preds = %16, %21
%22 = phi i64 [ %30, %21 ], [ %18, %16 ]
%23 = phi double [ %29, %21 ], [ %19, %16 ]
%24 = phi i64 [ %31, %21 ], [ 0, %16 ]
%25 = getelementptr inbounds double, double* %0, i64 %22
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %1, i64 %22
%28 = load double, double* %27
%29 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %23)
%30 = add nuw i64 %22, 1
%31 = add i64 %24, 1
%32 = icmp eq i64 %31, %12
br i1 %32, label %33, label %21
33: ; preds = %16, %21, %3
%34 = phi double [ 0.000000e+00, %3 ], [ %17, %16 ], [ %29, %21 ]
ret double %34
35: ; preds = %35, %14
%36 = phi i64 [ 0, %14 ], [ %62, %35 ]
%37 = phi double [ 0.000000e+00, %14 ], [ %61, %35 ]
%38 = phi i64 [ 0, %14 ], [ %63, %35 ]
%39 = getelementptr inbounds double, double* %0, i64 %36
%40 = load double, double* %39
%41 = getelementptr inbounds double, double* %1, i64 %36
%42 = load double, double* %41
%43 = tail call double @llvm.fmuladd.f64(double %40, double %42, double %37)
%44 = or i64 %36, 1
%45 = getelementptr inbounds double, double* %0, i64 %44
%46 = load double, double* %45
%47 = getelementptr inbounds double, double* %1, i64 %44
%48 = load double, double* %47
%49 = tail call double @llvm.fmuladd.f64(double %46, double %48, double %43)
%50 = or i64 %36, 2
%51 = getelementptr inbounds double, double* %0, i64 %50
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %1, i64 %50
%54 = load double, double* %53
%55 = tail call double @llvm.fmuladd.f64(double %52, double %54, double %49)
%56 = or i64 %36, 3
%57 = getelementptr inbounds double, double* %0, i64 %56
%58 = load double, double* %57
%59 = getelementptr inbounds double, double* %1, i64 %56
%60 = load double, double* %59
%61 = tail call double @llvm.fmuladd.f64(double %58, double %60, double %55)
%62 = add nuw i64 %36, 4
%63 = add i64 %38, 4
%64 = icmp eq i64 %63, %15
br i1 %64, label %16, label %35
}