#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 log(double);
int dot_score(double *cvec, double *pvec, int veclen) {
  int i;
  double score = 0.0;
  for (i = 0; i < veclen; i++, cvec++, pvec++)
    if (*pvec > 0.0)
      score += *cvec * log(*pvec);
  return ((int)1000.0 * score);
}


x86 assembly (clang, -O0):
<dot_score>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b2 <dot_score+0xa2>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1187 <dot_score+0x77>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    118c <dot_score+0x7c>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1132 <dot_score+0x22>
movsd  0xe46(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dot_score>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    1182 <dot_score+0x72>
mov    %rsi,%r15
mov    %rdi,%r14
mov    %edx,%r12d
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
jmp    1149 <dot_score+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %ebx,%r12d
je     1186 <dot_score+0x76>
movsd  (%r15,%rbx,8),%xmm0
ucomisd %xmm2,%xmm0
jbe    1140 <dot_score+0x30>
movsd  (%r14,%rbx,8),%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
call   1030 <log@plt>
xorpd  %xmm2,%xmm2
movsd  0x10(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm1
jmp    1140 <dot_score+0x30>
xorpd  %xmm1,%xmm1
mulsd  0xe72(%rip),%xmm1
cvttsd2si %xmm1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @dot_score(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store double 0.000000e+00, double* %8
store i32 0, i32* %7
br label %9
9: ; preds = %26, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = load double*, double** %5
%15 = load double, double* %14
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load double*, double** %4
%19 = load double, double* %18
%20 = load double*, double** %5
%21 = load double, double* %20
%22 = call double @log(double %21)
%23 = load double, double* %8
%24 = call double @llvm.fmuladd.f64(double %19, double %22, double %23)
store double %24, double* %8
br label %25
25: ; preds = %17, %13
br label %26
26: ; preds = %25
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
%29 = load double*, double** %4
%30 = getelementptr inbounds double, double* %29, i32 1
store double* %30, double** %4
%31 = load double*, double** %5
%32 = getelementptr inbounds double, double* %31, i32 1
store double* %32, double** %5
br label %9
33: ; preds = %9
%34 = load double, double* %8
%35 = fmul double 1.000000e+03, %34
%36 = fptosi double %35 to i32
ret i32 %36
}

LLVM IR (-O2):
define i32 @dot_score(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %3, %16
%6 = phi double [ %17, %16 ], [ 0.000000e+00, %3 ]
%7 = phi i32 [ %18, %16 ], [ 0, %3 ]
%8 = phi double* [ %19, %16 ], [ %0, %3 ]
%9 = phi double* [ %20, %16 ], [ %1, %3 ]
%10 = load double, double* %9
%11 = fcmp ogt double %10, 0.000000e+00
br i1 %11, label %12, label %16
12: ; preds = %5
%13 = load double, double* %8
%14 = tail call double @log(double %10)
%15 = tail call double @llvm.fmuladd.f64(double %13, double %14, double %6)
br label %16
16: ; preds = %5, %12
%17 = phi double [ %15, %12 ], [ %6, %5 ]
%18 = add nuw nsw i32 %7, 1
%19 = getelementptr inbounds double, double* %8, i64 1
%20 = getelementptr inbounds double, double* %9, i64 1
%21 = icmp eq i32 %18, %2
br i1 %21, label %22, label %5
22: ; preds = %16, %3
%23 = phi double [ 0.000000e+00, %3 ], [ %17, %16 ]
%24 = fmul double %23, 1.000000e+03
%25 = fptosi double %24 to i32
ret i32 %25
}