#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 */
int exp(double);
double fermi_dirac(double E, double EF, double kBTemp) {
  if (kBTemp == 0) {
    return (E <= EF) ? 1 : 0;
  } else {
    return 1 / (exp((E - EF) / kBTemp) + 1);
  }
}


x86 assembly (clang, -O0):
<fermi_dirac>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1165 <fermi_dirac+0x55>
jp     1165 <fermi_dirac+0x55>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
xor    %eax,%eax
mov    $0x1,%ecx
ucomisd %xmm1,%xmm0
cmovae %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    118f <fermi_dirac+0x7f>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <exp@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fermi_dirac>:
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm2
jne    112d <fermi_dirac+0x1d>
jp     112d <fermi_dirac+0x1d>
xor    %ecx,%ecx
ucomisd %xmm0,%xmm1
setae  %cl
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
ret
push   %rax
subsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1030 <exp@plt>
lea    0x1(%rax),%edx
add    $0x2,%eax
xor    %ecx,%ecx
cmp    $0x3,%eax
cmovb  %edx,%ecx
add    $0x8,%rsp
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
ret

LLVM IR (-O0):
define double @fermi_dirac(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%8 = load double, double* %7
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = load double, double* %5
%12 = load double, double* %6
%13 = fcmp ole double %11, %12
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
%16 = sitofp i32 %15 to double
store double %16, double* %4
br label %27
17: ; preds = %3
%18 = load double, double* %5
%19 = load double, double* %6
%20 = fsub double %18, %19
%21 = load double, double* %7
%22 = fdiv double %20, %21
%23 = call i32 @exp(double %22)
%24 = add nsw i32 %23, 1
%25 = sdiv i32 1, %24
%26 = sitofp i32 %25 to double
store double %26, double* %4
br label %27
27: ; preds = %17, %10
%28 = load double, double* %4
ret double %28
}

LLVM IR (-O2):
define double @fermi_dirac(double %0, double %1, double %2) {
%4 = fcmp oeq double %2, 0.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = fcmp ole double %0, %1
%7 = zext i1 %6 to i32
br label %16
8: ; preds = %3
%9 = fsub double %0, %1
%10 = fdiv double %9, %2
%11 = tail call i32 @exp(double %10)
%12 = add nsw i32 %11, 1
%13 = add i32 %11, 2
%14 = icmp ult i32 %13, 3
%15 = select i1 %14, i32 %12, i32 0
br label %16
16: ; preds = %8, %5
%17 = phi i32 [ %7, %5 ], [ %15, %8 ]
%18 = sitofp i32 %17 to double
ret double %18
}