#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 ldintensity(double, double *);
double ldradiusfromintensity(double intensity, double lda[5]) {
  int count = 0;
  double minr = 0.0, maxr = 1.0, iatmin, iatmax;
  double midr, iatmid, di;
  double rfitollerance = 0.0001;
  iatmin = ldintensity(minr, lda);
  iatmax = ldintensity(maxr, lda);
  di = 100;
  if (iatmin < intensity || iatmax > intensity)
    return -1.0;
  while (di > rfitollerance) {
    count++;
    midr = (minr + maxr) / 2.0;
    iatmid = ldintensity(midr, lda);
    if (iatmid > intensity) {
      minr = midr;
      di = iatmid - intensity;
    } else {
      maxr = midr;
      di = intensity - iatmid;
    }
    if (count > 100000000)
      di = 0;
  }
  return midr;
}


x86 assembly (clang, -O0):
<ldradiusfromintensity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xed8(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <ldintensity@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <ldintensity@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0xe88(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     11a1 <ldradiusfromintensity+0x91>
movsd  -0x40(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b3 <ldradiusfromintensity+0xa3>
movsd  0xe77(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    126a <ldradiusfromintensity+0x15a>
jmp    11b8 <ldradiusfromintensity+0xa8>
movsd  -0x58(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jbe    1260 <ldradiusfromintensity+0x150>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  0xe35(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <ldintensity@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    122d <ldradiusfromintensity+0x11d>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1246 <ldradiusfromintensity+0x136>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x5f5e100,-0x1c(%rbp)
jle    125b <ldradiusfromintensity+0x14b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11b8 <ldradiusfromintensity+0xa8>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldradiusfromintensity>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
call   1030 <ldintensity@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xecb(%rip),%xmm0
mov    %rbx,%rdi
call   1030 <ldintensity@plt>
movsd  0x8(%rsp),%xmm3
ucomisd 0x10(%rsp),%xmm3
movsd  0xeb7(%rip),%xmm5
ja     1231 <ldradiusfromintensity+0x121>
ucomisd %xmm3,%xmm0
movsd  0xe9d(%rip),%xmm2
ja     1231 <ldradiusfromintensity+0x121>
xorpd  %xmm6,%xmm6
xor    %ebp,%ebp
jmp    11aa <ldradiusfromintensity+0x9a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
movapd %xmm3,%xmm2
cmpltsd %xmm0,%xmm2
movapd %xmm2,%xmm0
andnpd %xmm5,%xmm0
andpd  %xmm4,%xmm2
orpd   %xmm0,%xmm2
ucomisd 0xe74(%rip),%xmm1
jbe    1231 <ldradiusfromintensity+0x121>
movsd  %xmm6,0x28(%rsp)
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
addsd  %xmm6,%xmm0
mulsd  0xe4a(%rip),%xmm0
movapd %xmm0,0x30(%rsp)
mov    %rbx,%rdi
call   1030 <ldintensity@plt>
movsd  0x8(%rsp),%xmm3
ucomisd %xmm3,%xmm0
ja     1200 <ldradiusfromintensity+0xf0>
movapd %xmm3,%xmm2
subsd  %xmm0,%xmm2
movapd 0x10(%rsp),%xmm4
movapd 0x30(%rsp),%xmm5
movsd  0x28(%rsp),%xmm6
jmp    1218 <ldradiusfromintensity+0x108>
nopl   0x0(%rax)
movapd %xmm0,%xmm2
subsd  %xmm3,%xmm2
movapd 0x30(%rsp),%xmm5
movapd %xmm5,%xmm6
movapd 0x10(%rsp),%xmm4
xorpd  %xmm1,%xmm1
cmp    $0x5f5e100,%ebp
jae    1180 <ldradiusfromintensity+0x70>
movapd %xmm2,%xmm1
jmp    1180 <ldradiusfromintensity+0x70>
movapd %xmm5,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @ldradiusfromintensity(double %0, double* %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double*
%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
store double %0, double* %4
store double* %1, double** %5
store i32 0, i32* %6
store double 0.000000e+00, double* %7
store double 1.000000e+00, double* %8
store double 1.000000e-04, double* %14
%15 = load double, double* %7
%16 = load double*, double** %5
%17 = call double @ldintensity(double %15, double* %16)
store double %17, double* %9
%18 = load double, double* %8
%19 = load double*, double** %5
%20 = call double @ldintensity(double %18, double* %19)
store double %20, double* %10
store double 1.000000e+02, double* %13
%21 = load double, double* %9
%22 = load double, double* %4
%23 = fcmp olt double %21, %22
br i1 %23, label %28, label %24
24: ; preds = %2
%25 = load double, double* %10
%26 = load double, double* %4
%27 = fcmp ogt double %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24, %2
store double -1.000000e+00, double* %3
br label %64
29: ; preds = %24
br label %30
30: ; preds = %61, %29
%31 = load double, double* %13
%32 = load double, double* %14
%33 = fcmp ogt double %31, %32
br i1 %33, label %34, label %62
34: ; preds = %30
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
%37 = load double, double* %7
%38 = load double, double* %8
%39 = fadd double %37, %38
%40 = fdiv double %39, 2.000000e+00
store double %40, double* %11
%41 = load double, double* %11
%42 = load double*, double** %5
%43 = call double @ldintensity(double %41, double* %42)
store double %43, double* %12
%44 = load double, double* %12
%45 = load double, double* %4
%46 = fcmp ogt double %44, %45
br i1 %46, label %47, label %52
47: ; preds = %34
%48 = load double, double* %11
store double %48, double* %7
%49 = load double, double* %12
%50 = load double, double* %4
%51 = fsub double %49, %50
store double %51, double* %13
br label %57
52: ; preds = %34
%53 = load double, double* %11
store double %53, double* %8
%54 = load double, double* %4
%55 = load double, double* %12
%56 = fsub double %54, %55
store double %56, double* %13
br label %57
57: ; preds = %52, %47
%58 = load i32, i32* %6
%59 = icmp sgt i32 %58, 100000000
br i1 %59, label %60, label %61
60: ; preds = %57
store double 0.000000e+00, double* %13
br label %61
61: ; preds = %60, %57
br label %30
62: ; preds = %30
%63 = load double, double* %11
store double %63, double* %3
br label %64
64: ; preds = %62, %28
%65 = load double, double* %3
ret double %65
}

LLVM IR (-O2):
define double @ldradiusfromintensity(double %0, double* %1) {
%3 = tail call double @ldintensity(double 0.000000e+00, double* %1)
%4 = tail call double @ldintensity(double 1.000000e+00, double* %1)
%5 = fcmp olt double %3, %0
%6 = fcmp ogt double %4, %0
%7 = select i1 %5, i1 true, i1 %6
br i1 %7, label %25, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %12, %8 ], [ 0, %2 ]
%10 = phi double [ %20, %8 ], [ 0.000000e+00, %2 ]
%11 = phi double [ %19, %8 ], [ 1.000000e+00, %2 ]
%12 = add nuw nsw i32 %9, 1
%13 = fadd double %11, %10
%14 = fmul double %13, 5.000000e-01
%15 = tail call double @ldintensity(double %14, double* %1)
%16 = fcmp ogt double %15, %0
%17 = fsub double %15, %0
%18 = fsub double %0, %15
%19 = select i1 %16, double %11, double %14
%20 = select i1 %16, double %14, double %10
%21 = select i1 %16, double %17, double %18
%22 = icmp ugt i32 %9, 99999999
%23 = select i1 %22, double 0.000000e+00, double %21
%24 = fcmp ogt double %23, 1.000000e-04
br i1 %24, label %8, label %25
25: ; preds = %8, %2
%26 = phi double [ -1.000000e+00, %2 ], [ %14, %8 ]
ret double %26
}