#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,
                                         int /*<<< orphan*/ *, int *);
double electronic_density_effect(int, struct atomic_shell *, double);
int /*<<< orphan*/ free(struct atomic_shell *);
double pumas_electronic_density_effect(int n_elements, const double *Z,
                                       const double *A, const double *w,
                                       double I, double density, double gamma) {
  struct atomic_shell *shells;
  int n_shells;
  double w1 = 1;
  if (w == NULL)
    w = &w1;
  shells =
      atomic_shell_unpack(n_elements, Z, A, w, I, density, NULL, &n_shells);
  if (shells == NULL)
    return -1.;
  const double d = electronic_density_effect(n_shells, shells, gamma);
  free(shells);
  return d;
}


x86 assembly (clang, -O0):
<pumas_electronic_density_effect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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  0xea2(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1176 <pumas_electronic_density_effect+0x46>
lea    -0x58(%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
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x4c(%rbp),%r9
call   1050 <atomic_shell_unpack@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11be <pumas_electronic_density_effect+0x8e>
movsd  0xe54(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e7 <pumas_electronic_density_effect+0xb7>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
call   1040 <electronic_density_effect@plt>
movsd  %xmm0,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pumas_electronic_density_effect>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm2,0x8(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x18(%rsp)
test   %rcx,%rcx
lea    0x18(%rsp),%rax
cmove  %rax,%rcx
lea    0x14(%rsp),%r9
xor    %r8d,%r8d
call   1050 <atomic_shell_unpack@plt>
test   %rax,%rax
je     1193 <pumas_electronic_density_effect+0x63>
mov    %rax,%rbx
mov    0x14(%rsp),%edi
mov    %rax,%rsi
movsd  0x8(%rsp),%xmm0
call   1040 <electronic_density_effect@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
jmp    119b <pumas_electronic_density_effect+0x6b>
movsd  0xe65(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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