#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*/ assert(int);
int ti_apo_start(double const *);
int ti_apo(int size, double const *const *inputs, double const *options,
           double *const *outputs) {
  const double *input = inputs[0];
  double *apo = outputs[0];
  const int short_period = (int)options[0];
  const int long_period = (int)options[1];
  if (short_period < 1)
    return 1;
  if (long_period < 2)
    return 1;
  if (long_period < short_period)
    return 1;
  if (size <= ti_apo_start(options))
    return 0;
  double short_per = 2 / ((double)short_period + 1);
  double long_per = 2 / ((double)long_period + 1);
  double short_ema = input[0];
  double long_ema = input[0];
  int i;
  for (i = 1; i < size; ++i) {
    short_ema = (input[i] - short_ema) * short_per + short_ema;
    long_ema = (input[i] - long_ema) * long_per + long_ema;
    const double out = short_ema - long_ema;
    *apo++ = out;
  }
  assert(apo - outputs[0] == size - ti_apo_start(options));
  return 0;
}


x86 assembly (clang, -O0):
<ti_apo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
cvttsd2si (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
cvttsd2si 0x8(%rax),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x1,-0x34(%rbp)
jge    117d <ti_apo+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    1315 <ti_apo+0x1f5>
cmpl   $0x2,-0x38(%rbp)
jge    1193 <ti_apo+0x73>
movl   $0x1,-0x4(%rbp)
jmp    1315 <ti_apo+0x1f5>
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11ab <ti_apo+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    1315 <ti_apo+0x1f5>
mov    -0x8(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ti_apo_start@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jg     11d3 <ti_apo+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    1315 <ti_apo+0x1f5>
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  0xe28(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe14(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdl -0x38(%rbp),%xmm1
movsd  0xe06(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xdf2(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12cb <ti_apo+0x1ab>
mov    -0x28(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x58(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x30(%rbp)
movsd  %xmm0,(%rax)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1238 <ti_apo+0x118>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ti_apo_start@plt>
mov    -0x7c(%rbp),%ecx
mov    %eax,%edx
mov    -0x78(%rbp),%rax
sub    %edx,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ti_apo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movupd (%rdx),%xmm0
cvttpd2dq %xmm0,%xmm2
movdqa 0xec2(%rip),%xmm0
pcmpgtd %xmm2,%xmm0
pshufd $0x50,%xmm0,%xmm0
movmskpd %xmm0,%eax
mov    $0x1,%r14d
test   $0x1,%al
jne    12ac <ti_apo+0x18c>
shr    %al
jne    12ac <ti_apo+0x18c>
pshufd $0x55,%xmm2,%xmm0
movdqa %xmm2,%xmm1
pcmpgtd %xmm0,%xmm1
movd   %xmm1,%eax
test   $0x1,%al
jne    12ac <ti_apo+0x18c>
mov    %rcx,%r15
mov    %rdx,%r13
mov    %edi,%r12d
movaps %xmm2,(%rsp)
mov    (%rsi),%rbx
mov    (%rcx),%rbp
mov    %rdx,%rdi
call   1030 <ti_apo_start@plt>
xor    %r14d,%r14d
cmp    %r12d,%eax
jge    12ac <ti_apo+0x18c>
cmp    $0x2,%r12d
jl     1289 <ti_apo+0x169>
cvtdq2pd (%rsp),%xmm1
addpd  0xe58(%rip),%xmm1
movapd 0xe60(%rip),%xmm0
divpd  %xmm1,%xmm0
mov    %r12d,%eax
movsd  (%rbx),%xmm1
unpcklpd %xmm1,%xmm1
add    $0xffffffffffffffff,%rax
cmp    $0x2,%r12d
jne    11e0 <ti_apo+0xc0>
mov    $0x1,%ecx
jmp    125b <ti_apo+0x13b>
mov    %rax,%rdx
and    $0xfffffffffffffffe,%rdx
neg    %rdx
mov    $0x1,%ecx
nop
movsd  (%rbx,%rcx,8),%xmm2
unpcklpd %xmm2,%xmm2
subpd  %xmm1,%xmm2
mulpd  %xmm0,%xmm2
addpd  %xmm1,%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
movapd %xmm2,%xmm3
subsd  %xmm1,%xmm3
movsd  %xmm3,0x0(%rbp)
movsd  0x8(%rbx,%rcx,8),%xmm1
unpcklpd %xmm1,%xmm1
subpd  %xmm2,%xmm1
mulpd  %xmm0,%xmm1
addpd  %xmm2,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
movapd %xmm1,%xmm3
subsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rbp)
add    $0x10,%rbp
lea    (%rdx,%rcx,1),%rsi
add    $0x2,%rsi
add    $0x2,%rcx
cmp    $0x1,%rsi
jne    11f0 <ti_apo+0xd0>
test   $0x1,%al
je     1289 <ti_apo+0x169>
movsd  (%rbx,%rcx,8),%xmm2
unpcklpd %xmm2,%xmm2
subpd  %xmm1,%xmm2
mulpd  %xmm0,%xmm2
addpd  %xmm1,%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
subsd  %xmm0,%xmm2
movsd  %xmm2,0x0(%rbp)
add    $0x8,%rbp
sub    (%r15),%rbp
sar    $0x3,%rbp
mov    %r13,%rdi
call   1030 <ti_apo_start@plt>
sub    %eax,%r12d
movslq %r12d,%rax
xor    %edi,%edi
cmp    %rax,%rbp
sete   %dil
call   1040 <assert@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ti_apo(i32 %0, double** %1, double* %2, double** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double**
%8 = alloca double*
%9 = alloca double**
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca double
store i32 %0, i32* %6
store double** %1, double*** %7
store double* %2, double** %8
store double** %3, double*** %9
%20 = load double**, double*** %7
%21 = getelementptr inbounds double*, double** %20, i64 0
%22 = load double*, double** %21
store double* %22, double** %10
%23 = load double**, double*** %9
%24 = getelementptr inbounds double*, double** %23, i64 0
%25 = load double*, double** %24
store double* %25, double** %11
%26 = load double*, double** %8
%27 = getelementptr inbounds double, double* %26, i64 0
%28 = load double, double* %27
%29 = fptosi double %28 to i32
store i32 %29, i32* %12
%30 = load double*, double** %8
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
%33 = fptosi double %32 to i32
store i32 %33, i32* %13
%34 = load i32, i32* %12
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %4
store i32 1, i32* %5
br label %118
37: ; preds = %4
%38 = load i32, i32* %13
%39 = icmp slt i32 %38, 2
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 1, i32* %5
br label %118
41: ; preds = %37
%42 = load i32, i32* %13
%43 = load i32, i32* %12
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 1, i32* %5
br label %118
46: ; preds = %41
%47 = load i32, i32* %6
%48 = load double*, double** %8
%49 = call i32 @ti_apo_start(double* %48)
%50 = icmp sle i32 %47, %49
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 0, i32* %5
br label %118
52: ; preds = %46
%53 = load i32, i32* %12
%54 = sitofp i32 %53 to double
%55 = fadd double %54, 1.000000e+00
%56 = fdiv double 2.000000e+00, %55
store double %56, double* %14
%57 = load i32, i32* %13
%58 = sitofp i32 %57 to double
%59 = fadd double %58, 1.000000e+00
%60 = fdiv double 2.000000e+00, %59
store double %60, double* %15
%61 = load double*, double** %10
%62 = getelementptr inbounds double, double* %61, i64 0
%63 = load double, double* %62
store double %63, double* %16
%64 = load double*, double** %10
%65 = getelementptr inbounds double, double* %64, i64 0
%66 = load double, double* %65
store double %66, double* %17
store i32 1, i32* %18
br label %67
67: ; preds = %98, %52
%68 = load i32, i32* %18
%69 = load i32, i32* %6
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %101
71: ; preds = %67
%72 = load double*, double** %10
%73 = load i32, i32* %18
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
%76 = load double, double* %75
%77 = load double, double* %16
%78 = fsub double %76, %77
%79 = load double, double* %14
%80 = load double, double* %16
%81 = call double @llvm.fmuladd.f64(double %78, double %79, double %80)
store double %81, double* %16
%82 = load double*, double** %10
%83 = load i32, i32* %18
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = load double, double* %17
%88 = fsub double %86, %87
%89 = load double, double* %15
%90 = load double, double* %17
%91 = call double @llvm.fmuladd.f64(double %88, double %89, double %90)
store double %91, double* %17
%92 = load double, double* %16
%93 = load double, double* %17
%94 = fsub double %92, %93
store double %94, double* %19
%95 = load double, double* %19
%96 = load double*, double** %11
%97 = getelementptr inbounds double, double* %96, i32 1
store double* %97, double** %11
store double %95, double* %96
br label %98
98: ; preds = %71
%99 = load i32, i32* %18
%100 = add nsw i32 %99, 1
store i32 %100, i32* %18
br label %67
101: ; preds = %67
%102 = load double*, double** %11
%103 = load double**, double*** %9
%104 = getelementptr inbounds double*, double** %103, i64 0
%105 = load double*, double** %104
%106 = ptrtoint double* %102 to i64
%107 = ptrtoint double* %105 to i64
%108 = sub i64 %106, %107
%109 = sdiv exact i64 %108, 8
%110 = load i32, i32* %6
%111 = load double*, double** %8
%112 = call i32 @ti_apo_start(double* %111)
%113 = sub nsw i32 %110, %112
%114 = sext i32 %113 to i64
%115 = icmp eq i64 %109, %114
%116 = zext i1 %115 to i32
%117 = call i32 @assert(i32 %116)
store i32 0, i32* %5
br label %118
118: ; preds = %101, %51, %45, %40, %36
%119 = load i32, i32* %5
ret i32 %119
}

LLVM IR (-O2):
define i32 @ti_apo(i32 %0, double** nocapture %1, double* %2, double** nocapture %3) {
%5 = load double*, double** %1
%6 = load double*, double** %3
%7 = bitcast double* %2 to <2 x double>*
%8 = load <2 x double>, <2 x double>* %7
%9 = fptosi <2 x double> %8 to <2 x i32>
%10 = icmp slt <2 x i32> %9, <i32 1, i32 2>
%11 = extractelement <2 x i1> %10, i64 0
%12 = extractelement <2 x i1> %10, i64 1
%13 = select i1 %11, i1 true, i1 %12
%14 = shufflevector <2 x i32> %9, <2 x i32> poison, <2 x i32> <i32 1, i32 undef>
%15 = icmp slt <2 x i32> %14, %9
%16 = extractelement <2 x i1> %15, i64 0
%17 = select i1 %13, i1 true, i1 %16
br i1 %17, label %95, label %18
18: ; preds = %4
%19 = tail call i32 @ti_apo_start(double* %2)
%20 = icmp slt i32 %19, %0
br i1 %20, label %21, label %95
21: ; preds = %18
%22 = sitofp <2 x i32> %9 to <2 x double>
%23 = fadd <2 x double> %22, <double 1.000000e+00, double 1.000000e+00>
%24 = fdiv <2 x double> <double 2.000000e+00, double 2.000000e+00>, %23
%25 = icmp sgt i32 %0, 1
br i1 %25, label %26, label %82
26: ; preds = %21
%27 = load double, double* %5
%28 = zext i32 %0 to i64
%29 = insertelement <2 x double> poison, double %27, i64 0
%30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
%31 = add nsw i64 %28, -1
%32 = and i64 %31, 1
%33 = icmp eq i32 %0, 2
br i1 %33, label %65, label %34
34: ; preds = %26
%35 = and i64 %31, -2
br label %36
36: ; preds = %36, %34
%37 = phi i64 [ 1, %34 ], [ %62, %36 ]
%38 = phi double* [ %6, %34 ], [ %61, %36 ]
%39 = phi <2 x double> [ %30, %34 ], [ %57, %36 ]
%40 = phi i64 [ 0, %34 ], [ %63, %36 ]
%41 = getelementptr inbounds double, double* %5, i64 %37
%42 = load double, double* %41
%43 = insertelement <2 x double> poison, double %42, i64 0
%44 = shufflevector <2 x double> %43, <2 x double> poison, <2 x i32> zeroinitializer
%45 = fsub <2 x double> %44, %39
%46 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %45, <2 x double> %24, <2 x double> %39)
%47 = shufflevector <2 x double> %46, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%48 = fsub <2 x double> %46, %47
%49 = extractelement <2 x double> %48, i64 0
%50 = getelementptr inbounds double, double* %38, i64 1
store double %49, double* %38
%51 = add nuw nsw i64 %37, 1
%52 = getelementptr inbounds double, double* %5, i64 %51
%53 = load double, double* %52
%54 = insertelement <2 x double> poison, double %53, i64 0
%55 = shufflevector <2 x double> %54, <2 x double> poison, <2 x i32> zeroinitializer
%56 = fsub <2 x double> %55, %46
%57 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %56, <2 x double> %24, <2 x double> %46)
%58 = shufflevector <2 x double> %57, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%59 = fsub <2 x double> %57, %58
%60 = extractelement <2 x double> %59, i64 0
%61 = getelementptr inbounds double, double* %38, i64 2
store double %60, double* %50
%62 = add nuw nsw i64 %37, 2
%63 = add i64 %40, 2
%64 = icmp eq i64 %63, %35
br i1 %64, label %65, label %36
65: ; preds = %36, %26
%66 = phi double* [ undef, %26 ], [ %61, %36 ]
%67 = phi i64 [ 1, %26 ], [ %62, %36 ]
%68 = phi double* [ %6, %26 ], [ %61, %36 ]
%69 = phi <2 x double> [ %30, %26 ], [ %57, %36 ]
%70 = icmp eq i64 %32, 0
br i1 %70, label %82, label %71
71: ; preds = %65
%72 = getelementptr inbounds double, double* %5, i64 %67
%73 = load double, double* %72
%74 = insertelement <2 x double> poison, double %73, i64 0
%75 = shufflevector <2 x double> %74, <2 x double> poison, <2 x i32> zeroinitializer
%76 = fsub <2 x double> %75, %69
%77 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %76, <2 x double> %24, <2 x double> %69)
%78 = shufflevector <2 x double> %77, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%79 = fsub <2 x double> %77, %78
%80 = extractelement <2 x double> %79, i64 0
%81 = getelementptr inbounds double, double* %68, i64 1
store double %80, double* %68
br label %82
82: ; preds = %71, %65, %21
%83 = phi double* [ %6, %21 ], [ %66, %65 ], [ %81, %71 ]
%84 = load double*, double** %3
%85 = ptrtoint double* %83 to i64
%86 = ptrtoint double* %84 to i64
%87 = sub i64 %85, %86
%88 = ashr exact i64 %87, 3
%89 = tail call i32 @ti_apo_start(double* %2)
%90 = sub nsw i32 %0, %89
%91 = sext i32 %90 to i64
%92 = icmp eq i64 %88, %91
%93 = zext i1 %92 to i32
%94 = tail call i32 @assert(i32 %93)
br label %95
95: ; preds = %18, %4, %82
%96 = phi i32 [ 0, %82 ], [ 1, %4 ], [ 0, %18 ]
ret i32 %96
}