#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_wad_start(double const *);
int ti_wad(int size, double const *const *inputs, double const *options,
           double *const *outputs) {
  const double *high = inputs[0];
  const double *low = inputs[1];
  const double *close = inputs[2];
  (void)options;
  if (size <= ti_wad_start(options))
    return 0;
  double *output = outputs[0];
  double sum = 0;
  double yc = close[0];
  int i;
  for (i = 1; i < size; ++i) {
    const double c = close[i];
    if (c > yc) {
      sum += c - ((yc) < (low[i]) ? (yc) : (low[i]));
    } else if (c < yc) {
      sum += c - ((yc) > (high[i]) ? (yc) : (high[i]));
    } else {
    }
    *output++ = sum;
    yc = close[i];
  }
  assert(output - outputs[0] == size - ti_wad_start(options));
  return 0;
}


x86 assembly (clang, -O0):
<ti_wad>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%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    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ti_wad_start@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cmp    %ecx,%eax
jg     1185 <ti_wad+0x65>
movl   $0x0,-0x4(%rbp)
jmp    1353 <ti_wad+0x233>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12fd <ti_wad+0x1dd>
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    123e <ti_wad+0x11e>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x50(%rbp),%xmm1
mov    -0x30(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    120f <ti_wad+0xef>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    1221 <ti_wad+0x101>
mov    -0x30(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  -0x78(%rbp),%xmm1
subsd  %xmm1,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12c5 <ti_wad+0x1a5>
movsd  -0x60(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12bb <ti_wad+0x19b>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
jbe    1286 <ti_wad+0x166>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
jmp    129b <ti_wad+0x17b>
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
movsd  -0x88(%rbp),%xmm1
ff
subsd  %xmm1,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12c0 <ti_wad+0x1a0>
jmp    12c0 <ti_wad+0x1a0>
jmp    12c5 <ti_wad+0x1a5>
movsd  -0x48(%rbp),%xmm0
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x40(%rbp)
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11ac <ti_wad+0x8c>
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %rax,-0x90(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ti_wad_start@plt>
mov    -0x94(%rbp),%ecx
mov    %eax,%edx
mov    -0x90(%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    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ti_wad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %edi,%r13d
mov    (%rsi),%r12
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r14
mov    %rdx,%rdi
call   1030 <ti_wad_start@plt>
cmp    %r13d,%eax
jge    11e1 <ti_wad+0xc1>
mov    %rbx,%rdi
mov    (%r15),%rax
mov    %rax,%rbx
cmp    $0x2,%r13d
jl     11c1 <ti_wad+0xa1>
mov    %r13d,%ecx
lea    -0x8(,%rcx,8),%rcx
ff
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    119c <ti_wad+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
minsd  0x8(%rbp,%rbx,1),%xmm2
subsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rbx,1)
add    $0x8,%rbx
cmp    %rbx,%rcx
je     11be <ti_wad+0x9e>
movsd  (%r14,%rbx,1),%xmm2
movsd  0x8(%r14,%rbx,1),%xmm1
ucomisd %xmm2,%xmm1
ja     1180 <ti_wad+0x60>
ucomisd %xmm1,%xmm2
jbe    118e <ti_wad+0x6e>
maxsd  0x8(%r12,%rbx,1),%xmm2
jmp    1186 <ti_wad+0x66>
add    %rax,%rbx
sub    %rax,%rbx
sar    $0x3,%rbx
call   1030 <ti_wad_start@plt>
sub    %eax,%r13d
movslq %r13d,%rax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1040 <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_wad(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 double
%15 = alloca double
%16 = alloca i32
%17 = alloca double
store i32 %0, i32* %6
store double** %1, double*** %7
store double* %2, double** %8
store double** %3, double*** %9
%18 = load double**, double*** %7
%19 = getelementptr inbounds double*, double** %18, i64 0
%20 = load double*, double** %19
store double* %20, double** %10
%21 = load double**, double*** %7
%22 = getelementptr inbounds double*, double** %21, i64 1
%23 = load double*, double** %22
store double* %23, double** %11
%24 = load double**, double*** %7
%25 = getelementptr inbounds double*, double** %24, i64 2
%26 = load double*, double** %25
store double* %26, double** %12
%27 = load double*, double** %8
%28 = load i32, i32* %6
%29 = load double*, double** %8
%30 = call i32 @ti_wad_start(double* %29)
%31 = icmp sle i32 %28, %30
br i1 %31, label %32, label %33
32: ; preds = %4
store i32 0, i32* %5
br label %132
33: ; preds = %4
%34 = load double**, double*** %9
%35 = getelementptr inbounds double*, double** %34, i64 0
%36 = load double*, double** %35
store double* %36, double** %13
store double 0.000000e+00, double* %14
%37 = load double*, double** %12
%38 = getelementptr inbounds double, double* %37, i64 0
%39 = load double, double* %38
store double %39, double* %15
store i32 1, i32* %16
br label %40
40: ; preds = %112, %33
%41 = load i32, i32* %16
%42 = load i32, i32* %6
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %115
44: ; preds = %40
%45 = load double*, double** %12
%46 = load i32, i32* %16
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
store double %49, double* %17
%50 = load double, double* %17
%51 = load double, double* %15
%52 = fcmp ogt double %50, %51
br i1 %52, label %53, label %75
53: ; preds = %44
%54 = load double, double* %17
%55 = load double, double* %15
%56 = load double*, double** %11
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = fcmp olt double %55, %60
br i1 %61, label %62, label %64
62: ; preds = %53
%63 = load double, double* %15
br label %70
64: ; preds = %53
%65 = load double*, double** %11
%66 = load i32, i32* %16
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
br label %70
70: ; preds = %64, %62
%71 = phi double [ %63, %62 ], [ %69, %64 ]
%72 = fsub double %54, %71
%73 = load double, double* %14
%74 = fadd double %73, %72
store double %74, double* %14
br label %103
75: ; preds = %44
%76 = load double, double* %17
%77 = load double, double* %15
%78 = fcmp olt double %76, %77
br i1 %78, label %79, label %101
79: ; preds = %75
%80 = load double, double* %17
%81 = load double, double* %15
%82 = load double*, double** %10
%83 = load i32, i32* %16
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = fcmp ogt double %81, %86
br i1 %87, label %88, label %90
88: ; preds = %79
%89 = load double, double* %15
br label %96
90: ; preds = %79
%91 = load double*, double** %10
%92 = load i32, i32* %16
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds double, double* %91, i64 %93
%95 = load double, double* %94
br label %96
96: ; preds = %90, %88
%97 = phi double [ %89, %88 ], [ %95, %90 ]
%98 = fsub double %80, %97
%99 = load double, double* %14
%100 = fadd double %99, %98
store double %100, double* %14
br label %102
101: ; preds = %75
br label %102
102: ; preds = %101, %96
br label %103
103: ; preds = %102, %70
%104 = load double, double* %14
%105 = load double*, double** %13
%106 = getelementptr inbounds double, double* %105, i32 1
store double* %106, double** %13
store double %104, double* %105
%107 = load double*, double** %12
%108 = load i32, i32* %16
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds double, double* %107, i64 %109
%111 = load double, double* %110
store double %111, double* %15
br label %112
112: ; preds = %103
%113 = load i32, i32* %16
%114 = add nsw i32 %113, 1
store i32 %114, i32* %16
br label %40
115: ; preds = %40
%116 = load double*, double** %13
%117 = load double**, double*** %9
%118 = getelementptr inbounds double*, double** %117, i64 0
%119 = load double*, double** %118
%120 = ptrtoint double* %116 to i64
%121 = ptrtoint double* %119 to i64
%122 = sub i64 %120, %121
%123 = sdiv exact i64 %122, 8
%124 = load i32, i32* %6
%125 = load double*, double** %8
%126 = call i32 @ti_wad_start(double* %125)
%127 = sub nsw i32 %124, %126
%128 = sext i32 %127 to i64
%129 = icmp eq i64 %123, %128
%130 = zext i1 %129 to i32
%131 = call i32 @assert(i32 %130)
store i32 0, i32* %5
br label %132
132: ; preds = %115, %32
%133 = load i32, i32* %5
ret i32 %133
}

LLVM IR (-O2):
define i32 @ti_wad(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 = getelementptr inbounds double*, double** %1, i64 2
%9 = load double*, double** %8
%10 = tail call i32 @ti_wad_start(double* %2)
%11 = icmp slt i32 %10, %0
br i1 %11, label %12, label %59
12: ; preds = %4
%13 = load double*, double** %3
%14 = icmp sgt i32 %0, 1
br i1 %14, label %15, label %47
15: ; preds = %12
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %15, %42
%18 = phi i64 [ 1, %15 ], [ %45, %42 ]
%19 = phi double* [ %9, %15 ], [ %23, %42 ]
%20 = phi double [ 0.000000e+00, %15 ], [ %43, %42 ]
%21 = phi double* [ %13, %15 ], [ %44, %42 ]
%22 = load double, double* %19
%23 = getelementptr inbounds double, double* %9, i64 %18
%24 = load double, double* %23
%25 = fcmp ogt double %24, %22
br i1 %25, label %26, label %33
26: ; preds = %17
%27 = getelementptr inbounds double, double* %7, i64 %18
%28 = load double, double* %27
%29 = fcmp olt double %22, %28
%30 = select i1 %29, double %22, double %28
%31 = fsub double %24, %30
%32 = fadd double %20, %31
br label %42
33: ; preds = %17
%34 = fcmp olt double %24, %22
br i1 %34, label %35, label %42
35: ; preds = %33
%36 = getelementptr inbounds double, double* %5, i64 %18
%37 = load double, double* %36
%38 = fcmp ogt double %22, %37
%39 = select i1 %38, double %22, double %37
%40 = fsub double %24, %39
%41 = fadd double %20, %40
br label %42
42: ; preds = %35, %33, %26
%43 = phi double [ %32, %26 ], [ %41, %35 ], [ %20, %33 ]
%44 = getelementptr inbounds double, double* %21, i64 1
store double %43, double* %21
%45 = add nuw nsw i64 %18, 1
%46 = icmp eq i64 %45, %16
br i1 %46, label %47, label %17
47: ; preds = %42, %12
%48 = phi double* [ %13, %12 ], [ %44, %42 ]
%49 = ptrtoint double* %48 to i64
%50 = ptrtoint double* %13 to i64
%51 = sub i64 %49, %50
%52 = ashr exact i64 %51, 3
%53 = tail call i32 @ti_wad_start(double* %2)
%54 = sub nsw i32 %0, %53
%55 = sext i32 %54 to i64
%56 = icmp eq i64 %52, %55
%57 = zext i1 %56 to i32
%58 = tail call i32 @assert(i32 %57)
br label %59
59: ; preds = %4, %47
ret i32 0
}