; 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_parameter_offset = external dso_local global [33 x i64], align 16
@lebedev_parameters = external dso_local global [1287 x [4 x double]], align 16
@lebedev_grid_sizes = external dso_local global [6 x i64], align 16
@lebedev_grid_0 = external dso_local global [18 x double], align 16
@lebedev_grid_1 = external dso_local global [36 x double], align 16
@lebedev_grid_2 = external dso_local global [24 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
declare dso_local void @set_lebedev_weight(ptr noundef, double noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gen_lebedev_points_category_3(ptr noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gen_lebedev_points_category_4(ptr noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gen_lebedev_points_category_5(ptr noundef, double noundef, double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @lebedev_gen_grid(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = getelementptr inbounds [33 x i64], ptr @lebedev_parameter_offset, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %16, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = add i64 %17, 1
  %19 = getelementptr inbounds [33 x i64], ptr @lebedev_parameter_offset, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %20, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %21 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %21, ptr %10, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %106, %3
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %109

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %28
  %30 = getelementptr inbounds [4 x double], ptr %29, i64 0, i64 0
  %31 = load double, ptr %30, align 16, !tbaa !11
  %32 = fptoui double %31 to i64
  store i64 %32, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %33 = load i64, ptr %11, align 8, !tbaa !9
  %34 = getelementptr inbounds [6 x i64], ptr @lebedev_grid_sizes, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  store i64 %35, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %36
  %38 = getelementptr inbounds [4 x double], ptr %37, i64 0, i64 3
  %39 = load double, ptr %38, align 8, !tbaa !11
  store double %39, ptr %13, align 8, !tbaa !11
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds double, ptr %40, i64 %41
  %43 = load double, ptr %13, align 8, !tbaa !11
  %44 = load i64, ptr %12, align 8, !tbaa !9
  call void @set_lebedev_weight(ptr noundef %42, double noundef %43, i64 noundef %44)
  %45 = load i64, ptr %11, align 8, !tbaa !9
  switch i64 %45, label %101 [
    i64 0, label %46
    i64 1, label %54
    i64 2, label %62
    i64 3, label %70
    i64 4, label %79
    i64 5, label %88
  ]

46:                                               ; preds = %27
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = mul i64 %48, 3
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load i64, ptr %12, align 8, !tbaa !9
  %52 = mul i64 %51, 3
  %53 = mul i64 %52, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %50, ptr align 16 @lebedev_grid_0, i64 %53, i1 false)
  br label %102

54:                                               ; preds = %27
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = mul i64 %56, 3
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  %59 = load i64, ptr %12, align 8, !tbaa !9
  %60 = mul i64 %59, 3
  %61 = mul i64 %60, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %58, ptr align 16 @lebedev_grid_1, i64 %61, i1 false)
  br label %102

62:                                               ; preds = %27
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i64, ptr %9, align 8, !tbaa !9
  %65 = mul i64 %64, 3
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = mul i64 %67, 3
  %69 = mul i64 %68, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %66, ptr align 16 @lebedev_grid_2, i64 %69, i1 false)
  br label %102

70:                                               ; preds = %27
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load i64, ptr %9, align 8, !tbaa !9
  %73 = mul i64 %72, 3
  %74 = getelementptr inbounds double, ptr %71, i64 %73
  %75 = load i64, ptr %10, align 8, !tbaa !9
  %76 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %75
  %77 = getelementptr inbounds [4 x double], ptr %76, i64 0, i64 1
  %78 = load double, ptr %77, align 8, !tbaa !11
  call void @gen_lebedev_points_category_3(ptr noundef %74, double noundef %78)
  br label %102

79:                                               ; preds = %27
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load i64, ptr %9, align 8, !tbaa !9
  %82 = mul i64 %81, 3
  %83 = getelementptr inbounds double, ptr %80, i64 %82
  %84 = load i64, ptr %10, align 8, !tbaa !9
  %85 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %84
  %86 = getelementptr inbounds [4 x double], ptr %85, i64 0, i64 1
  %87 = load double, ptr %86, align 8, !tbaa !11
  call void @gen_lebedev_points_category_4(ptr noundef %83, double noundef %87)
  br label %102

88:                                               ; preds = %27
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = load i64, ptr %9, align 8, !tbaa !9
  %91 = mul i64 %90, 3
  %92 = getelementptr inbounds double, ptr %89, i64 %91
  %93 = load i64, ptr %10, align 8, !tbaa !9
  %94 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %93
  %95 = getelementptr inbounds [4 x double], ptr %94, i64 0, i64 1
  %96 = load double, ptr %95, align 8, !tbaa !11
  %97 = load i64, ptr %10, align 8, !tbaa !9
  %98 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %97
  %99 = getelementptr inbounds [4 x double], ptr %98, i64 0, i64 2
  %100 = load double, ptr %99, align 16, !tbaa !11
  call void @gen_lebedev_points_category_5(ptr noundef %92, double noundef %96, double noundef %100)
  br label %102

101:                                              ; preds = %27
  br label %102

102:                                              ; preds = %101, %88, %79, %70, %62, %54, %46
  %103 = load i64, ptr %12, align 8, !tbaa !9
  %104 = load i64, ptr %9, align 8, !tbaa !9
  %105 = add i64 %104, %103
  store i64 %105, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %106

106:                                              ; preds = %102
  %107 = load i64, ptr %10, align 8, !tbaa !9
  %108 = add i64 %107, 1
  store i64 %108, ptr %10, align 8, !tbaa !9
  br label %22, !llvm.loop !13

109:                                              ; preds = %26
  %110 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %110
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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"

@lebedev_parameter_offset = external dso_local local_unnamed_addr global [33 x i64], align 16
@lebedev_parameters = external dso_local local_unnamed_addr global [1287 x [4 x double]], align 16
@lebedev_grid_sizes = external dso_local local_unnamed_addr global [6 x i64], align 16
@lebedev_grid_0 = external dso_local local_unnamed_addr global [18 x double], align 16
@lebedev_grid_1 = external dso_local local_unnamed_addr global [36 x double], align 16
@lebedev_grid_2 = external dso_local local_unnamed_addr global [24 x double], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @set_lebedev_weight(ptr noundef, double noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @gen_lebedev_points_category_3(ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @gen_lebedev_points_category_4(ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @gen_lebedev_points_category_5(ptr noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @lebedev_gen_grid(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds [33 x i64], ptr @lebedev_parameter_offset, i64 0, i64 %2
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = add i64 %2, 1
  %7 = getelementptr inbounds [33 x i64], ptr @lebedev_parameter_offset, i64 0, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = icmp ult i64 %5, %8
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %41, %3
  %.0.lcssa = phi i64 [ 0, %3 ], [ %42, %41 ]
  ret i64 %.0.lcssa

.lr.ph:                                           ; preds = %3, %41
  %.042 = phi i64 [ %42, %41 ], [ 0, %3 ]
  %.03541 = phi i64 [ %43, %41 ], [ %5, %3 ]
  %10 = getelementptr inbounds [1287 x [4 x double]], ptr @lebedev_parameters, i64 0, i64 %.03541
  %11 = load double, ptr %10, align 16, !tbaa !9
  %12 = fptoui double %11 to i64
  %13 = getelementptr inbounds [6 x i64], ptr @lebedev_grid_sizes, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %10, i64 24
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds double, ptr %1, i64 %.042
  tail call void @set_lebedev_weight(ptr noundef %17, double noundef %16, i64 noundef %14)
  switch i64 %12, label %41 [
    i64 0, label %18
    i64 1, label %21
    i64 2, label %24
    i64 3, label %27
    i64 4, label %31
    i64 5, label %35
  ]

18:                                               ; preds = %.lr.ph
  %.idx40 = mul i64 %.042, 24
  %19 = getelementptr inbounds i8, ptr %0, i64 %.idx40
  %20 = mul i64 %14, 24
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %19, ptr nonnull align 16 @lebedev_grid_0, i64 %20, i1 false)
  br label %41

21:                                               ; preds = %.lr.ph
  %.idx39 = mul i64 %.042, 24
  %22 = getelementptr inbounds i8, ptr %0, i64 %.idx39
  %23 = mul i64 %14, 24
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr nonnull align 16 @lebedev_grid_1, i64 %23, i1 false)
  br label %41

24:                                               ; preds = %.lr.ph
  %.idx38 = mul i64 %.042, 24
  %25 = getelementptr inbounds i8, ptr %0, i64 %.idx38
  %26 = mul i64 %14, 24
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %25, ptr nonnull align 16 @lebedev_grid_2, i64 %26, i1 false)
  br label %41

27:                                               ; preds = %.lr.ph
  %.idx37 = mul i64 %.042, 24
  %28 = getelementptr inbounds i8, ptr %0, i64 %.idx37
  %29 = getelementptr inbounds i8, ptr %10, i64 8
  %30 = load double, ptr %29, align 8, !tbaa !9
  tail call void @gen_lebedev_points_category_3(ptr noundef %28, double noundef %30)
  br label %41

31:                                               ; preds = %.lr.ph
  %.idx36 = mul i64 %.042, 24
  %32 = getelementptr inbounds i8, ptr %0, i64 %.idx36
  %33 = getelementptr inbounds i8, ptr %10, i64 8
  %34 = load double, ptr %33, align 8, !tbaa !9
  tail call void @gen_lebedev_points_category_4(ptr noundef %32, double noundef %34)
  br label %41

35:                                               ; preds = %.lr.ph
  %.idx = mul i64 %.042, 24
  %36 = getelementptr inbounds i8, ptr %0, i64 %.idx
  %37 = getelementptr inbounds i8, ptr %10, i64 8
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %10, i64 16
  %40 = load double, ptr %39, align 16, !tbaa !9
  tail call void @gen_lebedev_points_category_5(ptr noundef %36, double noundef %38, double noundef %40)
  br label %41

41:                                               ; preds = %.lr.ph, %35, %31, %27, %24, %21, %18
  %42 = add i64 %14, %.042
  %43 = add i64 %.03541, 1
  %exitcond.not = icmp eq i64 %43, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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}
!12 = !{!"llvm.loop.mustprogress"}


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