; LLVM IR from microsoft/LightAIMD :: src (lebedev_grid)

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

@lebedev_grid_sizes = external dso_local global [6 x i64], align 16
@lebedev_grid_5_a = external dso_local global [144 x double], align 16
@lebedev_grid_5_b = external dso_local global [144 x double], align 16
@lebedev_grid_5_c = external dso_local global [144 x double], align 16

; 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
declare double @sqrt(double noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @gen_lebedev_points_category_5(ptr noundef %0, double noundef %1, double noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load i64, ptr getelementptr inbounds ([6 x i64], ptr @lebedev_grid_sizes, i64 0, i64 5), align 8, !tbaa !11
  %11 = mul i64 %10, 3
  store i64 %11, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = load double, ptr %5, align 8, !tbaa !9
  %14 = fneg double %12
  %15 = call double @llvm.fmuladd.f64(double %14, double %13, double 1.000000e+00)
  %16 = load double, ptr %6, align 8, !tbaa !9
  %17 = load double, ptr %6, align 8, !tbaa !9
  %18 = fneg double %16
  %19 = call double @llvm.fmuladd.f64(double %18, double %17, double %15)
  %20 = call double @sqrt(double noundef %19) #4
  store double %20, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %21

21:                                               ; preds = %50, %3
  %22 = load i32, ptr %9, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %53

27:                                               ; preds = %21
  %28 = load i32, ptr %9, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_a, i64 0, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !13
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_b, i64 0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fmul double %36, %37
  %39 = call double @llvm.fmuladd.f64(double %31, double %32, double %38)
  %40 = load i32, ptr %9, align 4, !tbaa !13
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_c, i64 0, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = load double, ptr %8, align 8, !tbaa !9
  %45 = call double @llvm.fmuladd.f64(double %43, double %44, double %39)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  store double %45, ptr %49, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %27
  %51 = load i32, ptr %9, align 4, !tbaa !13
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %9, align 4, !tbaa !13
  br label %21, !llvm.loop !15

53:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@lebedev_grid_sizes = external dso_local local_unnamed_addr global [6 x i64], align 16
@lebedev_grid_5_a = external dso_local local_unnamed_addr global [144 x double], align 16
@lebedev_grid_5_b = external dso_local local_unnamed_addr global [144 x double], align 16
@lebedev_grid_5_c = external dso_local local_unnamed_addr global [144 x double], align 16

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nofree nounwind memory(readwrite, argmem: write, inaccessiblemem: write) uwtable
define dso_local void @gen_lebedev_points_category_5(ptr nocapture noundef writeonly %0, double noundef %1, double noundef %2) local_unnamed_addr #2 {
  %4 = ptrtoint ptr %0 to i64
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @lebedev_grid_sizes, i64 40), align 8, !tbaa !5
  %6 = fneg double %1
  %7 = tail call double @llvm.fmuladd.f64(double %6, double %1, double 1.000000e+00)
  %8 = fneg double %2
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %2, double %7)
  %10 = tail call double @sqrt(double noundef %9) #4
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %11 = mul i64 %5, 3
  %umax = tail call i64 @llvm.umax.i64(i64 %11, i64 1)
  %min.iters.check = icmp ult i64 %11, 6
  br i1 %min.iters.check, label %.lr.ph.preheader29, label %vector.memcheck

