#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 dEdX(int, double, int *, double *, double *, int, int, double);
double RangeToX(int ZP, double MP, int ZT[], double MT[], double CT[],
                int NTarEl, int IsGas, double E1, double E2) {
  double dEdX_ = 0.0, E = 0.0, dX = 0.0, Rng = 0.0;
  if (E1 <= E2)
    return 0.0;
  E = E1;
  dEdX_ = dEdX(ZP, MP, ZT, MT, CT, NTarEl, IsGas, E1);
  dX = 0.1 / dEdX_;
  dEdX_ = dEdX(ZP, MP, ZT, MT, CT, NTarEl, IsGas, E1 - 0.5 * (dEdX_ * dX));
  while ((E - E2) >= 0) {
    if ((E -= dEdX_ * dX) < 0)
      return -1.0;
    dEdX_ = dEdX(ZP, MP, ZT, MT, CT, NTarEl, IsGas, E - 0.5 * (dEdX_ * dX));
    Rng += dX;
  };
  Rng = Rng - dX * (1 - (dX * dEdX_ - (E2 - E)) / (dX * dEdX_));
  return Rng;
}


x86 assembly (clang, -O0):
<RangeToX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8d,-0x34(%rbp)
mov    %r9d,-0x38(%rbp)
movsd  %xmm1,-0x40(%rbp)
movsd  %xmm2,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     117f <RangeToX+0x6f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1352 <RangeToX+0x242>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
movsd  -0x40(%rbp),%xmm1
call   1030 <dEdX@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  0xe4c(%rip),%xmm0
divsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
movsd  -0x40(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movsd  0xe07(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
call   1030 <dEdX@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12cd <RangeToX+0x1bd>
movsd  -0x50(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,-0x58(%rbp)
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1274 <RangeToX+0x164>
movsd  0xdae(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1352 <RangeToX+0x242>
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  -0x60(%rbp),%xmm1
movsd  0xd59(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
call   1030 <dEdX@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    120b <RangeToX+0xfb>
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm4
movsd  -0x48(%rbp),%xmm2
subsd  -0x58(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm4,%xmm3
addsd  %xmm2,%xmm3
movsd  -0x60(%rbp),%xmm2
mulsd  -0x50(%rbp),%xmm2
divsd  %xmm2,%xmm3
movsd  0xcf0(%rip),%xmm2
subsd  %xmm3,%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RangeToX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm1,%xmm2
jae    1280 <RangeToX+0x170>
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,(%rsp)
call   1030 <dEdX@plt>
movapd %xmm0,%xmm1
movsd  0xea1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm0,%xmm1
mulsd  0xe93(%rip),%xmm1
addsd  (%rsp),%xmm1
mov    %ebp,%edi
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14d,%r9d
call   1030 <dEdX@plt>
movsd  (%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm1
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
xorpd  %xmm5,%xmm5
ucomisd %xmm5,%xmm0
jae    11c2 <RangeToX+0xb2>
movsd  0x8(%rsp),%xmm4
jmp    124a <RangeToX+0x13a>
xorpd  %xmm0,%xmm0
xorpd  %xmm5,%xmm5
movsd  0x8(%rsp),%xmm4
mulsd  %xmm4,%xmm1
subsd  %xmm1,%xmm3
ucomisd %xmm3,%xmm0
ja     1278 <RangeToX+0x168>
mulsd  0xe1e(%rip),%xmm1
addsd  %xmm3,%xmm1
mov    %ebp,%edi
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14d,%r9d
movsd  %xmm3,(%rsp)
movsd  %xmm5,0x20(%rsp)
call   1030 <dEdX@plt>
movsd  0x20(%rsp),%xmm5
movsd  0x8(%rsp),%xmm4
movsd  (%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm1
addsd  %xmm4,%xmm5
movapd %xmm3,%xmm0
subsd  %xmm2,%xmm0
ucomisd 0xddc(%rip),%xmm0
xorpd  %xmm0,%xmm0
jae    11d0 <RangeToX+0xc0>
subsd  %xmm3,%xmm2
mulsd  %xmm4,%xmm1
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
divsd  %xmm1,%xmm0
movsd  0xdb2(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm4,%xmm1
subsd  %xmm1,%xmm5
movapd %xmm5,%xmm0
jmp    1284 <RangeToX+0x174>
movsd  0xd90(%rip),%xmm3
movapd %xmm3,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @RangeToX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %7, double %8) {
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca i32*
%14 = alloca double*
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
store i32 %0, i32* %11
store double %1, double* %12
store i32* %2, i32** %13
store double* %3, double** %14
store double* %4, double** %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store double %7, double* %18
store double %8, double* %19
store double 0.000000e+00, double* %20
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %22
store double 0.000000e+00, double* %23
%24 = load double, double* %18
%25 = load double, double* %19
%26 = fcmp ole double %24, %25
br i1 %26, label %27, label %28
27: ; preds = %9
store double 0.000000e+00, double* %10
br label %102
28: ; preds = %9
%29 = load double, double* %18
store double %29, double* %21
%30 = load i32, i32* %11
%31 = load double, double* %12
%32 = load i32*, i32** %13
%33 = load double*, double** %14
%34 = load double*, double** %15
%35 = load i32, i32* %16
%36 = load i32, i32* %17
%37 = load double, double* %18
%38 = call double @dEdX(i32 %30, double %31, i32* %32, double* %33, double* %34, i32 %35, i32 %36, double %37)
store double %38, double* %20
%39 = load double, double* %20
%40 = fdiv double 1.000000e-01, %39
store double %40, double* %22
%41 = load i32, i32* %11
%42 = load double, double* %12
%43 = load i32*, i32** %13
%44 = load double*, double** %14
%45 = load double*, double** %15
%46 = load i32, i32* %16
%47 = load i32, i32* %17
%48 = load double, double* %18
%49 = load double, double* %20
%50 = load double, double* %22
%51 = fmul double %49, %50
%52 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %51, double %48)
%53 = call double @dEdX(i32 %41, double %42, i32* %43, double* %44, double* %45, i32 %46, i32 %47, double %52)
store double %53, double* %20
br label %54
54: ; preds = %67, %28
%55 = load double, double* %21
%56 = load double, double* %19
%57 = fsub double %55, %56
%58 = fcmp oge double %57, 0.000000e+00
br i1 %58, label %59, label %84
59: ; preds = %54
%60 = load double, double* %20
%61 = load double, double* %22
%62 = load double, double* %21
%63 = fneg double %60
%64 = call double @llvm.fmuladd.f64(double %63, double %61, double %62)
store double %64, double* %21
%65 = fcmp olt double %64, 0.000000e+00
br i1 %65, label %66, label %67
66: ; preds = %59
store double -1.000000e+00, double* %10
br label %102
67: ; preds = %59
%68 = load i32, i32* %11
%69 = load double, double* %12
%70 = load i32*, i32** %13
%71 = load double*, double** %14
%72 = load double*, double** %15
%73 = load i32, i32* %16
%74 = load i32, i32* %17
%75 = load double, double* %21
%76 = load double, double* %20
%77 = load double, double* %22
%78 = fmul double %76, %77
%79 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %78, double %75)
%80 = call double @dEdX(i32 %68, double %69, i32* %70, double* %71, double* %72, i32 %73, i32 %74, double %79)
store double %80, double* %20
%81 = load double, double* %22
%82 = load double, double* %23
%83 = fadd double %82, %81
store double %83, double* %23
br label %54
84: ; preds = %54
%85 = load double, double* %23
%86 = load double, double* %22
%87 = load double, double* %22
%88 = load double, double* %20
%89 = load double, double* %19
%90 = load double, double* %21
%91 = fsub double %89, %90
%92 = fneg double %91
%93 = call double @llvm.fmuladd.f64(double %87, double %88, double %92)
%94 = load double, double* %22
%95 = load double, double* %20
%96 = fmul double %94, %95
%97 = fdiv double %93, %96
%98 = fsub double 1.000000e+00, %97
%99 = fneg double %86
%100 = call double @llvm.fmuladd.f64(double %99, double %98, double %85)
store double %100, double* %23
%101 = load double, double* %23
store double %101, double* %10
br label %102
102: ; preds = %84, %66, %27
%103 = load double, double* %10
ret double %103
}

LLVM IR (-O2):
define double @RangeToX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %7, double %8) {
%10 = fcmp ugt double %7, %8
br i1 %10, label %11, label %45
11: ; preds = %9
%12 = tail call double @dEdX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %7)
%13 = fdiv double 1.000000e-01, %12
%14 = fmul double %12, %13
%15 = tail call double @llvm.fmuladd.f64(double %14, double -5.000000e-01, double %7)
%16 = tail call double @dEdX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %15)
%17 = fsub double %7, %8
%18 = fcmp ult double %17, 0.000000e+00
br i1 %18, label %33, label %19
19: ; preds = %11, %26
%20 = phi double [ %30, %26 ], [ 0.000000e+00, %11 ]
%21 = phi double [ %24, %26 ], [ %7, %11 ]
%22 = phi double [ %29, %26 ], [ %16, %11 ]
%23 = fneg double %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double %13, double %21)
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %45, label %26
26: ; preds = %19
%27 = fmul double %13, %22
%28 = tail call double @llvm.fmuladd.f64(double %27, double -5.000000e-01, double %24)
%29 = tail call double @dEdX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %28)
%30 = fadd double %13, %20
%31 = fsub double %24, %8
%32 = fcmp ult double %31, 0.000000e+00
br i1 %32, label %33, label %19
33: ; preds = %26, %11
%34 = phi double [ %16, %11 ], [ %29, %26 ]
%35 = phi double [ %7, %11 ], [ %24, %26 ]
%36 = phi double [ 0.000000e+00, %11 ], [ %30, %26 ]
%37 = fsub double %8, %35
%38 = fneg double %37
%39 = tail call double @llvm.fmuladd.f64(double %13, double %34, double %38)
%40 = fmul double %13, %34
%41 = fdiv double %39, %40
%42 = fsub double 1.000000e+00, %41
%43 = fneg double %13
%44 = tail call double @llvm.fmuladd.f64(double %43, double %42, double %36)
br label %45
45: ; preds = %19, %9, %33
%46 = phi double [ %44, %33 ], [ 0.000000e+00, %9 ], [ -1.000000e+00, %19 ]
ret double %46
}