#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 */
scalar_t__ abs(scalar_t__);
scalar_t__ sgn(double);
double zcross(double *x, const int fl, const int n) {
  int i;
  double z = 0;
  for (i = 0; i < fl; i++)
    z += abs(sgn(x[i + 1]) - sgn(x[i]));
  if (n)
    z /= fl;
  return (z);
}


x86 assembly (clang, -O0):
<zcross>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a3 <zcross+0x83>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sgn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <sgn@plt>
mov    -0x28(%rbp),%rdi
sub    %rax,%rdi
call   1030 <abs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <zcross+0x21>
cmpl   $0x0,-0x10(%rbp)
je     11c0 <zcross+0xa0>
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zcross>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0xc(%rsp)
mov    %esi,%r15d
test   %esi,%esi
jle    11ae <zcross+0x9e>
mov    %rdi,%r13
mov    %r15d,%r12d
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
lea    0x1(%rbp),%r14
movsd  0x8(%r13,%rbp,8),%xmm0
call   1030 <sgn@plt>
mov    %rax,%rbx
movsd  0x0(%r13,%rbp,8),%xmm0
call   1030 <sgn@plt>
movsd  0x10(%rsp),%xmm0
sub    %rax,%rbx
mov    %rbx,%rax
neg    %rax
cmovs  %rbx,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
mov    %r14,%rbp
cmp    %r14,%r12
jne    1140 <zcross+0x30>
cmpl   $0x0,0xc(%rsp)
je     119f <zcross+0x8f>
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
divsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xorpd  %xmm0,%xmm0
cmpl   $0x0,0xc(%rsp)
jne    1193 <zcross+0x83>
jmp    119f <zcross+0x8f>

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

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