#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_nvi_start(double const *);
int ti_nvi(int size, double const *const *inputs, double const *options,
           double *const *outputs) {
  const double *close = inputs[0];
  const double *volume = inputs[1];
  (void)options;
  double *output = outputs[0];
  if (size <= ti_nvi_start(options))
    return 0;
  double nvi = 1000;
  *output++ = nvi;
  int i;
  for (i = 1; i < size; ++i) {
    if (volume[i] < volume[i - 1]) {
      nvi += ((close[i] - close[i - 1]) / close[i - 1]) * nvi;
    }
    *output++ = nvi;
  }
  assert(output - outputs[0] == size - ti_nvi_start(options));
  return 0;
}


x86 assembly (clang, -O0):
<ti_nvi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ti_nvi_start@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cmp    %ecx,%eax
jg     1181 <ti_nvi+0x61>
movl   $0x0,-0x4(%rbp)
jmp    129a <ti_nvi+0x17a>
movsd  0xe77(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x38(%rbp)
movsd  %xmm0,(%rax)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1250 <ti_nvi+0x130>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x30(%rbp),%rax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    122a <ti_nvi+0x10a>
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x38(%rbp)
movsd  %xmm0,(%rax)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11ad <ti_nvi+0x8d>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ti_nvi_start@plt>
mov    -0x54(%rbp),%ecx
mov    %eax,%edx
mov    -0x50(%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    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ti_nvi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %edi,%r12d
mov    (%rsi),%r13
mov    0x8(%rsi),%rbp
mov    (%rcx),%rbx
mov    %rdx,%rdi
call   1040 <ti_nvi_start@plt>
cmp    %r12d,%eax
jge    11e8 <ti_nvi+0xc8>
movabs $0x408f400000000000,%rax
40 8f 40
mov    %rax,(%rbx)
cmp    $0x2,%r12d
jl     11bc <ti_nvi+0x9c>
mov    %r12d,%eax
shl    $0x3,%rax
movsd  0xe8f(%rip),%xmm0
mov    $0x8,%ecx
jmp    118e <ti_nvi+0x6e>
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rbx,%rcx,1)
add    $0x8,%rcx
cmp    %rcx,%rax
je     11c2 <ti_nvi+0xa2>
movsd  -0x8(%rbp,%rcx,1),%xmm1
ucomisd 0x0(%rbp,%rcx,1),%xmm1
jbe    1180 <ti_nvi+0x60>
movsd  -0x8(%r13,%rcx,1),%xmm1
movsd  0x0(%r13,%rcx,1),%xmm2
subsd  %xmm1,%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm0
jmp    1180 <ti_nvi+0x60>
add    $0x8,%rbx
jmp    11c5 <ti_nvi+0xa5>
add    %rcx,%rbx
sub    (%r15),%rbx
sar    $0x3,%rbx
mov    %r14,%rdi
call   1040 <ti_nvi_start@plt>
sub    %eax,%r12d
movslq %r12d,%rax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1030 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ti_nvi(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 double*
%13 = alloca double
%14 = alloca i32
store i32 %0, i32* %6
store double** %1, double*** %7
store double* %2, double** %8
store double** %3, double*** %9
%15 = load double**, double*** %7
%16 = getelementptr inbounds double*, double** %15, i64 0
%17 = load double*, double** %16
store double* %17, double** %10
%18 = load double**, double*** %7
%19 = getelementptr inbounds double*, double** %18, i64 1
%20 = load double*, double** %19
store double* %20, double** %11
%21 = load double*, double** %8
%22 = load double**, double*** %9
%23 = getelementptr inbounds double*, double** %22, i64 0
%24 = load double*, double** %23
store double* %24, double** %12
%25 = load i32, i32* %6
%26 = load double*, double** %8
%27 = call i32 @ti_nvi_start(double* %26)
%28 = icmp sle i32 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %4
store i32 0, i32* %5
br label %98
30: ; preds = %4
store double 1.000000e+03, double* %13
%31 = load double, double* %13
%32 = load double*, double** %12
%33 = getelementptr inbounds double, double* %32, i32 1
store double* %33, double** %12
store double %31, double* %32
store i32 1, i32* %14
br label %34
34: ; preds = %78, %30
%35 = load i32, i32* %14
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %81
38: ; preds = %34
%39 = load double*, double** %11
%40 = load i32, i32* %14
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double*, double** %11
%45 = load i32, i32* %14
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %44, i64 %47
%49 = load double, double* %48
%50 = fcmp olt double %43, %49
br i1 %50, label %51, label %74
51: ; preds = %38
%52 = load double*, double** %10
%53 = load i32, i32* %14
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %10
%58 = load i32, i32* %14
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %57, i64 %60
%62 = load double, double* %61
%63 = fsub double %56, %62
%64 = load double*, double** %10
%65 = load i32, i32* %14
%66 = sub nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %64, i64 %67
%69 = load double, double* %68
%70 = fdiv double %63, %69
%71 = load double, double* %13
%72 = load double, double* %13
%73 = call double @llvm.fmuladd.f64(double %70, double %71, double %72)
store double %73, double* %13
br label %74
74: ; preds = %51, %38
%75 = load double, double* %13
%76 = load double*, double** %12
%77 = getelementptr inbounds double, double* %76, i32 1
store double* %77, double** %12
store double %75, double* %76
br label %78
78: ; preds = %74
%79 = load i32, i32* %14
%80 = add nsw i32 %79, 1
store i32 %80, i32* %14
br label %34
81: ; preds = %34
%82 = load double*, double** %12
%83 = load double**, double*** %9
%84 = getelementptr inbounds double*, double** %83, i64 0
%85 = load double*, double** %84
%86 = ptrtoint double* %82 to i64
%87 = ptrtoint double* %85 to i64
%88 = sub i64 %86, %87
%89 = sdiv exact i64 %88, 8
%90 = load i32, i32* %6
%91 = load double*, double** %8
%92 = call i32 @ti_nvi_start(double* %91)
%93 = sub nsw i32 %90, %92
%94 = sext i32 %93 to i64
%95 = icmp eq i64 %89, %94
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
store i32 0, i32* %5
br label %98
98: ; preds = %81, %29
%99 = load i32, i32* %5
ret i32 %99
}

LLVM IR (-O2):
define i32 @ti_nvi(i32 %0, double** nocapture %1, double* %2, double** nocapture %3) {
%5 = load double*, double** %1
%6 = getelementptr inbounds double*, double** %1, i64 1
%7 = load double*, double** %6
%8 = load double*, double** %3
%9 = tail call i32 @ti_nvi_start(double* %2)
%10 = icmp slt i32 %9, %0
br i1 %10, label %11, label %52
11: ; preds = %4
store double 1.000000e+03, double* %8
%12 = getelementptr inbounds double, double* %8, i64 1
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %39
14: ; preds = %11
%15 = zext i32 %0 to i64
br label %16
16: ; preds = %14, %34
%17 = phi i64 [ 1, %14 ], [ %36, %34 ]
%18 = phi double* [ %12, %14 ], [ %37, %34 ]
%19 = phi double [ 1.000000e+03, %14 ], [ %35, %34 ]
%20 = getelementptr inbounds double, double* %7, i64 %17
%21 = load double, double* %20
%22 = add nsw i64 %17, -1
%23 = getelementptr inbounds double, double* %7, i64 %22
%24 = load double, double* %23
%25 = fcmp olt double %21, %24
br i1 %25, label %26, label %34
26: ; preds = %16
%27 = getelementptr inbounds double, double* %5, i64 %17
%28 = load double, double* %27
%29 = getelementptr inbounds double, double* %5, i64 %22
%30 = load double, double* %29
%31 = fsub double %28, %30
%32 = fdiv double %31, %30
%33 = tail call double @llvm.fmuladd.f64(double %32, double %19, double %19)
br label %34
34: ; preds = %26, %16
%35 = phi double [ %33, %26 ], [ %19, %16 ]
store double %35, double* %18
%36 = add nuw nsw i64 %17, 1
%37 = getelementptr inbounds double, double* %18, i64 1
%38 = icmp eq i64 %36, %15
br i1 %38, label %39, label %16
39: ; preds = %34, %11
%40 = phi double* [ %12, %11 ], [ %37, %34 ]
%41 = load double*, double** %3
%42 = ptrtoint double* %40 to i64
%43 = ptrtoint double* %41 to i64
%44 = sub i64 %42, %43
%45 = ashr exact i64 %44, 3
%46 = tail call i32 @ti_nvi_start(double* %2)
%47 = sub nsw i32 %0, %46
%48 = sext i32 %47 to i64
%49 = icmp eq i64 %45, %48
%50 = zext i1 %49 to i32
%51 = tail call i32 @assert(i32 %50)
br label %52
52: ; preds = %4, %39
ret i32 0
}