#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__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ vlog(double *, double *, int);
int /*<<< orphan*/ vsp(double *, double *, double, int);
double vldot(double *x, double *y, int n) {
  double *z, ans;
  double tiny = 1.0e-19;
  int i;
  if ((z = (double *)calloc((n), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", n);
  vsp(z, y, 1.0e-20, n);
  vlog(z, z, n);
  ans = 0.0;
  for (i = 0; i < n; i++) {
    if (x[i] > tiny)
      ans += x[i] * z[i];
  }
  free(z);
  return ans;
}


x86 assembly (clang, -O0):
<vldot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  0xe95(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119a <vldot+0x4a>
mov    -0x14(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1050 <fatalx@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
movsd  0xe5b(%rip),%xmm0
call   1040 <vsp@plt>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <vlog@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1234 <vldot+0xe4>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1221 <vldot+0xd1>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1226 <vldot+0xd6>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d1 <vldot+0x81>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vldot>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %edx,%edi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1181 <vldot+0x31>
lea    0xe96(%rip),%rdi
mov    %ebp,%esi
call   1050 <fatalx@plt>
movsd  0xe77(%rip),%xmm0
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <vsp@plt>
mov    %r14,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <vlog@plt>
test   %ebp,%ebp
jle    11e2 <vldot+0x92>
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    1203 <vldot+0xb3>
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
movsd  %xmm2,(%rsp)
test   $0x1,%al
je     11eb <vldot+0x9b>
movsd  (%rbx,%rcx,8),%xmm0
ucomisd 0xe3e(%rip),%xmm0
jbe    11eb <vldot+0x9b>
mulsd  (%r14,%rcx,8),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
jmp    11eb <vldot+0x9b>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm2,%xmm2
xor    %ecx,%ecx
movsd  0xdf2(%rip),%xmm0
jmp    1229 <vldot+0xd9>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rcx
cmp    %rcx,%rdx
je     11b4 <vldot+0x64>
movsd  (%rbx,%rcx,8),%xmm1
ucomisd %xmm0,%xmm1
jbe    123e <vldot+0xee>
mulsd  (%r14,%rcx,8),%xmm1
addsd  %xmm1,%xmm2
movsd  0x8(%rbx,%rcx,8),%xmm1
ucomisd %xmm0,%xmm1
jbe    1220 <vldot+0xd0>
mulsd  0x8(%r14,%rcx,8),%xmm1
addsd  %xmm1,%xmm2
jmp    1220 <vldot+0xd0>

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @vldot(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0x3BFD83C94FB6D2AC, double* %9
%11 = load i32, i32* %6
%12 = call i64 @calloc(i32 %11, i32 8)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %7
%14 = icmp eq double* %13, null
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* %6
%17 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %3
%19 = load double*, double** %7
%20 = load double*, double** %5
%21 = load i32, i32* %6
%22 = call i32 @vsp(double* %19, double* %20, double 0x3BC79CA10C924223, i32 %21)
%23 = load double*, double** %7
%24 = load double*, double** %7
%25 = load i32, i32* %6
%26 = call i32 @vlog(double* %23, double* %24, i32 %25)
store double 0.000000e+00, double* %8
store i32 0, i32* %10
br label %27
27: ; preds = %53, %18
%28 = load i32, i32* %10
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %56
31: ; preds = %27
%32 = load double*, double** %4
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double, double* %9
%38 = fcmp ogt double %36, %37
br i1 %38, label %39, label %52
39: ; preds = %31
%40 = load double*, double** %4
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %7
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = load double, double* %8
%51 = call double @llvm.fmuladd.f64(double %44, double %49, double %50)
store double %51, double* %8
br label %52
52: ; preds = %39, %31
br label %53
53: ; preds = %52
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %27
56: ; preds = %27
%57 = load double*, double** %7
%58 = call i32 @free(double* %57)
%59 = load double, double* %8
ret double %59
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define double @vldot(double* nocapture %0, double* %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %2, i32 8)
%5 = inttoptr i64 %4 to double*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @vsp(double* %5, double* %1, double 0x3BC79CA10C924223, i32 %2)
%11 = tail call i32 @vlog(double* %5, double* %5, i32 %2)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %58
13: ; preds = %9
%14 = zext i32 %2 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %2, 1
br i1 %16, label %45, label %17
17: ; preds = %13
%18 = and i64 %14, 4294967294
br label %19
19: ; preds = %40, %17
%20 = phi i64 [ 0, %17 ], [ %42, %40 ]
%21 = phi double [ 0.000000e+00, %17 ], [ %41, %40 ]
%22 = phi i64 [ 0, %17 ], [ %43, %40 ]
%23 = getelementptr inbounds double, double* %0, i64 %20
%24 = load double, double* %23
%25 = fcmp ogt double %24, 0x3BFD83C94FB6D2AC
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = getelementptr inbounds double, double* %5, i64 %20
%28 = load double, double* %27
%29 = tail call double @llvm.fmuladd.f64(double %24, double %28, double %21)
br label %30
30: ; preds = %19, %26
%31 = phi double [ %29, %26 ], [ %21, %19 ]
%32 = or i64 %20, 1
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = fcmp ogt double %34, 0x3BFD83C94FB6D2AC
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = getelementptr inbounds double, double* %5, i64 %32
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %34, double %38, double %31)
br label %40
40: ; preds = %36, %30
%41 = phi double [ %39, %36 ], [ %31, %30 ]
%42 = add nuw nsw i64 %20, 2
%43 = add i64 %22, 2
%44 = icmp eq i64 %43, %18
br i1 %44, label %45, label %19
45: ; preds = %40, %13
%46 = phi double [ undef, %13 ], [ %41, %40 ]
%47 = phi i64 [ 0, %13 ], [ %42, %40 ]
%48 = phi double [ 0.000000e+00, %13 ], [ %41, %40 ]
%49 = icmp eq i64 %15, 0
br i1 %49, label %58, label %50
50: ; preds = %45
%51 = getelementptr inbounds double, double* %0, i64 %47
%52 = load double, double* %51
%53 = fcmp ogt double %52, 0x3BFD83C94FB6D2AC
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = getelementptr inbounds double, double* %5, i64 %47
%56 = load double, double* %55
%57 = tail call double @llvm.fmuladd.f64(double %52, double %56, double %48)
br label %58
58: ; preds = %45, %54, %50, %9
%59 = phi double [ 0.000000e+00, %9 ], [ %46, %45 ], [ %57, %54 ], [ %48, %50 ]
%60 = tail call i32 @free(double* %5)
ret double %59
}