#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 */
double floor(double);
int /*<<< orphan*/ isnan(double);
double chisqtraptransit(double *a_, int ma, int N, double *t, double *mag,
                        double *sig, void *userparams) {
  double ph;
  double P;
  double q;
  double qingress;
  double in1_ph;
  double t0;
  double depth;
  double OOTmag;
  int i;
  double chisq, ph1, ph2;
  double mc, temp;
  P = a_[0];
  q = a_[1];
  qingress = a_[2];
  in1_ph = a_[3];
  depth = a_[4];
  OOTmag = a_[5];
  if (qingress > 0.5)
    qingress = 0.5;
  if (qingress < 0.)
    qingress = 0.;
  if (q > 1.)
    q = 1.;
  if (q < 0.)
    q = 0.;
  t0 = t[0] + in1_ph * P;
  chisq = 0.;
  ph1 = qingress * q;
  ph2 = q - qingress * q;
  for (i = 0; i < N; i++) {
    if (!isnan(mag[i])) {
      ph = ((t[i] - t0) / P);
      ph = ph - floor(ph);
      if (ph > q)
        mc = OOTmag;
      else if (ph > ph1 && ph < ph2)
        mc = OOTmag + depth;
      else {
        if (ph < ph1) {
          mc = OOTmag + depth * ph / ph1;
        } else {
          mc = OOTmag + depth * (q - ph) / ph1;
        }
      }
      temp = (mag[i] - mc) / sig[i];
      chisq += temp * temp;
    }
  }
  return (chisq);
}


