; 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_3_a = external dso_local global [72 x double], align 16
@lebedev_grid_3_b = external dso_local global [72 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 uwtable
define dso_local void @gen_lebedev_points_category_3(ptr noundef %0, double noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = load i64, ptr getelementptr inbounds ([6 x i64], ptr @lebedev_grid_sizes, i64 0, i64 3), align 8, !tbaa !11
  %9 = mul i64 %8, 3
  store i64 %9, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fmul double 2.000000e+00, %10
  %12 = load double, ptr %4, align 8, !tbaa !9
  %13 = fneg double %11
  %14 = call double @llvm.fmuladd.f64(double %13, double %12, double 1.000000e+00)
  %15 = call double @sqrt(double noundef %14) #4
  store double %15, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %16

16:                                               ; preds = %39, %2
  %17 = load i32, ptr %7, align 4, !tbaa !13
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr %5, align 8, !tbaa !11
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %42

22:                                               ; preds = %16
  %23 = load i32, ptr %7, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_a, i64 0, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = load double, ptr %4, align 8, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_b, i64 0, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = load double, ptr %6, align 8, !tbaa !9
  %33 = fmul double %31, %32
  %34 = call double @llvm.fmuladd.f64(double %26, double %27, double %33)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !13
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  store double %34, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %22
  %40 = load i32, ptr %7, align 4, !tbaa !13
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !13
  br label %16, !llvm.loop !15

42:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

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

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 = { 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 = { 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 = !{!"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_3_a = external dso_local local_unnamed_addr global [72 x double], align 16
@lebedev_grid_3_b = external dso_local local_unnamed_addr global [72 x double], align 16

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

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

.lr.ph.preheader19:                               ; 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.preheader19
  %9 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_a, i64 0, i64 %indvars.iv.ph
  %10 = load double, ptr %9, align 16, !tbaa !9
  %11 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_b, i64 0, i64 %indvars.iv.ph
  %12 = load double, ptr %11, align 16, !tbaa !9
  %13 = fmul double %7, %12
  %14 = tail call double @llvm.fmuladd.f64(double %10, double %1, double %13)
  %15 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.ph
  store double %14, ptr %15, 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.preheader19
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader19 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %16 = icmp eq i64 %umax, %.neg
  br i1 %16, label %._crit_edge, label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %17 = sub i64 %3, ptrtoint (ptr @lebedev_grid_3_a to i64)
  %diff.check = icmp ult i64 %17, 32
  %18 = sub i64 %3, ptrtoint (ptr @lebedev_grid_3_b to i64)
  %diff.check13 = icmp ult i64 %18, 32
  %conflict.rdx = or i1 %diff.check, %diff.check13
  br i1 %conflict.rdx, label %.lr.ph.preheader19, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %umax, -4
  %broadcast.splatinsert = insertelement <2 x double> poison, double %7, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert17 = insertelement <2 x double> poison, double %1, i64 0
  %broadcast.splat18 = shufflevector <2 x double> %broadcast.splatinsert17, <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 ]
  %19 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_a, i64 0, i64 %index
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %wide.load = load <2 x double>, ptr %19, align 16, !tbaa !9
  %wide.load14 = load <2 x double>, ptr %20, align 16, !tbaa !9
  %21 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_b, i64 0, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load15 = load <2 x double>, ptr %21, align 16, !tbaa !9
  %wide.load16 = load <2 x double>, ptr %22, align 16, !tbaa !9
  %23 = fmul <2 x double> %broadcast.splat, %wide.load15
  %24 = fmul <2 x double> %broadcast.splat, %wide.load16
  %25 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load, <2 x double> %broadcast.splat18, <2 x double> %23)
  %26 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load14, <2 x double> %broadcast.splat18, <2 x double> %24)
  %27 = getelementptr inbounds double, ptr %0, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  store <2 x double> %25, ptr %27, align 8, !tbaa !9
  store <2 x double> %26, ptr %28, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !11

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

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %2
  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 ]
  %30 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_a, i64 0, i64 %indvars.iv
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_b, i64 0, i64 %indvars.iv
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = fmul double %7, %33
  %35 = tail call double @llvm.fmuladd.f64(double %31, double %1, double %34)
  %36 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  store double %35, ptr %36, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_a, i64 0, i64 %indvars.iv.next
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds [72 x double], ptr @lebedev_grid_3_b, i64 0, i64 %indvars.iv.next
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fmul double %7, %40
  %42 = tail call double @llvm.fmuladd.f64(double %38, double %1, double %41)
  %43 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  store double %42, ptr %43, align 8, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %8, %indvars.iv.next.1
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !15
}

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

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

; 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 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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