#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 acos(double);
double area(double, double, double);
double intensity(double, double *);
void calc_limb_darkening(double *f_array, double *d_array, int N, double rprs,
                         double fac, int nthreads, double *intensity_args) {
  for (int i = 0; i < N; i++) {
    double d = d_array[i];
    double x_in = (((d - rprs) > (0.)) ? (d - rprs) : (0.));
    double x_out = (((d + rprs) < (1.0)) ? (d + rprs) : (1.0));
    if (x_in >= 1.)
      f_array[i] = 1.0;
    else if (x_out - x_in < 1.e-7)
      f_array[i] = 1.0;
    else {
      double delta = 0.;
      double x = x_in;
      double dx = fac * acos(x);
      x += dx;
      double A_i = 0.;
      while (x < x_out) {
        double A_f = area(d, x, rprs);
        double I = intensity(x - dx / 2., intensity_args);
        delta += (A_f - A_i) * I;
        dx = fac * acos(x);
        x = x + dx;
        A_i = A_f;
      }
      dx = x_out - x + dx;
      x = x_out;
      double A_f = area(d, x, rprs);
      double I = intensity(x - dx / 2., intensity_args);
      delta += (A_f - A_i) * I;
      f_array[i] = 1.0 - delta;
    }
  }
}


x86 assembly (clang, -O0):
<calc_limb_darkening>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    %r8,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    145a <calc_limb_darkening+0x32a>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11aa <calc_limb_darkening+0x7a>
movsd  -0x48(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
jmp    11ba <calc_limb_darkening+0x8a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
jmp    11ba <calc_limb_darkening+0x8a>
movsd  -0xa0(%rbp),%xmm0
ff
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
movsd  0xe27(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fa <calc_limb_darkening+0xca>
movsd  -0x48(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
jmp    120f <calc_limb_darkening+0xdf>
movsd  0xdfe(%rip),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
jmp    120f <calc_limb_darkening+0xdf>
movsd  -0xa8(%rbp),%xmm0
ff
movsd  %xmm0,-0x58(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  0xdd7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     124d <calc_limb_darkening+0x11d>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  0xdbd(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1447 <calc_limb_darkening+0x317>
movsd  -0x58(%rbp),%xmm1
subsd  -0x50(%rbp),%xmm1
movsd  0xda9(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1283 <calc_limb_darkening+0x153>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  0xd87(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1442 <calc_limb_darkening+0x312>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
call   1040 <acos@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x68(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    139c <calc_limb_darkening+0x26c>
movsd  -0x48(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1050 <area@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
movsd  0xcfa(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rdi
call   1030 <intensity@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
subsd  -0x78(%rbp),%xmm0
movsd  -0x88(%rbp),%xmm2
ff
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
call   1040 <acos@plt>
movaps %xmm0,%xmm1
movsd  -0xb8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    12d7 <calc_limb_darkening+0x1a7>
movsd  -0x58(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1050 <area@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
movsd  0xc28(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rdi
call   1030 <intensity@plt>
movsd  %xmm0,-0x98(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
subsd  -0x78(%rbp),%xmm0
movsd  -0x98(%rbp),%xmm2
ff
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xbd0(%rip),%xmm0
subsd  -0x60(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1447 <calc_limb_darkening+0x317>
jmp    144c <calc_limb_darkening+0x31c>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    115e <calc_limb_darkening+0x2e>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_limb_darkening>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
movsd  %xmm1,0x40(%rsp)
test   %edx,%edx
jle    1366 <calc_limb_darkening+0x236>
mov    %r8,%r13
movapd %xmm0,%xmm1
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
xorpd  %xmm2,%xmm2
movsd  0xe97(%rip),%xmm3
movsd  %xmm0,0x28(%rsp)
jmp    1220 <calc_limb_darkening+0xf0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp),%xmm2
movapd %xmm1,%xmm0
subsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
movsd  %xmm0,0x38(%rsp)
movapd %xmm2,%xmm0
movsd  0x28(%rsp),%xmm2
call   1050 <area@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x38(%rsp),%xmm0
mulsd  0xe41(%rip),%xmm0
addsd  0x30(%rsp),%xmm0
mov    %r13,%rdi
call   1030 <intensity@plt>
movsd  0x28(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
subsd  0x18(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  0x10(%rsp),%xmm2
movsd  0xdff(%rip),%xmm3
movapd %xmm3,%xmm4
subsd  %xmm2,%xmm4
xorpd  %xmm2,%xmm2
movsd  %xmm4,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %r12,%rbx
je     1366 <calc_limb_darkening+0x236>
movsd  (%r14,%rbx,8),%xmm5
movapd %xmm5,%xmm0
subsd  %xmm1,%xmm0
maxsd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
movapd %xmm3,%xmm4
jae    120d <calc_limb_darkening+0xdd>
movapd %xmm5,%xmm6
addsd  %xmm1,%xmm6
minsd  %xmm3,%xmm6
movapd %xmm6,%xmm7
subsd  %xmm0,%xmm7
movsd  0xdb0(%rip),%xmm4
ucomisd %xmm7,%xmm4
movapd %xmm3,%xmm4
ja     120d <calc_limb_darkening+0xdd>
movsd  %xmm5,0x20(%rsp)
movsd  %xmm6,0x30(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1040 <acos@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x30(%rsp),%xmm1
movapd %xmm0,%xmm4
movsd  0x40(%rsp),%xmm0
mulsd  %xmm0,%xmm4
addsd  %xmm4,%xmm3
ucomisd %xmm3,%xmm1
jbe    1180 <calc_limb_darkening+0x50>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x10(%rsp)
xorpd  %xmm5,%xmm5
movsd  0x20(%rsp),%xmm2
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm4,0x48(%rsp)
movsd  %xmm5,0x38(%rsp)
movsd  %xmm3,0x8(%rsp)
movaps %xmm2,%xmm0
movapd %xmm3,%xmm1
movsd  0x28(%rsp),%xmm2
call   1050 <area@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x48(%rsp),%xmm0
mulsd  0xd18(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
mov    %r13,%rdi
call   1030 <intensity@plt>
movsd  0x18(%rsp),%xmm1
subsd  0x38(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <acos@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x30(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
movapd %xmm0,%xmm4
mulsd  0x40(%rsp),%xmm4
addsd  %xmm4,%xmm3
ucomisd %xmm3,%xmm1
movsd  0x18(%rsp),%xmm5
ja     12c0 <calc_limb_darkening+0x190>
jmp    119a <calc_limb_darkening+0x6a>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @calc_limb_darkening(double* nocapture writeonly %0, double* nocapture %1, i32 %2, double %3, double %4, i32 %5, double* %6) {
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = zext i32 %2 to i64
br label %12
11: ; preds = %60, %7
ret void
12: ; preds = %9, %60
%13 = phi i64 [ 0, %9 ], [ %63, %60 ]
%14 = getelementptr inbounds double, double* %1, i64 %13
%15 = load double, double* %14
%16 = fsub double %15, %3
%17 = fcmp ogt double %16, 0.000000e+00
%18 = select i1 %17, double %16, double 0.000000e+00
%19 = fadd double %15, %3
%20 = fcmp olt double %19, 1.000000e+00
%21 = select i1 %20, double %19, double 1.000000e+00
%22 = fcmp oge double %18, 1.000000e+00
%23 = fsub double %21, %18
%24 = fcmp olt double %23, 0x3E7AD7F29ABCAF48
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %60, label %26
26: ; preds = %12
%27 = tail call double @acos(double %18)
%28 = fmul double %27, %4
%29 = fadd double %18, %28
%30 = fcmp olt double %29, %21
br i1 %30, label %31, label %46
31: ; preds = %26, %31
%32 = phi double [ %41, %31 ], [ 0.000000e+00, %26 ]
%33 = phi double [ %44, %31 ], [ %29, %26 ]
%34 = phi double [ %43, %31 ], [ %28, %26 ]
%35 = phi double [ %36, %31 ], [ 0.000000e+00, %26 ]
%36 = tail call double @area(double %15, double %33, double %3)
%37 = fmul double %34, 5.000000e-01
%38 = fsub double %33, %37
%39 = tail call double @intensity(double %38, double* %6)
%40 = fsub double %36, %35
%41 = tail call double @llvm.fmuladd.f64(double %40, double %39, double %32)
%42 = tail call double @acos(double %33)
%43 = fmul double %42, %4
%44 = fadd double %33, %43
%45 = fcmp olt double %44, %21
br i1 %45, label %31, label %46
46: ; preds = %31, %26
%47 = phi double [ 0.000000e+00, %26 ], [ %36, %31 ]
%48 = phi double [ %28, %26 ], [ %43, %31 ]
%49 = phi double [ %29, %26 ], [ %44, %31 ]
%50 = phi double [ 0.000000e+00, %26 ], [ %41, %31 ]
%51 = fsub double %21, %49
%52 = fadd double %48, %51
%53 = tail call double @area(double %15, double %21, double %3)
%54 = fmul double %52, 5.000000e-01
%55 = fsub double %21, %54
%56 = tail call double @intensity(double %55, double* %6)
%57 = fsub double %53, %47
%58 = tail call double @llvm.fmuladd.f64(double %57, double %56, double %50)
%59 = fsub double 1.000000e+00, %58
br label %60
60: ; preds = %12, %46
%61 = phi double [ %59, %46 ], [ 1.000000e+00, %12 ]
%62 = getelementptr inbounds double, double* %0, i64 %13
store double %61, double* %62
%63 = add nuw nsw i64 %13, 1
%64 = icmp eq i64 %63, %10
br i1 %64, label %11, label %12
}