#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 /*<<< orphan*/ detrend_endpt(double *, int, double *, double *, double *);
int /*<<< orphan*/ detrend_lsq(double *, int, double *, double *, double *);
void detrend(double *source, int n, double *dest, int type, double *slope,
             double *intercept) {
  if (n < 2) {
    *slope = 0.0f;
    *intercept = source[0];
    return;
  }
  switch (type) {
  case 2:
    detrend_endpt(source, n, dest, slope, intercept);
    break;
  case 1:
    detrend_lsq(source, n, dest, slope, intercept);
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<detrend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1168 <detrend+0x48>
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    11c7 <detrend+0xa7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1,%eax
je     11aa <detrend+0x8a>
jmp    117c <detrend+0x5c>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
jne    11c2 <detrend+0xa2>
jmp    118d <detrend+0x6d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <detrend_endpt@plt>
jmp    11c7 <detrend+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1030 <detrend_lsq@plt>
jmp    11c7 <detrend+0xa7>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detrend>:
cmp    $0x1,%esi
jg     1137 <detrend+0x17>
movq   $0x0,(%r8)
movsd  (%rdi),%xmm0
movsd  %xmm0,(%r9)
jmp    114c <detrend+0x2c>
cmp    $0x1,%ecx
je     114d <detrend+0x2d>
cmp    $0x2,%ecx
jne    114c <detrend+0x2c>
mov    %r8,%rcx
mov    %r9,%r8
jmp    1040 <detrend_endpt@plt>
ret
mov    %r8,%rcx
mov    %r9,%r8
jmp    1030 <detrend_lsq@plt>

LLVM IR (-O0):
define void @detrend(double* %0, i32 %1, double* %2, i32 %3, double* %4, double* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
store double* %0, double** %7
store i32 %1, i32* %8
store double* %2, double** %9
store i32 %3, i32* %10
store double* %4, double** %11
store double* %5, double** %12
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %6
%16 = load double*, double** %11
store double 0.000000e+00, double* %16
%17 = load double*, double** %7
%18 = getelementptr inbounds double, double* %17, i64 0
%19 = load double, double* %18
%20 = load double*, double** %12
store double %19, double* %20
br label %38
21: ; preds = %6
%22 = load i32, i32* %10
switch i32 %22, label %37 [
i32 2, label %23
i32 1, label %30
]
23: ; preds = %21
%24 = load double*, double** %7
%25 = load i32, i32* %8
%26 = load double*, double** %9
%27 = load double*, double** %11
%28 = load double*, double** %12
%29 = call i32 @detrend_endpt(double* %24, i32 %25, double* %26, double* %27, double* %28)
br label %38
30: ; preds = %21
%31 = load double*, double** %7
%32 = load i32, i32* %8
%33 = load double*, double** %9
%34 = load double*, double** %11
%35 = load double*, double** %12
%36 = call i32 @detrend_lsq(double* %31, i32 %32, double* %33, double* %34, double* %35)
br label %37
37: ; preds = %21, %30
br label %38
38: ; preds = %15, %37, %23
ret void
}

LLVM IR (-O2):
define void @detrend(double* %0, i32 %1, double* %2, i32 %3, double* %4, double* %5) {
%7 = icmp slt i32 %1, 2
br i1 %7, label %8, label %10
8: ; preds = %6
store double 0.000000e+00, double* %4
%9 = load double, double* %0
store double %9, double* %5
br label %15
10: ; preds = %6
switch i32 %3, label %15 [
i32 2, label %11
i32 1, label %13
]
11: ; preds = %10
%12 = tail call i32 @detrend_endpt(double* %0, i32 %1, double* %2, double* %4, double* %5)
br label %15
13: ; preds = %10
%14 = tail call i32 @detrend_lsq(double* %0, i32 %1, double* %2, double* %4, double* %5)
br label %15
15: ; preds = %13, %10, %8, %11
ret void
}