#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 floatsumsquaredmask(float *in, unsigned char *mask, size_t size,
                          size_t *nsize) {
  size_t counter = 0;
  float *pt, *fpt;
  double sum = 0;
  fpt = in + size;
  pt = in;
  for (pt = in; pt < fpt; pt++)
    if (mask[pt - in] == 0) {
      sum += *pt * *pt;
      counter++;
    }
  *nsize = counter;
  return sum;
}


x86 assembly (clang, -O0):
<floatsumsquaredmask>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    11b5 <floatsumsquaredmask+0xb5>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
sar    $0x2,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    119f <floatsumsquaredmask+0x9f>
mov    -0x30(%rbp),%rax
movss  (%rax),%xmm0
mov    -0x30(%rbp),%rax
mulss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a4 <floatsumsquaredmask+0xa4>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    1147 <floatsumsquaredmask+0x47>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movsd  -0x40(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<floatsumsquaredmask>:
test   %rdx,%rdx
jle    1155 <floatsumsquaredmask+0x55>
lea    (%rdi,%rdx,4),%r9
xorpd  %xmm0,%xmm0
xor    %edx,%edx
xor    %r8d,%r8d
jmp    1131 <floatsumsquaredmask+0x31>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rdi,%rdx,1),%rax
add    $0x4,%rax
add    $0x4,%rdx
cmp    %r9,%rax
jae    115c <floatsumsquaredmask+0x5c>
mov    %rdx,%rax
sar    $0x2,%rax
cmpb   $0x0,(%rsi,%rax,1)
jne    1120 <floatsumsquaredmask+0x20>
movss  (%rdi,%rdx,1),%xmm1
mulss  %xmm1,%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%r8
jmp    1120 <floatsumsquaredmask+0x20>
xorpd  %xmm0,%xmm0
xor    %r8d,%r8d
mov    %r8,(%rcx)
cvtsd2ss %xmm0,%xmm0
ret

LLVM IR (-O0):
define float @floatsumsquaredmask(float* %0, i8* %1, i64 %2, i64* %3) {
%5 = alloca float*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i64
%10 = alloca float*
%11 = alloca float*
%12 = alloca double
store float* %0, float** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64* %3, i64** %8
store i64 0, i64* %9
store double 0.000000e+00, double* %12
%13 = load float*, float** %5
%14 = load i64, i64* %7
%15 = getelementptr inbounds float, float* %13, i64 %14
store float* %15, float** %11
%16 = load float*, float** %5
store float* %16, float** %10
%17 = load float*, float** %5
store float* %17, float** %10
br label %18
18: ; preds = %46, %4
%19 = load float*, float** %10
%20 = load float*, float** %11
%21 = icmp ult float* %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load i8*, i8** %6
%24 = load float*, float** %10
%25 = load float*, float** %5
%26 = ptrtoint float* %24 to i64
%27 = ptrtoint float* %25 to i64
%28 = sub i64 %26, %27
%29 = sdiv exact i64 %28, 4
%30 = getelementptr inbounds i8, i8* %23, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %22
%35 = load float*, float** %10
%36 = load float, float* %35
%37 = load float*, float** %10
%38 = load float, float* %37
%39 = fmul float %36, %38
%40 = fpext float %39 to double
%41 = load double, double* %12
%42 = fadd double %41, %40
store double %42, double* %12
%43 = load i64, i64* %9
%44 = add i64 %43, 1
store i64 %44, i64* %9
br label %45
45: ; preds = %34, %22
br label %46
46: ; preds = %45
%47 = load float*, float** %10
%48 = getelementptr inbounds float, float* %47, i32 1
store float* %48, float** %10
br label %18
49: ; preds = %18
%50 = load i64, i64* %9
%51 = load i64*, i64** %8
store i64 %50, i64* %51
%52 = load double, double* %12
%53 = fptrunc double %52 to float
ret float %53
}

LLVM IR (-O2):
define float @floatsumsquaredmask(float* %0, i8* nocapture %1, i64 %2, i64* nocapture writeonly %3) {
%5 = getelementptr inbounds float, float* %0, i64 %2
%6 = icmp sgt i64 %2, 0
br i1 %6, label %7, label %30
7: ; preds = %4
%8 = ptrtoint float* %0 to i64
br label %9
9: ; preds = %7, %25
%10 = phi double [ 0.000000e+00, %7 ], [ %27, %25 ]
%11 = phi i64 [ 0, %7 ], [ %26, %25 ]
%12 = phi float* [ %0, %7 ], [ %28, %25 ]
%13 = ptrtoint float* %12 to i64
%14 = sub i64 %13, %8
%15 = ashr exact i64 %14, 2
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %9
%20 = load float, float* %12
%21 = fmul float %20, %20
%22 = fpext float %21 to double
%23 = fadd double %10, %22
%24 = add i64 %11, 1
br label %25
25: ; preds = %9, %19
%26 = phi i64 [ %24, %19 ], [ %11, %9 ]
%27 = phi double [ %23, %19 ], [ %10, %9 ]
%28 = getelementptr inbounds float, float* %12, i64 1
%29 = icmp ult float* %28, %5
br i1 %29, label %9, label %30
30: ; preds = %25, %4
%31 = phi i64 [ 0, %4 ], [ %26, %25 ]
%32 = phi double [ 0.000000e+00, %4 ], [ %27, %25 ]
store i64 %31, i64* %3
%33 = fptrunc double %32 to float
ret float %33
}