; 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
@__FUNCTION__.mMean = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 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

; Function Attrs: nounwind uwtable
define dso_local void @mMean(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %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 i32, align 4
  %11 = 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) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br label %12

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

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

19:                                               ; preds = %15
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp sle i32 %20, 0
  br label %22

22:                                               ; preds = %19, %15, %12
  %23 = phi i1 [ true, %15 ], [ true, %12 ], [ %21, %19 ]
  %24 = zext i1 %23 to i32
  store i32 %24, ptr %11, align 4, !tbaa !9
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  %28 = load i32, ptr %11, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %28, i32 noundef -1, ptr noundef @.str, i32 noundef 297, ptr noundef @__FUNCTION__.mMean, ptr noundef @.str.1)
  br label %29

29:                                               ; preds = %27, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %44, %31
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %47

36:                                               ; preds = %32
  %37 = load float, ptr %9, align 4, !tbaa !11
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %38, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !11
  %43 = fadd float %37, %42
  store float %43, ptr %9, align 4, !tbaa !11
  br label %44

44:                                               ; preds = %36
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %10, align 4, !tbaa !9
  br label %32, !llvm.loop !13

47:                                               ; preds = %32
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %57, label %50

50:                                               ; preds = %47
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = ptrtoint ptr %51 to i64
  %53 = icmp eq i64 %52, -1
  br i1 %53, label %57, label %54

54:                                               ; preds = %50
  %55 = load float, ptr %9, align 4, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store float %55, ptr %56, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %54, %50, %47
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %70, label %60

60:                                               ; preds = %57
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = ptrtoint ptr %61 to i64
  %63 = icmp eq i64 %62, -1
  br i1 %63, label %70, label %64

64:                                               ; preds = %60
  %65 = load float, ptr %9, align 4, !tbaa !11
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = sitofp i32 %66 to float
  %68 = fdiv float %65, %67
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store float %68, ptr %69, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %64, %60, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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/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
@__FUNCTION__.mMean = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @mMean(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %5 [
    i64 -1, label %7
    i64 0, label %7
  ]

5:                                                ; preds = %4
  %6 = icmp slt i32 %1, 1
  br i1 %6, label %.thread37, label %.lr.ph.preheader

.thread37:                                        ; preds = %5
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 297, ptr noundef nonnull @__FUNCTION__.mMean, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

7:                                                ; preds = %4, %4
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 297, ptr noundef nonnull @__FUNCTION__.mMean, ptr noundef nonnull @.str.1) #2
  %8 = icmp sgt i32 %1, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5, %7
  %wide.trip.count = zext nneg i32 %1 to i64
  %9 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %wide.trip.count, 7
  %10 = icmp ult i64 %9, 7
  br i1 %10, 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, 2147483640
  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.7, %.lr.ph ]
  %.034 = phi float [ 0.000000e+00, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %11 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %12 = load float, ptr %11, align 4, !tbaa !5
  %13 = fadd float %.034, %12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fadd float %13, %15
  %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 %16, %18
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %20 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.2
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = fadd float %19, %21
  %indvars.iv.next.3 = or disjoint i64 %indvars.iv, 4
  %23 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.3
  %24 = load float, ptr %23, align 4, !tbaa !5
  %25 = fadd float %22, %24
  %indvars.iv.next.4 = or disjoint i64 %indvars.iv, 5
  %26 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.4
  %27 = load float, ptr %26, align 4, !tbaa !5
  %28 = fadd float %25, %27
  %indvars.iv.next.5 = or disjoint i64 %indvars.iv, 6
  %29 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.5
  %30 = load float, ptr %29, align 4, !tbaa !5
  %31 = fadd float %28, %30
  %indvars.iv.next.6 = or disjoint i64 %indvars.iv, 7
  %32 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.6
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = fadd float %31, %33
  %indvars.iv.next.7 = add nuw nsw i64 %indvars.iv, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi float [ poison, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.7, %.lr.ph ]
  %.034.unr = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %34, %.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 ]
  %.034.epil = phi float [ %37, %.lr.ph.epil ], [ %.034.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %35 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.epil
  %36 = load float, ptr %35, align 4, !tbaa !5
  %37 = fadd float %.034.epil, %36
  %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, %.thread37, %7
  %.0.lcssa = phi float [ 0.000000e+00, %7 ], [ 0.000000e+00, %.thread37 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %37, %.lr.ph.epil ]
  %magicptr31 = ptrtoint ptr %2 to i64
  switch i64 %magicptr31, label %38 [
    i64 -1, label %39
    i64 0, label %39
  ]

38:                                               ; preds = %._crit_edge
  store float %.0.lcssa, ptr %2, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %._crit_edge, %._crit_edge, %38
  %magicptr32 = ptrtoint ptr %3 to i64
  switch i64 %magicptr32, label %40 [
    i64 -1, label %43
    i64 0, label %43
  ]

40:                                               ; preds = %39
  %41 = sitofp i32 %1 to float
  %42 = fdiv float %.0.lcssa, %41
  store float %42, ptr %3, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %39, %39, %40
  ret void
}

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

attributes #0 = { 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 = { "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)"}
!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,SROAPass,SimplifyCFGPass,TailCallElimPass