; LLVM IR from gem5/gem5 :: ext/dsent/model/optical/RingDetector.ll (ZN5DSENT12RingDetector14calcInvNormCdfEd)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN5DSENT12RingDetector14calcInvNormCdfEd(ptr noundef nonnull align 8 dereferenceable(336) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 20, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 2.000000e+01, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = load double, ptr %6, align 8, !tbaa !9
  store double %11, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %37, %2
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !11
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %40

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %18 = load double, ptr %7, align 8, !tbaa !9
  %19 = call double @sqrt(double noundef 2.000000e+00) #3
  %20 = fdiv double %18, %19
  %21 = call double @erfc(double noundef %20) #3
  %22 = fmul double 5.000000e-01, %21
  store double %22, ptr %9, align 8, !tbaa !9
  %23 = load double, ptr %9, align 8, !tbaa !9
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = fcmp ogt double %23, %24
  br i1 %25, label %26, label %30

26:                                               ; preds = %17
  %27 = load double, ptr %6, align 8, !tbaa !9
  %28 = load double, ptr %7, align 8, !tbaa !9
  %29 = fadd double %28, %27
  store double %29, ptr %7, align 8, !tbaa !9
  br label %34

30:                                               ; preds = %17
  %31 = load double, ptr %6, align 8, !tbaa !9
  %32 = load double, ptr %7, align 8, !tbaa !9
  %33 = fsub double %32, %31
  store double %33, ptr %7, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %30, %26
  %35 = load double, ptr %6, align 8, !tbaa !9
  %36 = fmul double %35, 5.000000e-01
  store double %36, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %37

37:                                               ; preds = %34
  %38 = load i32, ptr %8, align 4, !tbaa !11
  %39 = add i32 %38, 1
  store i32 %39, ptr %8, align 4, !tbaa !11
  br label %12, !llvm.loop !13

40:                                               ; preds = %16
  %41 = load double, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret double %41
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind
declare double @erfc(double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN5DSENT12RingDetector14calcInvNormCdfEd(ptr nocapture noundef nonnull readnone align 8 dereferenceable(336) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call double @erfc(double noundef 0x402C48C6001F0ABF) #2
  %4 = fmul double %3, 5.000000e-01
  %5 = fcmp ogt double %4, %1
  %.1 = select i1 %5, double 4.000000e+01, double 0.000000e+00
  %6 = fdiv double %.1, 0x3FF6A09E667F3BCD
  %7 = tail call double @erfc(double noundef %6) #2
  %8 = fmul double %7, 5.000000e-01
  %9 = fcmp ogt double %8, %1
  %.1.p.1 = select i1 %9, double 1.000000e+01, double -1.000000e+01
  %.1.1 = fadd double %.1, %.1.p.1
  %10 = fdiv double %.1.1, 0x3FF6A09E667F3BCD
  %11 = tail call double @erfc(double noundef %10) #2
  %12 = fmul double %11, 5.000000e-01
  %13 = fcmp ogt double %12, %1
  %.1.p.2 = select i1 %13, double 5.000000e+00, double -5.000000e+00
  %.1.2 = fadd double %.1.1, %.1.p.2
  %14 = fdiv double %.1.2, 0x3FF6A09E667F3BCD
  %15 = tail call double @erfc(double noundef %14) #2
  %16 = fmul double %15, 5.000000e-01
  %17 = fcmp ogt double %16, %1
  %.1.p.3 = select i1 %17, double 2.500000e+00, double -2.500000e+00
  %.1.3 = fadd double %.1.2, %.1.p.3
  %18 = fdiv double %.1.3, 0x3FF6A09E667F3BCD
  %19 = tail call double @erfc(double noundef %18) #2
  %20 = fmul double %19, 5.000000e-01
  %21 = fcmp ogt double %20, %1
  %.1.p.4 = select i1 %21, double 1.250000e+00, double -1.250000e+00
  %.1.4 = fadd double %.1.3, %.1.p.4
  %22 = fdiv double %.1.4, 0x3FF6A09E667F3BCD
  %23 = tail call double @erfc(double noundef %22) #2
  %24 = fmul double %23, 5.000000e-01
  %25 = fcmp ogt double %24, %1
  %.1.p.5 = select i1 %25, double 6.250000e-01, double -6.250000e-01
  %.1.5 = fadd double %.1.4, %.1.p.5
  %26 = fdiv double %.1.5, 0x3FF6A09E667F3BCD
  %27 = tail call double @erfc(double noundef %26) #2
  %28 = fmul double %27, 5.000000e-01
  %29 = fcmp ogt double %28, %1
  %.1.p.6 = select i1 %29, double 3.125000e-01, double -3.125000e-01
  %.1.6 = fadd double %.1.5, %.1.p.6
  %30 = fdiv double %.1.6, 0x3FF6A09E667F3BCD
  %31 = tail call double @erfc(double noundef %30) #2
  %32 = fmul double %31, 5.000000e-01
  %33 = fcmp ogt double %32, %1
  %.1.p.7 = select i1 %33, double 1.562500e-01, double -1.562500e-01
  %.1.7 = fadd double %.1.6, %.1.p.7
  %34 = fdiv double %.1.7, 0x3FF6A09E667F3BCD
  %35 = tail call double @erfc(double noundef %34) #2
  %36 = fmul double %35, 5.000000e-01
  %37 = fcmp ogt double %36, %1
  %.1.p.8 = select i1 %37, double 7.812500e-02, double -7.812500e-02
  %.1.8 = fadd double %.1.7, %.1.p.8
  %38 = fdiv double %.1.8, 0x3FF6A09E667F3BCD
  %39 = tail call double @erfc(double noundef %38) #2
  %40 = fmul double %39, 5.000000e-01
  %41 = fcmp ogt double %40, %1
  %.1.p.9 = select i1 %41, double 3.906250e-02, double -3.906250e-02
  %.1.9 = fadd double %.1.8, %.1.p.9
  %42 = fdiv double %.1.9, 0x3FF6A09E667F3BCD
  %43 = tail call double @erfc(double noundef %42) #2
  %44 = fmul double %43, 5.000000e-01
  %45 = fcmp ogt double %44, %1
  %.1.p.10 = select i1 %45, double 0x3F94000000000000, double 0xBF94000000000000
  %.1.10 = fadd double %.1.9, %.1.p.10
  %46 = fdiv double %.1.10, 0x3FF6A09E667F3BCD
  %47 = tail call double @erfc(double noundef %46) #2
  %48 = fmul double %47, 5.000000e-01
  %49 = fcmp ogt double %48, %1
  %.1.p.11 = select i1 %49, double 0x3F84000000000000, double 0xBF84000000000000
  %.1.11 = fadd double %.1.10, %.1.p.11
  %50 = fdiv double %.1.11, 0x3FF6A09E667F3BCD
  %51 = tail call double @erfc(double noundef %50) #2
  %52 = fmul double %51, 5.000000e-01
  %53 = fcmp ogt double %52, %1
  %.1.p.12 = select i1 %53, double 0x3F74000000000000, double 0xBF74000000000000
  %.1.12 = fadd double %.1.11, %.1.p.12
  %54 = fdiv double %.1.12, 0x3FF6A09E667F3BCD
  %55 = tail call double @erfc(double noundef %54) #2
  %56 = fmul double %55, 5.000000e-01
  %57 = fcmp ogt double %56, %1
  %.1.p.13 = select i1 %57, double 0x3F64000000000000, double 0xBF64000000000000
  %.1.13 = fadd double %.1.12, %.1.p.13
  %58 = fdiv double %.1.13, 0x3FF6A09E667F3BCD
  %59 = tail call double @erfc(double noundef %58) #2
  %60 = fmul double %59, 5.000000e-01
  %61 = fcmp ogt double %60, %1
  %.1.p.14 = select i1 %61, double 0x3F54000000000000, double 0xBF54000000000000
  %.1.14 = fadd double %.1.13, %.1.p.14
  %62 = fdiv double %.1.14, 0x3FF6A09E667F3BCD
  %63 = tail call double @erfc(double noundef %62) #2
  %64 = fmul double %63, 5.000000e-01
  %65 = fcmp ogt double %64, %1
  %.1.p.15 = select i1 %65, double 0x3F44000000000000, double 0xBF44000000000000
  %.1.15 = fadd double %.1.14, %.1.p.15
  %66 = fdiv double %.1.15, 0x3FF6A09E667F3BCD
  %67 = tail call double @erfc(double noundef %66) #2
  %68 = fmul double %67, 5.000000e-01
  %69 = fcmp ogt double %68, %1
  %.1.p.16 = select i1 %69, double 0x3F34000000000000, double 0xBF34000000000000
  %.1.16 = fadd double %.1.15, %.1.p.16
  %70 = fdiv double %.1.16, 0x3FF6A09E667F3BCD
  %71 = tail call double @erfc(double noundef %70) #2
  %72 = fmul double %71, 5.000000e-01
  %73 = fcmp ogt double %72, %1
  %.1.p.17 = select i1 %73, double 0x3F24000000000000, double 0xBF24000000000000
  %.1.17 = fadd double %.1.16, %.1.p.17
  %74 = fdiv double %.1.17, 0x3FF6A09E667F3BCD
  %75 = tail call double @erfc(double noundef %74) #2
  %76 = fmul double %75, 5.000000e-01
  %77 = fcmp ogt double %76, %1
  %.1.p.18 = select i1 %77, double 0x3F14000000000000, double 0xBF14000000000000
  %.1.18 = fadd double %.1.17, %.1.p.18
  %78 = fdiv double %.1.18, 0x3FF6A09E667F3BCD
  %79 = tail call double @erfc(double noundef %78) #2
  %80 = fmul double %79, 5.000000e-01
  %81 = fcmp ogt double %80, %1
  %.1.p.19 = select i1 %81, double 0x3F04000000000000, double 0xBF04000000000000
  %.1.19 = fadd double %.1.18, %.1.p.19
  ret double %.1.19
}

; Function Attrs: nounwind
declare double @erfc(double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass