#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_ppo_start(double const *);
int ti_ppo(int size, double const *const *inputs, double const *options,
           double *const *outputs) {
  const double *input = inputs[0];
  double *ppo = 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_ppo_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 = 100.0 * (short_ema - long_ema) / long_ema;
    *ppo++ = out;
  }
  assert(ppo - outputs[0] == size - ti_ppo_start(options));
  return 0;
}


x86 assembly (clang, -O0):
<ti_ppo>:
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_ppo+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    1326 <ti_ppo+0x206>
cmpl   $0x2,-0x38(%rbp)
jge    1193 <ti_ppo+0x73>
movl   $0x1,-0x4(%rbp)
jmp    1326 <ti_ppo+0x206>
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11ab <ti_ppo+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    1326 <ti_ppo+0x206>
mov    -0x8(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ti_ppo_start@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
cmp    %ecx,%eax
jg     11d3 <ti_ppo+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    1326 <ti_ppo+0x206>
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    12dc <ti_ppo+0x1bc>
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),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  0xd68(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -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_ppo+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   1040 <ti_ppo_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   1030 <assert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ti_ppo>:
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    1243 <ti_ppo+0x123>
shr    %al
jne    1243 <ti_ppo+0x123>
pshufd $0x55,%xmm2,%xmm0
movdqa %xmm2,%xmm1
pcmpgtd %xmm0,%xmm1
movd   %xmm1,%eax
test   $0x1,%al
jne    1243 <ti_ppo+0x123>
mov    %rcx,%r15
mov    %rdx,%r13
mov    %edi,%r12d
movaps %xmm2,(%rsp)
mov    (%rsi),%rbx
mov    (%rcx),%rbp
mov    %rdx,%rdi
call   1040 <ti_ppo_start@plt>
xor    %r14d,%r14d
cmp    %r12d,%eax
jge    1243 <ti_ppo+0x123>
cmp    $0x2,%r12d
jl     1220 <ti_ppo+0x100>
cvtdq2pd (%rsp),%xmm1
addpd  0xe5c(%rip),%xmm1
movapd 0xe64(%rip),%xmm0
divpd  %xmm1,%xmm0
mov    %r12d,%eax
movsd  (%rbx),%xmm1
unpcklpd %xmm1,%xmm1
lea    -0x8(,%rax,8),%rcx
ff
xor    %eax,%eax
movsd  0xe53(%rip),%xmm2
nopl   (%rax)
movsd  0x8(%rbx,%rax,1),%xmm3
unpcklpd %xmm3,%xmm3
subpd  %xmm1,%xmm3
mulpd  %xmm0,%xmm3
addpd  %xmm3,%xmm1
movapd %xmm1,%xmm3
unpckhpd %xmm1,%xmm3
movapd %xmm1,%xmm4
subsd  %xmm3,%xmm4
mulsd  %xmm2,%xmm4
divsd  %xmm3,%xmm4
movsd  %xmm4,0x0(%rbp,%rax,1)
add    $0x8,%rax
cmp    %rax,%rcx
jne    11e0 <ti_ppo+0xc0>
add    %rax,%rbp
sub    (%r15),%rbp
sar    $0x3,%rbp
mov    %r13,%rdi
call   1040 <ti_ppo_start@plt>
sub    %eax,%r12d
movslq %r12d,%rax
xor    %edi,%edi
cmp    %rax,%rbp
sete   %dil
call   1030 <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_ppo(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 %121
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 %121
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 %121
46: ; preds = %41
%47 = load i32, i32* %6
%48 = load double*, double** %8
%49 = call i32 @ti_ppo_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 %121
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 = %101, %52
%68 = load i32, i32* %18
%69 = load i32, i32* %6
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %104
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
%95 = fmul double 1.000000e+02, %94
%96 = load double, double* %17
%97 = fdiv double %95, %96
store double %97, double* %19
%98 = load double, double* %19
%99 = load double*, double** %11
%100 = getelementptr inbounds double, double* %99, i32 1
store double* %100, double** %11
store double %98, double* %99
br label %101
101: ; preds = %71
%102 = load i32, i32* %18
%103 = add nsw i32 %102, 1
store i32 %103, i32* %18
br label %67
104: ; preds = %67
%105 = load double*, double** %11
%106 = load double**, double*** %9
%107 = getelementptr inbounds double*, double** %106, i64 0
%108 = load double*, double** %107
%109 = ptrtoint double* %105 to i64
%110 = ptrtoint double* %108 to i64
%111 = sub i64 %109, %110
%112 = sdiv exact i64 %111, 8
%113 = load i32, i32* %6
%114 = load double*, double** %8
%115 = call i32 @ti_ppo_start(double* %114)
%116 = sub nsw i32 %113, %115
%117 = sext i32 %116 to i64
%118 = icmp eq i64 %112, %117
%119 = zext i1 %118 to i32
%120 = call i32 @assert(i32 %119)
store i32 0, i32* %5
br label %121
121: ; preds = %104, %51, %45, %40, %36
%122 = load i32, i32* %5
ret i32 %122
}

LLVM IR (-O2):
define i32 @ti_ppo(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 %62, label %18
18: ; preds = %4
%19 = tail call i32 @ti_ppo_start(double* %2)
%20 = icmp slt i32 %19, %0
br i1 %20, label %21, label %62
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 %49
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
br label %31
31: ; preds = %26, %31
%32 = phi i64 [ 1, %26 ], [ %47, %31 ]
%33 = phi double* [ %6, %26 ], [ %46, %31 ]
%34 = phi <2 x double> [ %30, %26 ], [ %40, %31 ]
%35 = getelementptr inbounds double, double* %5, i64 %32
%36 = load double, double* %35
%37 = insertelement <2 x double> poison, double %36, i64 0
%38 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> zeroinitializer
%39 = fsub <2 x double> %38, %34
%40 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %39, <2 x double> %24, <2 x double> %34)
%41 = extractelement <2 x double> %40, i64 0
%42 = extractelement <2 x double> %40, i64 1
%43 = fsub double %41, %42
%44 = fmul double %43, 1.000000e+02
%45 = fdiv double %44, %42
%46 = getelementptr inbounds double, double* %33, i64 1
store double %45, double* %33
%47 = add nuw nsw i64 %32, 1
%48 = icmp eq i64 %47, %28
br i1 %48, label %49, label %31
49: ; preds = %31, %21
%50 = phi double* [ %6, %21 ], [ %46, %31 ]
%51 = load double*, double** %3
%52 = ptrtoint double* %50 to i64
%53 = ptrtoint double* %51 to i64
%54 = sub i64 %52, %53
%55 = ashr exact i64 %54, 3
%56 = tail call i32 @ti_ppo_start(double* %2)
%57 = sub nsw i32 %0, %56
%58 = sext i32 %57 to i64
%59 = icmp eq i64 %55, %58
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
br label %62
62: ; preds = %18, %4, %49
%63 = phi i32 [ 0, %49 ], [ 1, %4 ], [ 0, %18 ]
ret i32 %63
}