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

%union.libxsmm_float_uint = type { float }
%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(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 i8, align 1
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %union.libxsmm_float_uint, 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 1, ptr %10) #2
  store i8 0, ptr %10, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %14, i32 0, i32 42
  %16 = load i32, ptr %15, align 8, !tbaa !14
  store i32 %16, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %17 = load ptr, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %17, i32 0, i32 25
  %19 = load i32, ptr %18, align 4, !tbaa !18
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %40

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

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

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

72:                                               ; preds = %40
  %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 !18
  %76 = icmp eq i32 %75, 3
  br i1 %76, label %77, label %103

77:                                               ; preds = %72
  %78 = load ptr, ptr %8, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %78, i32 0, i32 38
  %80 = load ptr, ptr %79, align 8, !tbaa !21
  %81 = load ptr, ptr %8, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %81, i32 0, i32 53
  %83 = load i64, ptr %82, align 8, !tbaa !24
  %84 = mul nsw i64 %83, 2
  %85 = load i32, ptr %11, align 4, !tbaa !5
  %86 = zext i32 %85 to i64
  %87 = sdiv i64 %84, %86
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = mul nsw i64 %87, %89
  %91 = getelementptr inbounds i8, ptr %80, i64 %90
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = load ptr, ptr %8, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %93, i32 0, i32 7
  %95 = load i32, ptr %94, align 4, !tbaa !20
  %96 = mul nsw i32 %92, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i8, ptr %91, i64 %97
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i8, ptr %98, i64 %100
  %102 = load i8, ptr %101, align 1, !tbaa !13
  store i8 %102, ptr %10, align 1, !tbaa !13
  br label %118

103:                                              ; preds = %72
  %104 = load ptr, ptr %8, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %104, i32 0, i32 38
  %106 = load ptr, ptr %105, align 8, !tbaa !21
  %107 = load i32, ptr %6, align 4, !tbaa !5
  %108 = load ptr, ptr %8, align 8, !tbaa !9
  %109 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %108, i32 0, i32 7
  %110 = load i32, ptr %109, align 4, !tbaa !20
  %111 = mul nsw i32 %107, %110
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds i8, ptr %106, i64 %112
  %114 = load i32, ptr %7, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i8, ptr %113, i64 %115
  %117 = load i8, ptr %116, align 1, !tbaa !13
  store i8 %117, ptr %10, align 1, !tbaa !13
  br label %118

118:                                              ; preds = %103, %77
  br label %119

119:                                              ; preds = %118, %45
  br label %120

120:                                              ; preds = %119, %21
  %121 = load i8, ptr %10, align 1, !tbaa !13
  %122 = zext i8 %121 to i32
  store i32 %122, ptr %12, align 4, !tbaa !5
  %123 = load i32, ptr %12, align 4, !tbaa !5
  %124 = shl i32 %123, 23
  store i32 %124, ptr %12, align 4, !tbaa !5
  %125 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %125, ptr %13, align 4, !tbaa !13
  %126 = load float, ptr %13, align 4, !tbaa !13
  store float %126, ptr %9, align 4, !tbaa !11
  %127 = load float, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret float %127
}

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 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 216}
!15 = !{!"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, !16, i64 48, !16, 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, !17, i64 264, !17, 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}
!16 = !{!"double", !7, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!15, !6, i64 108}
!19 = !{!15, !10, i64 184}
!20 = !{!15, !6, i64 28}
!21 = !{!15, !10, i64 192}
!22 = !{!15, !10, i64 280}
!23 = !{!17, !17, i64 0}
!24 = !{!15, !17, i64 264}


; 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(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 %38 [
    i32 1, label %9
    i32 2, label %15
    i32 3, label %27
  ]

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %3, i64 184
  %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 %41

15:                                               ; preds = %4
  %16 = getelementptr inbounds i8, ptr %3, i64 192
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %3, i64 280
  %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 = shl nsw i64 %22, 1
  %24 = zext i32 %6 to i64
  %25 = sdiv i64 %23, %24
  %26 = getelementptr inbounds i8, ptr %17, i64 %25
  br label %41

27:                                               ; preds = %4
  %28 = getelementptr inbounds i8, ptr %3, i64 192
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds i8, ptr %3, i64 264
  %31 = load i64, ptr %30, align 8, !tbaa !20
  %32 = shl nsw i64 %31, 1
  %33 = zext i32 %6 to i64
  %34 = sdiv i64 %32, %33
  %35 = sext i32 %0 to i64
  %36 = mul nsw i64 %34, %35
  %37 = getelementptr inbounds i8, ptr %29, i64 %36
  br label %41

38:                                               ; preds = %4
  %39 = getelementptr inbounds i8, ptr %3, i64 192
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  br label %41

41:                                               ; preds = %15, %38, %27, %9
  %.sink32 = phi ptr [ %26, %15 ], [ %40, %38 ], [ %37, %27 ], [ %14, %9 ]
  %42 = getelementptr inbounds i8, ptr %3, i64 28
  %43 = load i32, ptr %42, align 4, !tbaa !21
  %44 = mul nsw i32 %43, %1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %.sink32, i64 %45
  %47 = sext i32 %2 to i64
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %.0 = load i8, ptr %48, align 1, !tbaa !22
  %49 = zext i8 %.0 to i32
  %50 = shl nuw nsw i32 %49, 23
  %51 = bitcast i32 %50 to float
  ret float %51
}

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 184}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !12, i64 192}
!18 = !{!6, !12, i64 280}
!19 = !{!13, !13, i64 0}
!20 = !{!6, !13, i64 264}
!21 = !{!6, !7, i64 28}
!22 = !{!8, !8, i64 0}


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