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

; 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_gemm_def = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, double, double, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr }

; 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 float @libxsmm_calculate_mxfp4_scf_b(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %11 = load ptr, ptr %8, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %11, i32 0, i32 42
  %13 = load i32, ptr %12, align 8, !tbaa !13
  store i32 %13, ptr %10, align 4, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %14, i32 0, i32 25
  %16 = load i32, ptr %15, align 4, !tbaa !17
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %39

18:                                               ; preds = %4
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %19, i32 0, i32 31
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %27, i32 0, i32 8
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = udiv i32 %29, %30
  %32 = mul i32 %26, %31
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %25, i64 %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %34, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !11
  store float %38, ptr %9, align 4, !tbaa !11
  br label %123

39:                                               ; preds = %4
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %40, i32 0, i32 25
  %42 = load i32, ptr %41, align 4, !tbaa !17
  %43 = icmp eq i32 %42, 2
  br i1 %43, label %44, label %72

44:                                               ; preds = %39
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %45, i32 0, i32 32
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %48, i32 0, i32 56
  %50 = load ptr, ptr %49, align 8, !tbaa !21
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i64, ptr %50, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !22
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = zext i32 %55 to i64
  %57 = sdiv i64 %54, %56
  %58 = getelementptr inbounds float, ptr %47, i64 %57
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %60, i32 0, i32 8
  %62 = load i32, ptr %61, align 8, !tbaa !19
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = udiv i32 %62, %63
  %65 = mul i32 %59, %64
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds float, ptr %58, i64 %66
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds float, ptr %67, i64 %69
  %71 = load float, ptr %70, align 4, !tbaa !11
  store float %71, ptr %9, align 4, !tbaa !11
  br label %122

72:                                               ; preds = %39
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %73, i32 0, i32 25
  %75 = load i32, ptr %74, align 4, !tbaa !17
  %76 = icmp eq i32 %75, 3
  br i1 %76, label %77, label %104

77:                                               ; preds = %72
  %78 = load ptr, ptr %8, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %78, i32 0, i32 32
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  %81 = load ptr, ptr %8, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %81, i32 0, i32 54
  %83 = load i64, ptr %82, align 8, !tbaa !23
  %84 = load i32, ptr %10, align 4, !tbaa !5
  %85 = zext i32 %84 to i64
  %86 = sdiv i64 %83, %85
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = mul nsw i64 %86, %88
  %90 = getelementptr inbounds float, ptr %80, i64 %89
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %92, i32 0, i32 8
  %94 = load i32, ptr %93, align 8, !tbaa !19
  %95 = load i32, ptr %10, align 4, !tbaa !5
  %96 = udiv i32 %94, %95
  %97 = mul i32 %91, %96
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds float, ptr %90, i64 %98
  %100 = load i32, ptr %6, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds float, ptr %99, i64 %101
  %103 = load float, ptr %102, align 4, !tbaa !11
  store float %103, ptr %9, align 4, !tbaa !11
  br label %121

104:                                              ; preds = %72
  %105 = load ptr, ptr %8, align 8, !tbaa !9
  %106 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %105, i32 0, i32 32
  %107 = load ptr, ptr %106, align 8, !tbaa !20
  %108 = load i32, ptr %7, align 4, !tbaa !5
  %109 = load ptr, ptr %8, align 8, !tbaa !9
  %110 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %109, i32 0, i32 8
  %111 = load i32, ptr %110, align 8, !tbaa !19
  %112 = load i32, ptr %10, align 4, !tbaa !5
  %113 = udiv i32 %111, %112
  %114 = mul i32 %108, %113
  %115 = zext i32 %114 to i64
  %116 = getelementptr inbounds float, ptr %107, i64 %115
  %117 = load i32, ptr %6, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds float, ptr %116, i64 %118
  %120 = load float, ptr %119, align 4, !tbaa !11
  store float %120, ptr %9, align 4, !tbaa !11
  br label %121

121:                                              ; preds = %104, %77
  br label %122

122:                                              ; preds = %121, %44
  br label %123

123:                                              ; preds = %122, %18
  %124 = load float, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret float %124
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 216}
!14 = !{!"libxsmm_gemm_def", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !15, i64 48, !15, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !6, i64 100, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !6, i64 120, !12, i64 124, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !6, i64 208, !6, i64 212, !6, i64 216, !6, i64 220, !6, i64 224, !6, i64 228, !6, i64 232, !6, i64 236, !6, i64 240, !6, i64 244, !6, i64 248, !6, i64 252, !6, i64 256, !16, i64 264, !16, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !6, i64 320, !6, i64 324, !6, i64 328, !6, i64 332, !6, i64 336, !6, i64 340, !10, i64 344, !10, i64 352}
!15 = !{!"double", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!14, !6, i64 108}
!18 = !{!14, !10, i64 136}
!19 = !{!14, !6, i64 32}
!20 = !{!14, !10, i64 144}
!21 = !{!14, !10, i64 288}
!22 = !{!16, !16, i64 0}
!23 = !{!14, !16, i64 272}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local float @libxsmm_calculate_mxfp4_scf_b(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %3, i64 216
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 108
  %8 = load i32, ptr %7, align 4, !tbaa !14
  switch i32 %8, label %36 [
    i32 1, label %9
    i32 2, label %15
    i32 3, label %26
  ]

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %3, i64 136
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = sext i32 %0 to i64
  %13 = getelementptr inbounds ptr, ptr %11, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  br label %39

15:                                               ; preds = %4
  %16 = getelementptr inbounds i8, ptr %3, i64 144
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %3, i64 288
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = sext i32 %0 to i64
  %21 = getelementptr inbounds i64, ptr %19, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !19
  %23 = zext i32 %6 to i64
  %24 = sdiv i64 %22, %23
  %25 = getelementptr inbounds float, ptr %17, i64 %24
  br label %39

26:                                               ; preds = %4
  %27 = getelementptr inbounds i8, ptr %3, i64 144
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds i8, ptr %3, i64 272
  %30 = load i64, ptr %29, align 8, !tbaa !20
  %31 = zext i32 %6 to i64
  %32 = sdiv i64 %30, %31
  %33 = sext i32 %0 to i64
  %34 = mul nsw i64 %32, %33
  %35 = getelementptr inbounds float, ptr %28, i64 %34
  br label %39

36:                                               ; preds = %4
  %37 = getelementptr inbounds i8, ptr %3, i64 144
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  br label %39

39:                                               ; preds = %15, %36, %26, %9
  %.sink33 = phi ptr [ %25, %15 ], [ %38, %36 ], [ %35, %26 ], [ %14, %9 ]
  %40 = getelementptr inbounds i8, ptr %3, i64 32
  %41 = load i32, ptr %40, align 8, !tbaa !21
  %42 = udiv i32 %41, %6
  %43 = mul i32 %42, %2
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %.sink33, i64 %44
  %46 = sext i32 %1 to i64
  %47 = getelementptr inbounds float, ptr %45, i64 %46
  %.0 = load float, ptr %47, align 4, !tbaa !22
  ret float %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !7, i64 216}
!6 = !{!"libxsmm_gemm_def", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !10, i64 48, !10, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !11, i64 124, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !7, i64 208, !7, i64 212, !7, i64 216, !7, i64 220, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !7, i64 248, !7, i64 252, !7, i64 256, !13, i64 264, !13, i64 272, !12, i64 280, !12, i64 288, !12, i64 296, !12, i64 304, !12, i64 312, !7, i64 320, !7, i64 324, !7, i64 328, !7, i64 332, !7, i64 336, !7, i64 340, !12, i64 344, !12, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = !{!6, !7, i64 108}
!15 = !{!6, !12, i64 136}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !12, i64 144}
!18 = !{!6, !12, i64 288}
!19 = !{!13, !13, i64 0}
!20 = !{!6, !13, i64 272}
!21 = !{!6, !7, i64 32}
!22 = !{!11, !11, i64 0}


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