#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 */
double pr(double *, double, int, double);
int npeaks(double *pars, double d_max, int n_c, int nslice) {
  double r;
  double value;
  int i;
  double previous = 0.0;
  double slope = 0.0;
  int count = 0;
  for (i = 0; i < nslice; i++) {
    r = d_max / (1.0 * nslice) * i;
    value = pr(pars, d_max, n_c, r);
    if (previous <= value) {
      slope = 1;
    } else {
      if (slope > 0)
        count += 1;
      slope = -1;
    }
    previous = value;
  }
  return count;
}


x86 assembly (clang, -O0):
<npeaks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fa <npeaks+0xea>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm2
movsd  0xe9d(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm1
call   1030 <pr@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11ba <npeaks+0xaa>
movsd  0xe50(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11e2 <npeaks+0xd2>
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d5 <npeaks+0xc5>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movsd  0xe2b(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1145 <npeaks+0x35>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<npeaks>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,0x8(%rsp)
test   %edx,%edx
jle    11cb <npeaks+0xbb>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xor    %ebp,%ebp
lea    0xeae(%rip),%r12
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
xorpd  %xmm2,%xmm2
xchg   %ax,%ax
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm2,0x28(%rsp)
movsd  0x10(%rsp),%xmm1
mulsd  %xmm2,%xmm1
mov    %r15,%rdi
movsd  0x8(%rsp),%xmm0
mov    %r14d,%esi
call   1030 <pr@plt>
movsd  0x28(%rsp),%xmm2
xor    %eax,%eax
ucomisd 0x18(%rsp),%xmm0
setb   %al
movsd  0x20(%rsp),%xmm1
ucomisd 0xe6c(%rip),%xmm1
seta   %cl
movsd  (%r12,%rax,8),%xmm1
and    %cl,%al
movzbl %al,%eax
add    %eax,%ebp
addsd  0xe4c(%rip),%xmm2
add    $0xffffffff,%ebx
jne    1160 <npeaks+0x50>
jmp    11cd <npeaks+0xbd>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @npeaks(double* %0, double %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double* %0, double** %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %14
store i32 0, i32* %11
br label %15
15: ; preds = %46, %4
%16 = load i32, i32* %11
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %49
19: ; preds = %15
%20 = load double, double* %6
%21 = load i32, i32* %8
%22 = sitofp i32 %21 to double
%23 = fmul double 1.000000e+00, %22
%24 = fdiv double %20, %23
%25 = load i32, i32* %11
%26 = sitofp i32 %25 to double
%27 = fmul double %24, %26
store double %27, double* %9
%28 = load double*, double** %5
%29 = load double, double* %6
%30 = load i32, i32* %7
%31 = load double, double* %9
%32 = call double @pr(double* %28, double %29, i32 %30, double %31)
store double %32, double* %10
%33 = load double, double* %12
%34 = load double, double* %10
%35 = fcmp ole double %33, %34
br i1 %35, label %36, label %37
36: ; preds = %19
store double 1.000000e+00, double* %13
br label %44
37: ; preds = %19
%38 = load double, double* %13
%39 = fcmp ogt double %38, 0.000000e+00
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* %14
%42 = add nsw i32 %41, 1
store i32 %42, i32* %14
br label %43
43: ; preds = %40, %37
store double -1.000000e+00, double* %13
br label %44
44: ; preds = %43, %36
%45 = load double, double* %10
store double %45, double* %12
br label %46
46: ; preds = %44
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
br label %15
49: ; preds = %15
%50 = load i32, i32* %14
ret i32 %50
}

LLVM IR (-O2):
define i32 @npeaks(double* %0, double %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %25
6: ; preds = %4
%7 = sitofp i32 %3 to double
%8 = fdiv double %1, %7
br label %9
9: ; preds = %6, %9
%10 = phi i32 [ 0, %6 ], [ %22, %9 ]
%11 = phi double [ 0.000000e+00, %6 ], [ %19, %9 ]
%12 = phi double [ 0.000000e+00, %6 ], [ %16, %9 ]
%13 = phi i32 [ 0, %6 ], [ %23, %9 ]
%14 = sitofp i32 %13 to double
%15 = fmul double %8, %14
%16 = tail call double @pr(double* %0, double %1, i32 %2, double %15)
%17 = fcmp ugt double %12, %16
%18 = fcmp ogt double %11, 0.000000e+00
%19 = select i1 %17, double -1.000000e+00, double 1.000000e+00
%20 = select i1 %17, i1 %18, i1 false
%21 = zext i1 %20 to i32
%22 = add nuw nsw i32 %10, %21
%23 = add nuw nsw i32 %13, 1
%24 = icmp eq i32 %23, %3
br i1 %24, label %25, label %9
25: ; preds = %9, %4
%26 = phi i32 [ 0, %4 ], [ %22, %9 ]
ret i32 %26
}