#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 ELossPeak(int ZP, double MP, int ZT[], double MT[], double CT[],
                 int NTarEl, int IsGas, double TT, double E) {
  double EIn = 0.0, dEdX_ = 0.0, dX = 0.0, X = 0.0, dEMax = 0.0;
  EIn = E;
  dEdX_ = dEdX(ZP, MP, ZT, MT, CT, NTarEl, IsGas, EIn);
  dX = 0.1 / dEdX_;
  dEMax = dEdX_;
  while ((TT - X - dX) >= 0) {
    if ((E = E - (dEdX_ * dX)) < 0)
      return dEMax;
    X = X + dX;
    dEdX_ = dEdX(ZP, MP, ZT, MT, CT, NTarEl, IsGas, E);
    if (dEdX_ > dEMax)
      dEMax = dEdX_;
  };
  return (dEMax);
}


x86 assembly (clang, -O0):
<ELossPeak>:
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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%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  -0x50(%rbp),%xmm1
call   1030 <dEdX@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  0xe5d(%rip),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     127b <ELossPeak+0x16b>
movsd  -0x48(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1222 <ELossPeak+0x112>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1285 <ELossPeak+0x175>
movsd  -0x68(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%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  -0x48(%rbp),%xmm1
call   1030 <dEdX@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
ucomisd -0x70(%rbp),%xmm0
jbe    1276 <ELossPeak+0x166>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    11b7 <ELossPeak+0xa7>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ELossPeak>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x8(%rsp)
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
movsd  %xmm0,0x20(%rsp)
movsd  %xmm2,0x10(%rsp)
movapd %xmm2,%xmm1
call   1030 <dEdX@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm0,%xmm2
movsd  0xea4(%rip),%xmm4
divsd  %xmm0,%xmm4
movapd %xmm3,%xmm0
subsd  %xmm4,%xmm0
xorpd  %xmm5,%xmm5
ucomisd %xmm5,%xmm0
jae    117b <ELossPeak+0x6b>
movapd %xmm2,%xmm1
jmp    1208 <ELossPeak+0xf8>
xorpd  %xmm6,%xmm6
movapd %xmm2,%xmm0
movsd  %xmm4,0x18(%rsp)
nopl   0x0(%rax)
mulsd  %xmm4,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
ucomisd %xmm1,%xmm5
ja     1172 <ELossPeak+0x62>
addsd  %xmm4,%xmm6
movsd  %xmm6,0x30(%rsp)
mov    %ebp,%edi
movsd  0x20(%rsp),%xmm0
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
mov    %r14d,%r9d
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x28(%rsp)
call   1030 <dEdX@plt>
movsd  0x30(%rsp),%xmm6
xorpd  %xmm5,%xmm5
movsd  0x18(%rsp),%xmm4
movsd  0x8(%rsp),%xmm2
movapd %xmm0,%xmm1
maxsd  0x28(%rsp),%xmm1
subsd  %xmm6,%xmm2
subsd  %xmm4,%xmm2
ucomisd %xmm5,%xmm2
movapd %xmm1,%xmm2
jae    1190 <ELossPeak+0x80>
movapd %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @ELossPeak(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
%24 = 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
store double 0.000000e+00, double* %24
%25 = load double, double* %19
store double %25, double* %20
%26 = load i32, i32* %11
%27 = load double, double* %12
%28 = load i32*, i32** %13
%29 = load double*, double** %14
%30 = load double*, double** %15
%31 = load i32, i32* %16
%32 = load i32, i32* %17
%33 = load double, double* %20
%34 = call double @dEdX(i32 %26, double %27, i32* %28, double* %29, double* %30, i32 %31, i32 %32, double %33)
store double %34, double* %21
%35 = load double, double* %21
%36 = fdiv double 1.000000e-01, %35
store double %36, double* %22
%37 = load double, double* %21
store double %37, double* %24
br label %38
38: ; preds = %72, %9
%39 = load double, double* %18
%40 = load double, double* %23
%41 = fsub double %39, %40
%42 = load double, double* %22
%43 = fsub double %41, %42
%44 = fcmp oge double %43, 0.000000e+00
br i1 %44, label %45, label %73
45: ; preds = %38
%46 = load double, double* %19
%47 = load double, double* %21
%48 = load double, double* %22
%49 = fneg double %47
%50 = call double @llvm.fmuladd.f64(double %49, double %48, double %46)
store double %50, double* %19
%51 = fcmp olt double %50, 0.000000e+00
br i1 %51, label %52, label %54
52: ; preds = %45
%53 = load double, double* %24
store double %53, double* %10
br label %75
54: ; preds = %45
%55 = load double, double* %23
%56 = load double, double* %22
%57 = fadd double %55, %56
store double %57, double* %23
%58 = load i32, i32* %11
%59 = load double, double* %12
%60 = load i32*, i32** %13
%61 = load double*, double** %14
%62 = load double*, double** %15
%63 = load i32, i32* %16
%64 = load i32, i32* %17
%65 = load double, double* %19
%66 = call double @dEdX(i32 %58, double %59, i32* %60, double* %61, double* %62, i32 %63, i32 %64, double %65)
store double %66, double* %21
%67 = load double, double* %21
%68 = load double, double* %24
%69 = fcmp ogt double %67, %68
br i1 %69, label %70, label %72
70: ; preds = %54
%71 = load double, double* %21
store double %71, double* %24
br label %72
72: ; preds = %70, %54
br label %38
73: ; preds = %38
%74 = load double, double* %24
store double %74, double* %10
br label %75
75: ; preds = %73, %52
%76 = load double, double* %10
ret double %76
}

LLVM IR (-O2):
define double @ELossPeak(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %7, double %8) {
%10 = tail call double @dEdX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %8)
%11 = fdiv double 1.000000e-01, %10
%12 = fsub double %7, %11
%13 = fcmp ult double %12, 0.000000e+00
br i1 %13, label %30, label %14
14: ; preds = %9, %22
%15 = phi double [ %26, %22 ], [ %10, %9 ]
%16 = phi double [ %23, %22 ], [ 0.000000e+00, %9 ]
%17 = phi double [ %24, %22 ], [ %10, %9 ]
%18 = phi double [ %20, %22 ], [ %8, %9 ]
%19 = fneg double %17
%20 = tail call double @llvm.fmuladd.f64(double %19, double %11, double %18)
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %30, label %22
22: ; preds = %14
%23 = fadd double %11, %16
%24 = tail call double @dEdX(i32 %0, double %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, double %20)
%25 = fcmp ogt double %24, %15
%26 = select i1 %25, double %24, double %15
%27 = fsub double %7, %23
%28 = fsub double %27, %11
%29 = fcmp ult double %28, 0.000000e+00
br i1 %29, label %30, label %14
30: ; preds = %14, %22, %9
%31 = phi double [ %10, %9 ], [ %26, %22 ], [ %15, %14 ]
ret double %31
}