#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 abs(scalar_t__);
scalar_t__ sgn(double);
double llz_zrc(double *buf, int frame_len) {
  int i;
  int zrc_cnt;
  zrc_cnt = 0;
  for (i = 1; i < frame_len; i++)
    zrc_cnt += abs(sgn(buf[i]) - sgn(buf[i - 1])) / 2;
  return (double)zrc_cnt / frame_len;
}


x86 assembly (clang, -O0):
<llz_zrc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <llz_zrc+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sgn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sgn@plt>
mov    -0x20(%rbp),%rdi
sub    %rax,%rdi
call   1030 <abs@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <llz_zrc+0x1d>
cvtsi2sdl -0x14(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llz_zrc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
xorpd  %xmm0,%xmm0
cmp    $0x2,%esi
jl     1192 <llz_zrc+0x72>
mov    %rdi,%r12
mov    %r14d,%r15d
xor    %r13d,%r13d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  (%r12,%rbx,8),%xmm0
call   1040 <sgn@plt>
mov    %rax,%rbp
movsd  -0x8(%r12,%rbx,8),%xmm0
call   1040 <sgn@plt>
sub    %rax,%rbp
mov    %rbp,%rdi
call   1030 <abs@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
add    %ecx,%r13d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <llz_zrc+0x30>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @llz_zrc(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 1, i32* %5
br label %7
7: ; preds = %30, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %33
11: ; preds = %7
%12 = load double*, double** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %12, i64 %14
%16 = load double, double* %15
%17 = call i64 @sgn(double %16)
%18 = load double*, double** %3
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %18, i64 %21
%23 = load double, double* %22
%24 = call i64 @sgn(double %23)
%25 = sub nsw i64 %17, %24
%26 = call i32 @abs(i64 %25)
%27 = sdiv i32 %26, 2
%28 = load i32, i32* %6
%29 = add nsw i32 %28, %27
store i32 %29, i32* %6
br label %30
30: ; preds = %11
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %7
33: ; preds = %7
%34 = load i32, i32* %6
%35 = sitofp i32 %34 to double
%36 = load i32, i32* %4
%37 = sitofp i32 %36 to double
%38 = fdiv double %35, %37
ret double %38
}

LLVM IR (-O2):
define double @llz_zrc(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %24
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 1, %4 ], [ %20, %6 ]
%8 = phi i32 [ 0, %4 ], [ %19, %6 ]
%9 = getelementptr inbounds double, double* %0, i64 %7
%10 = load double, double* %9
%11 = tail call i64 @sgn(double %10)
%12 = add nsw i64 %7, -1
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = tail call i64 @sgn(double %14)
%16 = sub nsw i64 %11, %15
%17 = tail call i32 @abs(i64 %16)
%18 = sdiv i32 %17, 2
%19 = add nsw i32 %18, %8
%20 = add nuw nsw i64 %7, 1
%21 = icmp eq i64 %20, %5
br i1 %21, label %22, label %6
22: ; preds = %6
%23 = sitofp i32 %19 to double
br label %24
24: ; preds = %22, %2
%25 = phi double [ 0.000000e+00, %2 ], [ %23, %22 ]
%26 = sitofp i32 %1 to double
%27 = fdiv double %25, %26
ret double %27
}