.lr.ph.preheader29:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.neg = or disjoint i64 %indvars.iv.ph, 1
  %xtraiter = and i64 %umax, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader29
  %12 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_a, i64 0, i64 %indvars.iv.ph
  %13 = load double, ptr %12, align 16, !tbaa !9
  %14 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_b, i64 0, i64 %indvars.iv.ph
  %15 = load double, ptr %14, align 16, !tbaa !9
  %16 = fmul double %15, %2
  %17 = tail call double @llvm.fmuladd.f64(double %13, double %1, double %16)
  %18 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_c, i64 0, i64 %indvars.iv.ph
  %19 = load double, ptr %18, align 16, !tbaa !9
  %20 = tail call double @llvm.fmuladd.f64(double %19, double %10, double %17)
  %21 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.ph
  store double %20, ptr %21, align 8, !tbaa !9
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader29
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader29 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %22 = icmp eq i64 %umax, %.neg
  br i1 %22, label %._crit_edge, label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %23 = sub i64 %4, ptrtoint (ptr @lebedev_grid_5_a to i64)
  %diff.check = icmp ult i64 %23, 32
  %24 = sub i64 %4, ptrtoint (ptr @lebedev_grid_5_b to i64)
  %diff.check17 = icmp ult i64 %24, 32
  %conflict.rdx = or i1 %diff.check, %diff.check17
  %25 = sub i64 %4, ptrtoint (ptr @lebedev_grid_5_c to i64)
  %diff.check18 = icmp ult i64 %25, 32
  %conflict.rdx19 = or i1 %conflict.rdx, %diff.check18
  br i1 %conflict.rdx19, label %.lr.ph.preheader29, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %umax, -4
  %broadcast.splatinsert = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert23 = insertelement <2 x double> poison, double %1, i64 0
  %broadcast.splat24 = shufflevector <2 x double> %broadcast.splatinsert23, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert27 = insertelement <2 x double> poison, double %10, i64 0
  %broadcast.splat28 = shufflevector <2 x double> %broadcast.splatinsert27, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_a, i64 0, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load = load <2 x double>, ptr %26, align 16, !tbaa !9
  %wide.load20 = load <2 x double>, ptr %27, align 16, !tbaa !9
  %28 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_b, i64 0, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load21 = load <2 x double>, ptr %28, align 16, !tbaa !9
  %wide.load22 = load <2 x double>, ptr %29, align 16, !tbaa !9
  %30 = fmul <2 x double> %wide.load21, %broadcast.splat
  %31 = fmul <2 x double> %wide.load22, %broadcast.splat
  %32 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %broadcast.splat24, <2 x double> %30)
  %33 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load20, <2 x double> %broadcast.splat24, <2 x double> %31)
  %34 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_c, i64 0, i64 %index
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %wide.load25 = load <2 x double>, ptr %34, align 16, !tbaa !9
  %wide.load26 = load <2 x double>, ptr %35, align 16, !tbaa !9
  %36 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load25, <2 x double> %broadcast.splat28, <2 x double> %32)
  %37 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load26, <2 x double> %broadcast.splat28, <2 x double> %33)
  %38 = getelementptr inbounds double, ptr %0, i64 %index
  %39 = getelementptr inbounds i8, ptr %38, i64 16
  store <2 x double> %36, ptr %38, align 8, !tbaa !9
  store <2 x double> %37, ptr %39, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %40 = icmp eq i64 %index.next, %n.vec
  br i1 %40, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %11, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader29

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %41 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_a, i64 0, i64 %indvars.iv
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_b, i64 0, i64 %indvars.iv
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = fmul double %44, %2
  %46 = tail call double @llvm.fmuladd.f64(double %42, double %1, double %45)
  %47 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_c, i64 0, i64 %indvars.iv
  %48 = load double, ptr %47, align 8, !tbaa !9
  %49 = tail call double @llvm.fmuladd.f64(double %48, double %10, double %46)
  %50 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  store double %49, ptr %50, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %51 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_a, i64 0, i64 %indvars.iv.next
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_b, i64 0, i64 %indvars.iv.next
  %54 = load double, ptr %53, align 8, !tbaa !9
  %55 = fmul double %54, %2
  %56 = tail call double @llvm.fmuladd.f64(double %52, double %1, double %55)
  %57 = getelementptr inbounds [144 x double], ptr @lebedev_grid_5_c, i64 0, i64 %indvars.iv.next
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = tail call double @llvm.fmuladd.f64(double %58, double %10, double %56)
  %60 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  store double %59, ptr %60, align 8, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %11, %indvars.iv.next.1
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !15
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #3

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree nounwind memory(readwrite, argmem: write, inaccessiblemem: write) 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass