#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 sqrt(float);
scalar_t__ square(short);
float find_sq_eng(short *speech, int x_start, int len) {
  int i;
  float total = 0.0;
  for (i = 0; i < len; i++)
    total += square(speech[x_start + i]);
  total = total / len;
  total = sqrt(total);
  return (total);
}


x86 assembly (clang, -O0):
<find_sq_eng>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1180 <find_sq_eng+0x60>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movswl (%rax,%rcx,2),%edi
call   1030 <square@plt>
cvtsi2ss %rax,%xmm0
addss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <find_sq_eng+0x21>
movss  -0x18(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
call   1040 <sqrt@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_sq_eng>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
xorps  %xmm0,%xmm0
test   %edx,%edx
jle    116b <find_sq_eng+0x4b>
movslq %esi,%rax
mov    %r14d,%r15d
lea    (%rdi,%rax,2),%rbp
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
movss  %xmm0,0x4(%rsp)
movswl 0x0(%rbp,%rbx,2),%edi
call   1030 <square@plt>
movss  0x4(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
addss  %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <find_sq_eng+0x20>
xorps  %xmm1,%xmm1
cvtsi2ss %r14d,%xmm1
divss  %xmm1,%xmm0
ucomiss 0xe82(%rip),%xmm0
jb     118f <find_sq_eng+0x6f>
sqrtss %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define float @find_sq_eng(i16* %0, i32 %1, i32 %2) {
%4 = alloca i16*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
store i16* %0, i16** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store float 0.000000e+00, float* %8
store i32 0, i32* %7
br label %9
9: ; preds = %25, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i16*, i16** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = add nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i16, i16* %14, i64 %18
%20 = load i16, i16* %19
%21 = call i64 @square(i16 signext %20)
%22 = sitofp i64 %21 to float
%23 = load float, float* %8
%24 = fadd float %23, %22
store float %24, float* %8
br label %25
25: ; preds = %13
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %9
28: ; preds = %9
%29 = load float, float* %8
%30 = load i32, i32* %6
%31 = sitofp i32 %30 to float
%32 = fdiv float %29, %31
store float %32, float* %8
%33 = load float, float* %8
%34 = call float @sqrt(float %33)
store float %34, float* %8
%35 = load float, float* %8
ret float %35
}

LLVM IR (-O2):
define float @find_sq_eng(i16* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %19
5: ; preds = %3
%6 = sext i32 %1 to i64
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %17, %8 ]
%10 = phi float [ 0.000000e+00, %5 ], [ %16, %8 ]
%11 = add nsw i64 %9, %6
%12 = getelementptr inbounds i16, i16* %0, i64 %11
%13 = load i16, i16* %12
%14 = tail call i64 @square(i16 signext %13)
%15 = sitofp i64 %14 to float
%16 = fadd float %10, %15
%17 = add nuw nsw i64 %9, 1
%18 = icmp eq i64 %17, %7
br i1 %18, label %19, label %8
19: ; preds = %8, %3
%20 = phi float [ 0.000000e+00, %3 ], [ %16, %8 ]
%21 = sitofp i32 %2 to float
%22 = fdiv float %20, %21
%23 = tail call float @sqrt(float %22)
ret float %23
}