#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 */
float myTrapz(float *, int /*<<< orphan*/, unsigned int);
float sqrt(float);
int /*<<< orphan*/ vectorMult(float *, float *, unsigned int);
int /*<<< orphan*/ vectorPow(float *, unsigned int);
void powerFactor(float *t, float *V, float *I, unsigned int size, float *fp,
                 float *S, float *P, float *Vrms, float *Irms) {
  float fp_t = 0, S_t = 0, P_t = 0, Vrms_t = 0, Irms_t = 0;
  float T = t[size - 1] - t[0];
  P_t = myTrapz(t, vectorMult(V, I, size), size) / T;
  Vrms_t = sqrt(myTrapz(t, vectorPow(V, size), size) / T);
  Irms_t = sqrt(myTrapz(t, vectorPow(I, size), size) / T);
  S_t = Vrms_t * Irms_t;
  fp_t = P_t / S_t;
  *fp = fp_t;
  *S = S_t;
  *P = P_t;
  *Vrms = Vrms_t;
  *Irms = Irms_t;
}


x86 assembly (clang, -O0):
<powerFactor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movss  (%rax,%rcx,4),%xmm0
mov    -0x8(%rbp),%rax
subss  (%rax),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <vectorMult@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1040 <myTrapz@plt>
divss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <vectorPow@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1040 <myTrapz@plt>
divss  -0x48(%rbp),%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <vectorPow@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1040 <myTrapz@plt>
divss  -0x48(%rbp),%xmm0
call   1060 <sqrt@plt>
movss  %xmm0,-0x44(%rbp)
movss  -0x40(%rbp),%xmm0
mulss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x3c(%rbp),%xmm0
divss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x38(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x3c(%rbp),%xmm0
mov    0x10(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x40(%rbp),%xmm0
mov    0x18(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x44(%rbp),%xmm0
mov    0x20(%rbp),%rax
movss  %xmm0,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<powerFactor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%ebx
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r12
lea    -0x1(%rbx),%eax
movss  (%rdi,%rax,4),%xmm0
subss  (%rdi),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1050 <vectorMult@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <myTrapz@plt>
movss  %xmm0,0x10(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
call   1030 <vectorPow@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <myTrapz@plt>
divss  0xc(%rsp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11ba <powerFactor+0x7a>
sqrtss %xmm0,%xmm0
jmp    11bf <powerFactor+0x7f>
call   1060 <sqrt@plt>
movss  %xmm0,0x14(%rsp)
mov    0x50(%rsp),%rbp
movss  0x10(%rsp),%xmm0
divss  0xc(%rsp),%xmm0
movss  %xmm0,0x10(%rsp)
mov    %r13,%rdi
mov    %ebx,%esi
call   1030 <vectorPow@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <myTrapz@plt>
divss  0xc(%rsp),%xmm0
ucomiss 0xe01(%rip),%xmm0
jb     1207 <powerFactor+0xc7>
sqrtss %xmm0,%xmm0
jmp    120c <powerFactor+0xcc>
call   1060 <sqrt@plt>
movss  0x14(%rsp),%xmm4
movaps %xmm4,%xmm1
mulss  %xmm0,%xmm1
movss  0x10(%rsp),%xmm3
movaps %xmm3,%xmm2
divss  %xmm1,%xmm2
movss  %xmm2,(%r15)
movss  %xmm1,(%r14)
movss  %xmm3,0x0(%rbp)
mov    0x58(%rsp),%rax
movss  %xmm4,(%rax)
mov    0x60(%rsp),%rax
movss  %xmm0,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @powerFactor(float* %0, float* %1, float* %2, i32 %3, float* %4, float* %5, float* %6, float* %7, float* %8) {
%10 = alloca float*
%11 = alloca float*
%12 = alloca float*
%13 = alloca i32
%14 = alloca float*
%15 = alloca float*
%16 = alloca float*
%17 = alloca float*
%18 = alloca float*
%19 = alloca float
%20 = alloca float
%21 = alloca float
%22 = alloca float
%23 = alloca float
%24 = alloca float
store float* %0, float** %10
store float* %1, float** %11
store float* %2, float** %12
store i32 %3, i32* %13
store float* %4, float** %14
store float* %5, float** %15
store float* %6, float** %16
store float* %7, float** %17
store float* %8, float** %18
store float 0.000000e+00, float* %19
store float 0.000000e+00, float* %20
store float 0.000000e+00, float* %21
store float 0.000000e+00, float* %22
store float 0.000000e+00, float* %23
%25 = load float*, float** %10
%26 = load i32, i32* %13
%27 = sub i32 %26, 1
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds float, float* %25, i64 %28
%30 = load float, float* %29
%31 = load float*, float** %10
%32 = getelementptr inbounds float, float* %31, i64 0
%33 = load float, float* %32
%34 = fsub float %30, %33
store float %34, float* %24
%35 = load float*, float** %10
%36 = load float*, float** %11
%37 = load float*, float** %12
%38 = load i32, i32* %13
%39 = call i32 @vectorMult(float* %36, float* %37, i32 %38)
%40 = load i32, i32* %13
%41 = call float @myTrapz(float* %35, i32 %39, i32 %40)
%42 = load float, float* %24
%43 = fdiv float %41, %42
store float %43, float* %21
%44 = load float*, float** %10
%45 = load float*, float** %11
%46 = load i32, i32* %13
%47 = call i32 @vectorPow(float* %45, i32 %46)
%48 = load i32, i32* %13
%49 = call float @myTrapz(float* %44, i32 %47, i32 %48)
%50 = load float, float* %24
%51 = fdiv float %49, %50
%52 = call float @sqrt(float %51)
store float %52, float* %22
%53 = load float*, float** %10
%54 = load float*, float** %12
%55 = load i32, i32* %13
%56 = call i32 @vectorPow(float* %54, i32 %55)
%57 = load i32, i32* %13
%58 = call float @myTrapz(float* %53, i32 %56, i32 %57)
%59 = load float, float* %24
%60 = fdiv float %58, %59
%61 = call float @sqrt(float %60)
store float %61, float* %23
%62 = load float, float* %22
%63 = load float, float* %23
%64 = fmul float %62, %63
store float %64, float* %20
%65 = load float, float* %21
%66 = load float, float* %20
%67 = fdiv float %65, %66
store float %67, float* %19
%68 = load float, float* %19
%69 = load float*, float** %14
store float %68, float* %69
%70 = load float, float* %20
%71 = load float*, float** %15
store float %70, float* %71
%72 = load float, float* %21
%73 = load float*, float** %16
store float %72, float* %73
%74 = load float, float* %22
%75 = load float*, float** %17
store float %74, float* %75
%76 = load float, float* %23
%77 = load float*, float** %18
store float %76, float* %77
ret void
}

LLVM IR (-O2):
define void @powerFactor(float* %0, float* %1, float* %2, i32 %3, float* nocapture writeonly %4, float* nocapture writeonly %5, float* nocapture writeonly %6, float* nocapture writeonly %7, float* nocapture writeonly %8) {
%10 = add i32 %3, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds float, float* %0, i64 %11
%13 = load float, float* %12
%14 = load float, float* %0
%15 = fsub float %13, %14
%16 = tail call i32 @vectorMult(float* %1, float* %2, i32 %3)
%17 = tail call float @myTrapz(float* %0, i32 %16, i32 %3)
%18 = fdiv float %17, %15
%19 = tail call i32 @vectorPow(float* %1, i32 %3)
%20 = tail call float @myTrapz(float* %0, i32 %19, i32 %3)
%21 = fdiv float %20, %15
%22 = tail call float @sqrt(float %21)
%23 = tail call i32 @vectorPow(float* %2, i32 %3)
%24 = tail call float @myTrapz(float* %0, i32 %23, i32 %3)
%25 = fdiv float %24, %15
%26 = tail call float @sqrt(float %25)
%27 = fmul float %22, %26
%28 = fdiv float %18, %27
store float %28, float* %4
store float %27, float* %5
store float %18, float* %6
store float %22, float* %7
store float %26, float* %8
ret void
}