; LLVM IR from jingweizhanghuai/Morn :: src/math (morn_math_common)

; 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"

@.str = external hidden unnamed_addr constant [83 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mVariance = external hidden unnamed_addr constant [10 x i8], align 1

; 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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @mVariance(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store float 0.000000e+00, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  br label %13

13:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %32, label %16

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = icmp eq i64 %18, -1
  br i1 %19, label %32, label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp sle i32 %21, 0
  br i1 %22, label %32, label %23

23:                                               ; preds = %20
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %30, label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = ptrtoint ptr %27 to i64
  %29 = icmp eq i64 %28, -1
  br label %30

30:                                               ; preds = %26, %23
  %31 = phi i1 [ true, %23 ], [ %29, %26 ]
  br label %32

32:                                               ; preds = %30, %20, %16, %13
  %33 = phi i1 [ true, %20 ], [ true, %16 ], [ true, %13 ], [ %31, %30 ]
  %34 = zext i1 %33 to i32
  store i32 %34, ptr %12, align 4, !tbaa !9
  %35 = load i32, ptr %12, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  %38 = load i32, ptr %12, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %38, i32 noundef -1, ptr noundef @.str, i32 noundef 312, ptr noundef @__FUNCTION__.mVariance, ptr noundef @.str.1)
  br label %39

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

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %66, %41
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %46, label %69

46:                                               ; preds = %42
  %47 = load float, ptr %9, align 4, !tbaa !11
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds float, ptr %48, i64 %50
  %52 = load float, ptr %51, align 4, !tbaa !11
  %53 = fadd float %47, %52
  store float %53, ptr %9, align 4, !tbaa !11
  %54 = load float, ptr %10, align 4, !tbaa !11
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds float, ptr %55, i64 %57
  %59 = load float, ptr %58, align 4, !tbaa !11
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %60, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = call float @llvm.fmuladd.f32(float %59, float %64, float %54)
  store float %65, ptr %10, align 4, !tbaa !11
  br label %66

66:                                               ; preds = %46
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %11, align 4, !tbaa !9
  br label %42, !llvm.loop !13

69:                                               ; preds = %42
  %70 = load float, ptr %9, align 4, !tbaa !11
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = sitofp i32 %71 to float
  %73 = fdiv float %70, %72
  store float %73, ptr %9, align 4, !tbaa !11
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = icmp eq ptr %74, null
  br i1 %75, label %83, label %76

76:                                               ; preds = %69
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = ptrtoint ptr %77 to i64
  %79 = icmp eq i64 %78, -1
  br i1 %79, label %83, label %80

80:                                               ; preds = %76
  %81 = load float, ptr %9, align 4, !tbaa !11
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  store float %81, ptr %82, align 4, !tbaa !11
  br label %83

83:                                               ; preds = %80, %76, %69
  %84 = load float, ptr %10, align 4, !tbaa !11
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = sitofp i32 %85 to float
  %87 = fdiv float %84, %86
  %88 = load float, ptr %9, align 4, !tbaa !11
  %89 = load float, ptr %9, align 4, !tbaa !11
  %90 = fneg float %88
  %91 = call float @llvm.fmuladd.f32(float %90, float %89, float %87)
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  store float %91, ptr %92, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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"

@.str = external hidden unnamed_addr constant [83 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mVariance = external hidden unnamed_addr constant [10 x i8], align 1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @mVariance(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = icmp slt i32 %1, 1
  br i1 %5, label %7, label %switch.early.test

switch.early.test:                                ; preds = %4
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %6 [
    i64 -1, label %.thread48
    i64 0, label %.thread48
  ]

6:                                                ; preds = %switch.early.test
  %magicptr40 = ptrtoint ptr %3 to i64
  switch i64 %magicptr40, label %.lr.ph.preheader [
    i64 -1, label %.thread48
    i64 0, label %.thread48
  ]

.thread48:                                        ; preds = %switch.early.test, %switch.early.test, %6, %6
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 312, ptr noundef nonnull @__FUNCTION__.mVariance, ptr noundef nonnull @.str.1) #3
  br label %.lr.ph.preheader

7:                                                ; preds = %4
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 312, ptr noundef nonnull @__FUNCTION__.mVariance, ptr noundef nonnull @.str.1) #3
  br label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6, %.thread48
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %8 = icmp ult i32 %1, 4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.043 = phi float [ 0.000000e+00, %.lr.ph.preheader.new ], [ %23, %.lr.ph ]
  %.03641 = phi float [ 0.000000e+00, %.lr.ph.preheader.new ], [ %24, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %9 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = fadd float %.043, %10
  %12 = tail call float @llvm.fmuladd.f32(float %10, float %10, float %.03641)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next
  %14 = load float, ptr %13, align 4, !tbaa !5
  %15 = fadd float %11, %14
  %16 = tail call float @llvm.fmuladd.f32(float %14, float %14, float %12)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %17 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.1
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = fadd float %15, %18
  %20 = tail call float @llvm.fmuladd.f32(float %18, float %18, float %16)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %21 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.2
  %22 = load float, ptr %21, align 4, !tbaa !5
  %23 = fadd float %19, %22
  %24 = tail call float @llvm.fmuladd.f32(float %22, float %22, float %20)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa51.ph = phi float [ poison, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %.lcssa.ph = phi float [ poison, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.043.unr = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %.03641.unr = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.043.epil = phi float [ %27, %.lr.ph.epil ], [ %.043.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.03641.epil = phi float [ %28, %.lr.ph.epil ], [ %.03641.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %25 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.epil
  %26 = load float, ptr %25, align 4, !tbaa !5
  %27 = fadd float %.043.epil, %26
  %28 = tail call float @llvm.fmuladd.f32(float %26, float %26, float %.03641.epil)
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %7
  %.036.lcssa = phi float [ 0.000000e+00, %7 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %28, %.lr.ph.epil ]
  %.0.lcssa = phi float [ 0.000000e+00, %7 ], [ %.lcssa51.ph, %._crit_edge.loopexit.unr-lcssa ], [ %27, %.lr.ph.epil ]
  %29 = sitofp i32 %1 to float
  %30 = fdiv float %.0.lcssa, %29
  %magicptr39 = ptrtoint ptr %2 to i64
  switch i64 %magicptr39, label %31 [
    i64 -1, label %32
    i64 0, label %32
  ]

31:                                               ; preds = %._crit_edge
  store float %30, ptr %2, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %._crit_edge, %._crit_edge, %31
  %33 = fdiv float %.036.lcssa, %29
  %34 = fneg float %30
  %35 = tail call float @llvm.fmuladd.f32(float %34, float %30, float %33)
  store float %35, ptr %3, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

attributes #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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass