#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 */
struct atomic_shell {
  int dummy;
};

/* Variables and functions */
struct atomic_shell *atomic_shell_unpack(int, double const *, double const *,
                                         double const *, double, double,
                                         double *, int *);
double electronic_energy_loss(double, double, int, struct atomic_shell *,
                              double, double, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(struct atomic_shell *);
double pumas_electronic_stopping_power(int n_elements, const double *Z,
                                       const double *A, const double *w,
                                       double I, double density, double mass,
                                       double energy) {
  struct atomic_shell *shells;
  int n_shells;
  double w1 = 1;
  if (w == NULL)
    w = &w1;
  double ZoA;
  shells =
      atomic_shell_unpack(n_elements, Z, A, w, I, density, &ZoA, &n_shells);
  if (shells == NULL)
    return -1.;
  const double d =
      electronic_energy_loss(ZoA, I, n_shells, shells, mass, energy, NULL);
  free(shells);
  return d;
}


x86 assembly (clang, -O0):
<pumas_electronic_stopping_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
movsd  %xmm2,-0x40(%rbp)
movsd  %xmm3,-0x48(%rbp)
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117b <pumas_electronic_stopping_power+0x4b>
lea    -0x60(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
lea    -0x68(%rbp),%r8
lea    -0x54(%rbp),%r9
call   1050 <atomic_shell_unpack@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    11c2 <pumas_electronic_stopping_power+0x92>
movsd  0xe50(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11fe <pumas_electronic_stopping_power+0xce>
movsd  -0x68(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm3
xor    %eax,%eax
mov    %eax,%edx
call   1040 <electronic_energy_loss@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pumas_electronic_stopping_power>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm3,(%rsp)
movsd  %xmm2,0x18(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x28(%rsp)
test   %rcx,%rcx
lea    0x28(%rsp),%rax
cmove  %rax,%rcx
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
movsd  %xmm0,0x10(%rsp)
call   1050 <atomic_shell_unpack@plt>
test   %rax,%rax
je     11b1 <pumas_electronic_stopping_power+0x81>
mov    %rax,%rbx
movsd  0x20(%rsp),%xmm0
mov    0xc(%rsp),%edi
movsd  0x10(%rsp),%xmm1
mov    %rax,%rsi
movsd  0x18(%rsp),%xmm2
movsd  (%rsp),%xmm3
xor    %edx,%edx
call   1040 <electronic_energy_loss@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
jmp    11b9 <pumas_electronic_stopping_power+0x89>
movsd  0xe47(%rip),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.atomic_shell = type { i32 }
define double @pumas_electronic_stopping_power(i32 %0, double* %1, double* %2, double* %3, double %4, double %5, double %6, double %7) {
%9 = alloca double
%10 = alloca i32
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca %struct.atomic_shell*
%19 = alloca i32
%20 = alloca double
%21 = alloca double
%22 = alloca double
store i32 %0, i32* %10
store double* %1, double** %11
store double* %2, double** %12
store double* %3, double** %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store double %7, double* %17
store double 1.000000e+00, double* %20
%23 = load double*, double** %13
%24 = icmp eq double* %23, null
br i1 %24, label %25, label %26
25: ; preds = %8
store double* %20, double** %13
br label %26
26: ; preds = %25, %8
%27 = load i32, i32* %10
%28 = load double*, double** %11
%29 = load double*, double** %12
%30 = load double*, double** %13
%31 = load double, double* %14
%32 = load double, double* %15
%33 = call %struct.atomic_shell* @atomic_shell_unpack(i32 %27, double* %28, double* %29, double* %30, double %31, double %32, double* %21, i32* %19)
store %struct.atomic_shell* %33, %struct.atomic_shell** %18
%34 = load %struct.atomic_shell*, %struct.atomic_shell** %18
%35 = icmp eq %struct.atomic_shell* %34, null
br i1 %35, label %36, label %37
36: ; preds = %26
store double -1.000000e+00, double* %9
br label %48
37: ; preds = %26
%38 = load double, double* %21
%39 = load double, double* %14
%40 = load i32, i32* %19
%41 = load %struct.atomic_shell*, %struct.atomic_shell** %18
%42 = load double, double* %16
%43 = load double, double* %17
%44 = call double @electronic_energy_loss(double %38, double %39, i32 %40, %struct.atomic_shell* %41, double %42, double %43, i32* null)
store double %44, double* %22
%45 = load %struct.atomic_shell*, %struct.atomic_shell** %18
%46 = call i32 @free(%struct.atomic_shell* %45)
%47 = load double, double* %22
store double %47, double* %9
br label %48
48: ; preds = %37, %36
%49 = load double, double* %9
ret double %49
}

LLVM IR (-O2):
%struct.atomic_shell = type { i32 }
define double @pumas_electronic_stopping_power(i32 %0, double* %1, double* %2, double* %3, double %4, double %5, double %6, double %7) {
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = bitcast i32* %9 to i8*
%13 = bitcast double* %10 to i8*
store double 1.000000e+00, double* %10
%14 = icmp eq double* %3, null
%15 = select i1 %14, double* %10, double* %3
%16 = bitcast double* %11 to i8*
%17 = call %struct.atomic_shell* @atomic_shell_unpack(i32 %0, double* %1, double* %2, double* %15, double %4, double %5, double* %11, i32* %9)
%18 = icmp eq %struct.atomic_shell* %17, null
br i1 %18, label %24, label %19
19: ; preds = %8
%20 = load double, double* %11
%21 = load i32, i32* %9
%22 = call double @electronic_energy_loss(double %20, double %4, i32 %21, %struct.atomic_shell* %17, double %6, double %7, i32* null)
%23 = call i32 @free(%struct.atomic_shell* %17)
br label %24
24: ; preds = %8, %19
%25 = phi double [ %22, %19 ], [ -1.000000e+00, %8 ]
ret double %25
}