#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 */
float erf1(float);
float erfinv(float);
float sqrt(int);
float pe_gauss(float mu0, float sigma0, float mu1, float sigma1, float res) {
  float p1, p2;
  float phiinv;
  float aux;
  float y;
  float phiy;
  float perror;
  float pfa;
  float pe = 100;
  float pcd;
  p1 = sigma0 / sigma1;
  p2 = ((mu1 - mu0) / sigma1) / sqrt(2);
  for (pfa = 0; pfa <= 1; pfa += res) {
    aux = 2 * (1 - pfa) - 1;
    phiinv = erfinv(aux);
    y = p1 * phiinv - p2;
    phiy = erf1(y);
    pcd = 1 - 0.5 * (1 + phiy);
    perror = (pfa + (1 - pcd)) / 2;
    if (perror < pe)
      pe = perror;
  }
  return pe;
}


x86 assembly (clang, -O0):
<pe_gauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  %xmm4,-0x14(%rbp)
movss  0xea7(%rip),%xmm0
movss  %xmm0,-0x38(%rbp)
movss  -0x8(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
mov    $0x2,%edi
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x40(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  0xe58(%rip),%xmm0
ucomiss -0x34(%rbp),%xmm0
jb     12ae <pe_gauss+0x17e>
movss  0xe46(%rip),%xmm0
subss  -0x34(%rbp),%xmm0
addss  %xmm0,%xmm0
movss  0xe3d(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <erfinv@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x18(%rbp),%xmm0
movss  -0x20(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
call   1040 <erf1@plt>
movss  %xmm0,-0x2c(%rbp)
movss  0xddd(%rip),%xmm0
addss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdd8(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdd4(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x34(%rbp),%xmm0
movss  0xda6(%rip),%xmm1
subss  -0x3c(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xd99(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm1
movss  -0x38(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1295 <pe_gauss+0x165>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x38(%rbp)
jmp    129a <pe_gauss+0x16a>
movss  -0x14(%rbp),%xmm0
addss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
jmp    11a4 <pe_gauss+0x74>
movss  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_gauss>:
sub    $0x28,%rsp
movss  %xmm4,0x8(%rsp)
movss  %xmm3,(%rsp)
divss  %xmm3,%xmm1
movss  %xmm1,0x4(%rsp)
subss  %xmm0,%xmm2
movaps %xmm2,0x10(%rsp)
mov    $0x2,%edi
call   1050 <sqrt@plt>
movaps 0x10(%rsp),%xmm1
xorps  0xe98(%rip),%xmm1
divss  (%rsp),%xmm1
divss  %xmm0,%xmm1
movaps %xmm1,0x10(%rsp)
movss  0xe92(%rip),%xmm0
xorps  %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  %xmm1,(%rsp)
movss  %xmm0,0xc(%rsp)
movss  0xe71(%rip),%xmm0
subss  %xmm1,%xmm0
addss  %xmm0,%xmm0
addss  0xe65(%rip),%xmm0
call   1030 <erfinv@plt>
mulss  0x4(%rsp),%xmm0
addss  0x10(%rsp),%xmm0
call   1040 <erf1@plt>
movss  0xe43(%rip),%xmm2
addss  %xmm2,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe3f(%rip),%xmm0
addsd  0xe3f(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsd2ss %xmm0,%xmm1
movaps %xmm2,%xmm0
subss  %xmm1,%xmm0
movss  (%rsp),%xmm1
addss  %xmm1,%xmm0
mulss  0xe14(%rip),%xmm0
minss  0xc(%rsp),%xmm0
addss  0x8(%rsp),%xmm1
ucomiss %xmm1,%xmm2
jae    1190 <pe_gauss+0x60>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define float @pe_gauss(float %0, float %1, float %2, float %3, float %4) {
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca float
%16 = alloca float
%17 = alloca float
%18 = alloca float
%19 = alloca float
%20 = alloca float
store float %0, float* %6
store float %1, float* %7
store float %2, float* %8
store float %3, float* %9
store float %4, float* %10
store float 1.000000e+02, float* %19
%21 = load float, float* %7
%22 = load float, float* %9
%23 = fdiv float %21, %22
store float %23, float* %11
%24 = load float, float* %8
%25 = load float, float* %6
%26 = fsub float %24, %25
%27 = load float, float* %9
%28 = fdiv float %26, %27
%29 = call float @sqrt(i32 2)
%30 = fdiv float %28, %29
store float %30, float* %12
store float 0.000000e+00, float* %18
br label %31
31: ; preds = %63, %5
%32 = load float, float* %18
%33 = fcmp ole float %32, 1.000000e+00
br i1 %33, label %34, label %67
34: ; preds = %31
%35 = load float, float* %18
%36 = fsub float 1.000000e+00, %35
%37 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %36, float -1.000000e+00)
store float %37, float* %14
%38 = load float, float* %14
%39 = call float @erfinv(float %38)
store float %39, float* %13
%40 = load float, float* %11
%41 = load float, float* %13
%42 = load float, float* %12
%43 = fneg float %42
%44 = call float @llvm.fmuladd.f32(float %40, float %41, float %43)
store float %44, float* %15
%45 = load float, float* %15
%46 = call float @erf1(float %45)
store float %46, float* %16
%47 = load float, float* %16
%48 = fadd float 1.000000e+00, %47
%49 = fpext float %48 to double
%50 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %49, double 1.000000e+00)
%51 = fptrunc double %50 to float
store float %51, float* %20
%52 = load float, float* %18
%53 = load float, float* %20
%54 = fsub float 1.000000e+00, %53
%55 = fadd float %52, %54
%56 = fdiv float %55, 2.000000e+00
store float %56, float* %17
%57 = load float, float* %17
%58 = load float, float* %19
%59 = fcmp olt float %57, %58
br i1 %59, label %60, label %62
60: ; preds = %34
%61 = load float, float* %17
store float %61, float* %19
br label %62
62: ; preds = %60, %34
br label %63
63: ; preds = %62
%64 = load float, float* %10
%65 = load float, float* %18
%66 = fadd float %65, %64
store float %66, float* %18
br label %31
67: ; preds = %31
%68 = load float, float* %19
ret float %68
}

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