x86 assembly (clang, -O0):
<chisqtraptransit>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x28(%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xe5b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11bc <chisqtraptransit+0x9c>
movsd  0xe49(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    11d2 <chisqtraptransit+0xb2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe29(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f6 <chisqtraptransit+0xd6>
movsd  0xe17(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    120c <chisqtraptransit+0xec>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movl   $0x0,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1418 <chisqtraptransit+0x2f8>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    1405 <chisqtraptransit+0x2e5>
mov    -0x18(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x58(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x30(%rbp),%xmm0
call   1040 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    130f <chisqtraptransit+0x1ef>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    13b9 <chisqtraptransit+0x299>
movsd  -0x30(%rbp),%xmm0
ucomisd -0x80(%rbp),%xmm0
jbe    134d <chisqtraptransit+0x22d>
movsd  -0x30(%rbp),%xmm1
movsd  -0x88(%rbp),%xmm0
ff
ucomisd %xmm1,%xmm0
jbe    134d <chisqtraptransit+0x22d>
movsd  -0x68(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    13b4 <chisqtraptransit+0x294>
movsd  -0x30(%rbp),%xmm1
movsd  -0x80(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1386 <chisqtraptransit+0x266>
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
divsd  -0x80(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    13af <chisqtraptransit+0x28f>
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
subsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  -0x80(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
jmp    13b4 <chisqtraptransit+0x294>
jmp    13b9 <chisqtraptransit+0x299>
mov    -0x20(%rbp),%rax
movslq -0x6c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x90(%rbp),%xmm0
ff
mov    -0x28(%rbp),%rax
movslq -0x6c(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm0
ff
movsd  -0x98(%rbp),%xmm2
ff
movsd  -0x78(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    140a <chisqtraptransit+0x2ea>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    127f <chisqtraptransit+0x15f>
movsd  -0x78(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chisqtraptransit>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
xorpd  %xmm2,%xmm2
test   %edx,%edx
jle    12b0 <chisqtraptransit+0x190>
mov    %r9,%r14
mov    %r8,%r13
mov    %rcx,%r15
movsd  (%rdi),%xmm3
movsd  0x20(%rdi),%xmm4
movsd  0x28(%rdi),%xmm5
movsd  0xea8(%rip),%xmm0
minsd  0x10(%rdi),%xmm0
xorpd  %xmm6,%xmm6
movsd  0xe9f(%rip),%xmm1
minsd  0x8(%rdi),%xmm1
maxsd  %xmm0,%xmm6
maxsd  %xmm1,%xmm2
movsd  0x18(%rdi),%xmm0
movsd  %xmm3,0x38(%rsp)
mulsd  %xmm3,%xmm0
addsd  (%rcx),%xmm0
movsd  %xmm0,0x30(%rsp)
mulsd  %xmm2,%xmm6
movapd %xmm2,%xmm0
movsd  %xmm6,0x18(%rsp)
subsd  %xmm6,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  %xmm4,0x10(%rsp)
movsd  %xmm5,0x8(%rsp)
addsd  %xmm5,%xmm4
movsd  %xmm4,0x20(%rsp)
mov    %edx,%r12d
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
movsd  %xmm2,0x40(%rsp)
jmp    1220 <chisqtraptransit+0x100>
movapd %xmm2,%xmm0
subsd  %xmm3,%xmm0
mulsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
nopl   0x0(%rax,%rax,1)
movsd  0x0(%r13,%rbx,8),%xmm1
subsd  %xmm0,%xmm1
divsd  (%r14,%rbx,8),%xmm1
mulsd  %xmm1,%xmm1
movsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
add    $0x1,%rbx
cmp    %rbx,%r12
je     12b9 <chisqtraptransit+0x199>
movsd  0x0(%r13,%rbx,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1213 <chisqtraptransit+0xf3>
movsd  (%r15,%rbx,8),%xmm0
subsd  0x30(%rsp),%xmm0
divsd  0x38(%rsp),%xmm0
movsd  %xmm0,0x48(%rsp)
call   1040 <floor@plt>
movsd  0x48(%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0x40(%rsp),%xmm2
ucomisd %xmm2,%xmm3
movsd  0x8(%rsp),%xmm0
ja     11f0 <chisqtraptransit+0xd0>
ucomisd 0x18(%rsp),%xmm3
jbe    1287 <chisqtraptransit+0x167>
movsd  0x28(%rsp),%xmm0
ucomisd %xmm3,%xmm0
movsd  0x20(%rsp),%xmm0
ja     11f0 <chisqtraptransit+0xd0>
movsd  0x18(%rsp),%xmm1
ucomisd %xmm3,%xmm1
jbe    11d3 <chisqtraptransit+0xb3>
mulsd  0x10(%rsp),%xmm3
divsd  %xmm1,%xmm3
addsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm0
jmp    11f0 <chisqtraptransit+0xd0>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @chisqtraptransit(double* %0, i32 %1, i32 %2, double* %3, double* %4, double* %5, i8* %6) {
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i8*
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca i32
%24 = alloca double
%25 = alloca double
%26 = alloca double
%27 = alloca double
%28 = alloca double
store double* %0, double** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store double* %3, double** %11
store double* %4, double** %12
store double* %5, double** %13
store i8* %6, i8** %14
%29 = load double*, double** %8
%30 = getelementptr inbounds double, double* %29, i64 0
%31 = load double, double* %30
store double %31, double* %16
%32 = load double*, double** %8
%33 = getelementptr inbounds double, double* %32, i64 1
%34 = load double, double* %33
store double %34, double* %17
%35 = load double*, double** %8
%36 = getelementptr inbounds double, double* %35, i64 2
%37 = load double, double* %36
store double %37, double* %18
%38 = load double*, double** %8
%39 = getelementptr inbounds double, double* %38, i64 3
%40 = load double, double* %39
store double %40, double* %19
%41 = load double*, double** %8
%42 = getelementptr inbounds double, double* %41, i64 4
%43 = load double, double* %42
store double %43, double* %21
%44 = load double*, double** %8
%45 = getelementptr inbounds double, double* %44, i64 5
%46 = load double, double* %45
store double %46, double* %22
%47 = load double, double* %18
%48 = fcmp ogt double %47, 5.000000e-01
br i1 %48, label %49, label %50
49: ; preds = %7
store double 5.000000e-01, double* %18
br label %50
50: ; preds = %49, %7
%51 = load double, double* %18
%52 = fcmp olt double %51, 0.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %50
store double 0.000000e+00, double* %18
br label %54
54: ; preds = %53, %50
%55 = load double, double* %17
%56 = fcmp ogt double %55, 1.000000e+00
br i1 %56, label %57, label %58
57: ; preds = %54
store double 1.000000e+00, double* %17
br label %58
58: ; preds = %57, %54
%59 = load double, double* %17
%60 = fcmp olt double %59, 0.000000e+00
br i1 %60, label %61, label %62
61: ; preds = %58
store double 0.000000e+00, double* %17
br label %62
62: ; preds = %61, %58
%63 = load double*, double** %11
%64 = getelementptr inbounds double, double* %63, i64 0
%65 = load double, double* %64
%66 = load double, double* %19
%67 = load double, double* %16
%68 = call double @llvm.fmuladd.f64(double %66, double %67, double %65)
store double %68, double* %20
store double 0.000000e+00, double* %24
%69 = load double, double* %18
%70 = load double, double* %17
%71 = fmul double %69, %70
store double %71, double* %25
%72 = load double, double* %17
%73 = load double, double* %18
%74 = load double, double* %17
%75 = fneg double %73
%76 = call double @llvm.fmuladd.f64(double %75, double %74, double %72)
store double %76, double* %26
store i32 0, i32* %23
br label %77
77: ; preds = %163, %62
%78 = load i32, i32* %23
%79 = load i32, i32* %10
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %166
81: ; preds = %77
%82 = load double*, double** %12
%83 = load i32, i32* %23
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
%86 = load double, double* %85
%87 = call i32 @isnan(double %86)
%88 = icmp ne i32 %87, 0
br i1 %88, label %162, label %89
89: ; preds = %81
%90 = load double*, double** %11
%91 = load i32, i32* %23
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double, double* %90, i64 %92
%94 = load double, double* %93
%95 = load double, double* %20
%96 = fsub double %94, %95
%97 = load double, double* %16
%98 = fdiv double %96, %97
store double %98, double* %15
%99 = load double, double* %15
%100 = load double, double* %15
%101 = call double @llvm.floor.f64(double %100)
%102 = fsub double %99, %101
store double %102, double* %15
%103 = load double, double* %15
%104 = load double, double* %17
%105 = fcmp ogt double %103, %104
br i1 %105, label %106, label %108
106: ; preds = %89
%107 = load double, double* %22
store double %107, double* %27
br label %144
108: ; preds = %89
%109 = load double, double* %15
%110 = load double, double* %25
%111 = fcmp ogt double %109, %110
br i1 %111, label %112, label %120
112: ; preds = %108
%113 = load double, double* %15
%114 = load double, double* %26
%115 = fcmp olt double %113, %114
br i1 %115, label %116, label %120
116: ; preds = %112
%117 = load double, double* %22
%118 = load double, double* %21
%119 = fadd double %117, %118
store double %119, double* %27
br label %143
120: ; preds = %112, %108
%121 = load double, double* %15
%122 = load double, double* %25
%123 = fcmp olt double %121, %122
br i1 %123, label %124, label %132
124: ; preds = %120
%125 = load double, double* %22
%126 = load double, double* %21
%127 = load double, double* %15
%128 = fmul double %126, %127
%129 = load double, double* %25
%130 = fdiv double %128, %129
%131 = fadd double %125, %130
store double %131, double* %27
br label %142
132: ; preds = %120
%133 = load double, double* %22
%134 = load double, double* %21
%135 = load double, double* %17
%136 = load double, double* %15
%137 = fsub double %135, %136
%138 = fmul double %134, %137
%139 = load double, double* %25
%140 = fdiv double %138, %139
%141 = fadd double %133, %140
store double %141, double* %27
br label %142
142: ; preds = %132, %124
br label %143
143: ; preds = %142, %116
br label %144
144: ; preds = %143, %106
%145 = load double*, double** %12
%146 = load i32, i32* %23
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds double, double* %145, i64 %147
%149 = load double, double* %148
%150 = load double, double* %27
%151 = fsub double %149, %150
%152 = load double*, double** %13
%153 = load i32, i32* %23
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds double, double* %152, i64 %154
%156 = load double, double* %155
%157 = fdiv double %151, %156
store double %157, double* %28
%158 = load double, double* %28
%159 = load double, double* %28
%160 = load double, double* %24
%161 = call double @llvm.fmuladd.f64(double %158, double %159, double %160)
store double %161, double* %24
br label %162
162: ; preds = %144, %81
br label %163
163: ; preds = %162
%164 = load i32, i32* %23
%165 = add nsw i32 %164, 1
store i32 %165, i32* %23
br label %77
166: ; preds = %77
%167 = load double, double* %24
ret double %167
}

LLVM IR (-O2):
define double @chisqtraptransit(double* nocapture %0, i32 %1, i32 %2, double* nocapture %3, double* nocapture %4, double* nocapture %5, i8* nocapture readnone %6) {
%8 = load double, double* %0
%9 = getelementptr inbounds double, double* %0, i64 1
%10 = load double, double* %9
%11 = getelementptr inbounds double, double* %0, i64 2
%12 = load double, double* %11
%13 = getelementptr inbounds double, double* %0, i64 3
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %0, i64 4
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %0, i64 5
%18 = load double, double* %17
%19 = fcmp ogt double %12, 5.000000e-01
%20 = select i1 %19, double 5.000000e-01, double %12
%21 = fcmp olt double %20, 0.000000e+00
%22 = select i1 %21, double 0.000000e+00, double %20
%23 = fcmp ogt double %10, 1.000000e+00
%24 = select i1 %23, double 1.000000e+00, double %10
%25 = fcmp olt double %24, 0.000000e+00
%26 = select i1 %25, double 0.000000e+00, double %24
%27 = load double, double* %3
%28 = tail call double @llvm.fmuladd.f64(double %14, double %8, double %27)
%29 = fmul double %26, %22
%30 = fneg double %22
%31 = tail call double @llvm.fmuladd.f64(double %30, double %26, double %26)
%32 = icmp sgt i32 %2, 0
br i1 %32, label %33, label %78
33: ; preds = %7
%34 = fadd double %16, %18
%35 = zext i32 %2 to i64
br label %36
36: ; preds = %33, %74
%37 = phi i64 [ 0, %33 ], [ %76, %74 ]
%38 = phi double [ 0.000000e+00, %33 ], [ %75, %74 ]
%39 = getelementptr inbounds double, double* %4, i64 %37
%40 = load double, double* %39
%41 = tail call i32 @isnan(double %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %74
43: ; preds = %36
%44 = getelementptr inbounds double, double* %3, i64 %37
%45 = load double, double* %44
%46 = fsub double %45, %28
%47 = fdiv double %46, %8
%48 = tail call double @llvm.floor.f64(double %47)
%49 = fsub double %47, %48
%50 = fcmp ogt double %49, %26
br i1 %50, label %66, label %51
51: ; preds = %43
%52 = fcmp ogt double %49, %29
%53 = fcmp olt double %49, %31
%54 = select i1 %52, i1 %53, i1 false
br i1 %54, label %66, label %55
55: ; preds = %51
%56 = fcmp olt double %49, %29
br i1 %56, label %57, label %61
57: ; preds = %55
%58 = fmul double %16, %49
%59 = fdiv double %58, %29
%60 = fadd double %18, %59
br label %66
61: ; preds = %55
%62 = fsub double %26, %49
%63 = fmul double %16, %62
%64 = fdiv double %63, %29
%65 = fadd double %18, %64
br label %66
66: ; preds = %51, %43, %61, %57
%67 = phi double [ %60, %57 ], [ %65, %61 ], [ %18, %43 ], [ %34, %51 ]
%68 = load double, double* %39
%69 = fsub double %68, %67
%70 = getelementptr inbounds double, double* %5, i64 %37
%71 = load double, double* %70
%72 = fdiv double %69, %71
%73 = tail call double @llvm.fmuladd.f64(double %72, double %72, double %38)
br label %74
74: ; preds = %36, %66
%75 = phi double [ %38, %36 ], [ %73, %66 ]
%76 = add nuw nsw i64 %37, 1
%77 = icmp eq i64 %76, %35
br i1 %77, label %78, label %36
78: ; preds = %74, %7
%79 = phi double [ 0.000000e+00, %7 ], [ %75, %74 ]
ret double %79
}