; LLVM IR from libxsmm/libxsmm :: src (generator_packed_spgemm_bcsc_bsparse_avx_avx2_avx512_amx)

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

%struct.libxsmm_generated_code = type { ptr, i32, i32, i32, i32, i32, i32 }

; 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 @libxsmm_spgemm_max_mn_blocking_factors_x86(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 i32, 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) #2
  store i32 32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.libxsmm_generated_code, ptr %12, i32 0, i32 6
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp ult i32 %14, 1101
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store i32 14, ptr %9, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %16, %4
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = sub i32 %18, 2
  store i32 %19, ptr %10, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %25, %17
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = urem i32 %21, %22
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %20
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = add i32 %26, -1
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %20, !llvm.loop !13

28:                                               ; preds = %20
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp ugt i32 %29, 4
  br i1 %30, label %31, label %46

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %42, %31
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = urem i32 %33, %34
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %40, label %37

37:                                               ; preds = %32
  %38 = load i32, ptr %10, align 4, !tbaa !9
  %39 = icmp ugt i32 %38, 4
  br label %40

40:                                               ; preds = %37, %32
  %41 = phi i1 [ true, %32 ], [ %39, %37 ]
  br i1 %41, label %42, label %45

42:                                               ; preds = %40
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = add i32 %43, -1
  store i32 %44, ptr %10, align 4, !tbaa !9
  br label %32, !llvm.loop !15

45:                                               ; preds = %40
  br label %46

46:                                               ; preds = %45, %28
  %47 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %47, ptr %11, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %57, %46
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = mul i32 %49, %50
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add i32 %51, %52
  %54 = add i32 %53, 1
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp ugt i32 %54, %55
  br i1 %56, label %57, label %60

57:                                               ; preds = %48
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = add i32 %58, -1
  store i32 %59, ptr %11, align 4, !tbaa !9
  br label %48, !llvm.loop !16

60:                                               ; preds = %48
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %61, ptr %62, align 4, !tbaa !9
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %63, ptr %64, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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 }

!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, !10, i64 28}
!12 = !{!"libxsmm_generated_code", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @libxsmm_spgemm_max_mn_blocking_factors_x86(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 28
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp ult i32 %6, 1101
  %spec.select = select i1 %7, i32 14, i32 32
  %8 = add nsw i32 %spec.select, -2
  br label %9

9:                                                ; preds = %9, %4
  %.019 = phi i32 [ %8, %4 ], [ %11, %9 ]
  %10 = urem i32 %1, %.019
  %.not = icmp eq i32 %10, 0
  %11 = add i32 %.019, -1
  br i1 %.not, label %12, label %9, !llvm.loop !11

12:                                               ; preds = %9
  %13 = icmp ugt i32 %.019, 4
  br i1 %13, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %12, %.preheader
  %.1 = phi i32 [ %18, %.preheader ], [ %.019, %12 ]
  %14 = urem i32 %1, %.1
  %15 = icmp ne i32 %14, 0
  %16 = icmp ugt i32 %.1, 4
  %17 = or i1 %16, %15
  %18 = add i32 %.1, -1
  br i1 %17, label %.preheader, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.preheader, %12
  %.2 = phi i32 [ %.019, %12 ], [ %.1, %.preheader ]
  %.021 = add nuw nsw i32 %.2, 1
  br label %19

19:                                               ; preds = %19, %.loopexit
  %.0 = phi i32 [ %spec.select, %.loopexit ], [ %23, %19 ]
  %20 = mul i32 %.0, %.021
  %21 = add i32 %20, 1
  %22 = icmp ugt i32 %21, %spec.select
  %23 = add i32 %.0, -1
  br i1 %22, label %19, label %24, !llvm.loop !14

24:                                               ; preds = %19
  store i32 %.0, ptr %2, align 4, !tbaa !15
  store i32 %.2, ptr %3, align 4, !tbaa !15
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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, !10, i64 28}
!6 = !{!"libxsmm_generated_code", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!10, !10, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass