#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);
int /*<<< orphan*/ utilVectorAdd(float *, float *, unsigned int);
int /*<<< orphan*/ utilVectorDevideByScalar(float *, unsigned int,
                                            unsigned int);
int /*<<< orphan*/ utilVectorSetByScalar(float *, int /*<<< orphan*/,
                                         unsigned int);
void vectorAverageComputeAverage(float **window, unsigned int numelements,
                                 float *average) {
  unsigned int total = 30;
  utilVectorSetByScalar(average, 0, numelements * 2);
  for (size_t i = 0; i < 30; i++) {
    if (window[i])
      utilVectorAdd(average, window[i], numelements * 2);
    else
      total--;
  }
  assert(total != 0);
  utilVectorDevideByScalar(average, total, numelements * 2);
}


x86 assembly (clang, -O0):
<vectorAverageComputeAverage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1e,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
shl    $0x1,%edx
xor    %esi,%esi
call   1050 <utilVectorSetByScalar@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x1e,-0x28(%rbp)
jae    11d0 <vectorAverageComputeAverage+0x90>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11b1 <vectorAverageComputeAverage+0x71>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0xc(%rbp),%edx
shl    $0x1,%edx
call   1040 <utilVectorAdd@plt>
jmp    11ba <vectorAverageComputeAverage+0x7a>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bf <vectorAverageComputeAverage+0x7f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1173 <vectorAverageComputeAverage+0x33>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
shl    $0x1,%edx
call   1030 <utilVectorDevideByScalar@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vectorAverageComputeAverage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
add    %esi,%r15d
xor    %ebp,%ebp
mov    %rdx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <utilVectorSetByScalar@plt>
mov    $0x1e,%r12d
jmp    117e <vectorAverageComputeAverage+0x3e>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r12d
add    $0x1,%rbp
cmp    $0x1e,%rbp
je     1194 <vectorAverageComputeAverage+0x54>
mov    (%rbx,%rbp,8),%rsi
test   %rsi,%rsi
je     1170 <vectorAverageComputeAverage+0x30>
mov    %r14,%rdi
mov    %r15d,%edx
call   1040 <utilVectorAdd@plt>
jmp    1174 <vectorAverageComputeAverage+0x34>
xor    %edi,%edi
test   %r12d,%r12d
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <utilVectorDevideByScalar@plt>

LLVM IR (-O0):
define void @vectorAverageComputeAverage(float** %0, i32 %1, float* %2) {
%4 = alloca float**
%5 = alloca i32
%6 = alloca float*
%7 = alloca i32
%8 = alloca i64
store float** %0, float*** %4
store i32 %1, i32* %5
store float* %2, float** %6
store i32 30, i32* %7
%9 = load float*, float** %6
%10 = load i32, i32* %5
%11 = mul i32 %10, 2
%12 = call i32 @utilVectorSetByScalar(float* %9, i32 0, i32 %11)
store i64 0, i64* %8
br label %13
13: ; preds = %35, %3
%14 = load i64, i64* %8
%15 = icmp ult i64 %14, 30
br i1 %15, label %16, label %38
16: ; preds = %13
%17 = load float**, float*** %4
%18 = load i64, i64* %8
%19 = getelementptr inbounds float*, float** %17, i64 %18
%20 = load float*, float** %19
%21 = icmp ne float* %20, null
br i1 %21, label %22, label %31
22: ; preds = %16
%23 = load float*, float** %6
%24 = load float**, float*** %4
%25 = load i64, i64* %8
%26 = getelementptr inbounds float*, float** %24, i64 %25
%27 = load float*, float** %26
%28 = load i32, i32* %5
%29 = mul i32 %28, 2
%30 = call i32 @utilVectorAdd(float* %23, float* %27, i32 %29)
br label %34
31: ; preds = %16
%32 = load i32, i32* %7
%33 = add i32 %32, -1
store i32 %33, i32* %7
br label %34
34: ; preds = %31, %22
br label %35
35: ; preds = %34
%36 = load i64, i64* %8
%37 = add i64 %36, 1
store i64 %37, i64* %8
br label %13
38: ; preds = %13
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load float*, float** %6
%44 = load i32, i32* %7
%45 = load i32, i32* %5
%46 = mul i32 %45, 2
%47 = call i32 @utilVectorDevideByScalar(float* %43, i32 %44, i32 %46)
ret void
}

LLVM IR (-O2):
define void @vectorAverageComputeAverage(float** nocapture %0, i32 %1, float* %2) {
%4 = shl i32 %1, 1
%5 = tail call i32 @utilVectorSetByScalar(float* %2, i32 0, i32 %4)
br label %11
6: ; preds = %21
%7 = icmp ne i32 %22, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @utilVectorDevideByScalar(float* %2, i32 %22, i32 %4)
ret void
11: ; preds = %3, %21
%12 = phi i64 [ 0, %3 ], [ %23, %21 ]
%13 = phi i32 [ 30, %3 ], [ %22, %21 ]
%14 = getelementptr inbounds float*, float** %0, i64 %12
%15 = load float*, float** %14
%16 = icmp eq float* %15, null
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @utilVectorAdd(float* %2, float* %15, i32 %4)
br label %21
19: ; preds = %11
%20 = add i32 %13, -1
br label %21
21: ; preds = %17, %19
%22 = phi i32 [ %13, %17 ], [ %20, %19 ]
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, 30
br i1 %24, label %6, label %11
}