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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @libxsmm_x86_is_Amxfp4_Bfp32_gemm(ptr noundef) #1

declare i32 @libxsmm_x86_is_Amxfp4_Bi8_gemm(ptr noundef) #1

declare i32 @libxsmm_x86_is_Amxfp4_Bbf16_gemm(ptr noundef) #1

; 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 i32 @libxsmm_generator_gemm_sse_avx_avx2_avx512_get_max_n_blocking(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %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 ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call i32 @libxsmm_x86_is_Amxfp4_Bfp32_gemm(ptr noundef %12)
  store i32 %13, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call i32 @libxsmm_x86_is_Amxfp4_Bbf16_gemm(ptr noundef %14)
  store i32 %15, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call i32 @libxsmm_x86_is_Amxfp4_Bi8_gemm(ptr noundef %16)
  store i32 %17, ptr %10, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp uge i32 %19, 1002
  br i1 %20, label %21, label %31

21:                                               ; preds = %3
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp ugt i32 %22, 0
  br i1 %23, label %30, label %24

24:                                               ; preds = %21
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp ugt i32 %25, 0
  br i1 %26, label %30, label %27

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

30:                                               ; preds = %27, %24, %21
  store i32 4, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %54

31:                                               ; preds = %27, %3
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = icmp uge i32 %32, 1002
  br i1 %33, label %34, label %43

34:                                               ; preds = %31
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp ult i32 %35, 1051
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 1008
  br i1 %39, label %40, label %42

40:                                               ; preds = %37
  %41 = call i32 @libxsmm_cpuid_x86_srf_gemm_set_n_max_blocking()
  store i32 %41, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %54

42:                                               ; preds = %37
  store i32 3, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %54

43:                                               ; preds = %34, %31
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = icmp uge i32 %44, 1051
  br i1 %45, label %46, label %50

46:                                               ; preds = %43
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp ule i32 %47, 1999
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  store i32 28, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %54

50:                                               ; preds = %46, %43
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %54

54:                                               ; preds = %53, %49, %42, %40, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %55 = load i32, ptr %4, align 4
  ret i32 %55
}

declare i32 @libxsmm_cpuid_x86_srf_gemm_set_n_max_blocking() #1

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


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

declare i32 @libxsmm_x86_is_Amxfp4_Bfp32_gemm(ptr noundef) local_unnamed_addr #0

declare i32 @libxsmm_x86_is_Amxfp4_Bi8_gemm(ptr noundef) local_unnamed_addr #0

declare i32 @libxsmm_x86_is_Amxfp4_Bbf16_gemm(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @libxsmm_generator_gemm_sse_avx_avx2_avx512_get_max_n_blocking(ptr nocapture noundef readnone %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @libxsmm_x86_is_Amxfp4_Bfp32_gemm(ptr noundef %1) #2
  %5 = tail call i32 @libxsmm_x86_is_Amxfp4_Bbf16_gemm(ptr noundef %1) #2
  %6 = tail call i32 @libxsmm_x86_is_Amxfp4_Bi8_gemm(ptr noundef %1) #2
  %7 = icmp ugt i32 %2, 1001
  br i1 %7, label %8, label %.thread

8:                                                ; preds = %3
  %9 = icmp ne i32 %4, 0
  %10 = icmp ne i32 %5, 0
  %or.cond = select i1 %9, i1 true, i1 %10
  %11 = icmp ne i32 %6, 0
  %or.cond3 = select i1 %or.cond, i1 true, i1 %11
  br i1 %or.cond3, label %19, label %12

12:                                               ; preds = %8
  %13 = add i32 %2, -1002
  %or.cond5 = icmp ult i32 %13, 49
  br i1 %or.cond5, label %14, label %.thread

14:                                               ; preds = %12
  %15 = icmp eq i32 %2, 1008
  br i1 %15, label %16, label %19

16:                                               ; preds = %14
  %17 = tail call i32 @libxsmm_cpuid_x86_srf_gemm_set_n_max_blocking() #2
  br label %19

.thread:                                          ; preds = %3, %12
  %18 = add i32 %2, -1051
  %or.cond7 = icmp ult i32 %18, 949
  %. = select i1 %or.cond7, i32 28, i32 0
  br label %19

19:                                               ; preds = %.thread, %14, %8, %16
  %.0 = phi i32 [ %17, %16 ], [ 4, %8 ], [ 3, %14 ], [ %., %.thread ]
  ret i32 %.0
}

declare i32 @libxsmm_cpuid_x86_srf_gemm_set_n_max_blocking() local_unnamed_addr #0

attributes #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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass