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

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_ref_allocate_c_vnni_scratch = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_ref_allocate_c_vnni_scratch(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %3, i32 0, i32 64
  %5 = load i32, ptr %4, align 8, !tbaa !9
  %6 = icmp ugt i32 %5, 0
  br i1 %6, label %7, label %135

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %8, i32 0, i32 9
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = sext i32 %10 to i64
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %12, i32 0, i32 5
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %15 = sext i32 %14 to i64
  %16 = mul i64 %11, %15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 8, !tbaa !17
  %20 = icmp eq i32 0, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %7
  br label %128

22:                                               ; preds = %7
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = icmp eq i32 1, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  br label %126

28:                                               ; preds = %22
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !17
  %32 = icmp eq i32 2, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  br label %124

34:                                               ; preds = %28
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !17
  %38 = icmp eq i32 3, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  br label %122

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

45:                                               ; preds = %40
  br label %120

46:                                               ; preds = %40
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !17
  %50 = icmp eq i32 5, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  br label %118

52:                                               ; preds = %46
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !17
  %56 = icmp eq i32 6, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  br label %116

58:                                               ; preds = %52
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %59, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !17
  %62 = icmp eq i32 7, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  br label %114

64:                                               ; preds = %58
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %65, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !17
  %68 = icmp eq i32 8, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %64
  br label %112

70:                                               ; preds = %64
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 8, !tbaa !17
  %74 = icmp eq i32 9, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  br label %110

76:                                               ; preds = %70
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !17
  %80 = icmp eq i32 10, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %76
  br label %108

82:                                               ; preds = %76
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %83, i32 0, i32 2
  %85 = load i32, ptr %84, align 8, !tbaa !17
  %86 = icmp eq i32 11, %85
  br i1 %86, label %87, label %88

87:                                               ; preds = %82
  br label %106

88:                                               ; preds = %82
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %89, i32 0, i32 2
  %91 = load i32, ptr %90, align 8, !tbaa !17
  %92 = icmp eq i32 12, %91
  br i1 %92, label %93, label %94

93:                                               ; preds = %88
  br label %104

94:                                               ; preds = %88
  %95 = load ptr, ptr %2, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %95, i32 0, i32 2
  %97 = load i32, ptr %96, align 8, !tbaa !17
  %98 = icmp eq i32 13, %97
  br i1 %98, label %99, label %100

99:                                               ; preds = %94
  br label %102

100:                                              ; preds = %94
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 205, ptr noundef @__PRETTY_FUNCTION__.libxsmm_ref_allocate_c_vnni_scratch) #3
  unreachable

101:                                              ; No predecessors!
  br label %102

102:                                              ; preds = %101, %99
  %103 = phi i32 [ 1, %99 ], [ 0, %101 ]
  br label %104

104:                                              ; preds = %102, %93
  %105 = phi i32 [ 1, %93 ], [ %103, %102 ]
  br label %106

106:                                              ; preds = %104, %87
  %107 = phi i32 [ 2, %87 ], [ %105, %104 ]
  br label %108

108:                                              ; preds = %106, %81
  %109 = phi i32 [ 2, %81 ], [ %107, %106 ]
  br label %110

110:                                              ; preds = %108, %75
  %111 = phi i32 [ 4, %75 ], [ %109, %108 ]
  br label %112

112:                                              ; preds = %110, %69
  %113 = phi i32 [ 4, %69 ], [ %111, %110 ]
  br label %114

114:                                              ; preds = %112, %63
  %115 = phi i32 [ 8, %63 ], [ %113, %112 ]
  br label %116

116:                                              ; preds = %114, %57
  %117 = phi i32 [ 8, %57 ], [ %115, %114 ]
  br label %118

118:                                              ; preds = %116, %51
  %119 = phi i32 [ 1, %51 ], [ %117, %116 ]
  br label %120

120:                                              ; preds = %118, %45
  %121 = phi i32 [ 1, %45 ], [ %119, %118 ]
  br label %122

122:                                              ; preds = %120, %39
  %123 = phi i32 [ 2, %39 ], [ %121, %120 ]
  br label %124

124:                                              ; preds = %122, %33
  %125 = phi i32 [ 2, %33 ], [ %123, %122 ]
  br label %126

126:                                              ; preds = %124, %27
  %127 = phi i32 [ 4, %27 ], [ %125, %124 ]
  br label %128

128:                                              ; preds = %126, %21
  %129 = phi i32 [ 8, %21 ], [ %127, %126 ]
  %130 = sext i32 %129 to i64
  %131 = mul i64 %16, %130
  %132 = call noalias ptr @malloc(i64 noundef %131) #4
  %133 = load ptr, ptr %2, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %133, i32 0, i32 67
  store ptr %132, ptr %134, align 8, !tbaa !18
  br label %135

135:                                              ; preds = %128, %1
  ret void
}

attributes #0 = { noreturn nounwind "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 allocsize(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 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 = { noreturn nounwind }
attributes #4 = { nounwind allocsize(0) }

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


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

@.str = external hidden unnamed_addr constant [27 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_ref_allocate_c_vnni_scratch = external hidden unnamed_addr constant [61 x i8], align 1
@switch.table.libxsmm_ref_allocate_c_vnni_scratch = private unnamed_addr constant [14 x i64] [i64 8, i64 4, i64 2, i64 2, i64 1, i64 1, i64 8, i64 8, i64 4, i64 4, i64 2, i64 2, i64 1, i64 1], align 8

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_ref_allocate_c_vnni_scratch(ptr nocapture noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 336
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %20, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !14
  %7 = icmp ult i32 %6, 14
  br i1 %7, label %switch.lookup, label %8

8:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 205, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_ref_allocate_c_vnni_scratch) #3
  unreachable

switch.lookup:                                    ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 20
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 36
  %13 = load i32, ptr %12, align 4, !tbaa !16
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %11, %14
  %16 = zext nneg i32 %6 to i64
  %switch.gep = getelementptr inbounds [14 x i64], ptr @switch.table.libxsmm_ref_allocate_c_vnni_scratch, i64 0, i64 %16
  %switch.load = load i64, ptr %switch.gep, align 8
  %17 = mul i64 %15, %switch.load
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #4
  %19 = getelementptr inbounds i8, ptr %0, i64 352
  store ptr %18, ptr %19, align 8, !tbaa !17
  br label %20

20:                                               ; preds = %switch.lookup, %1
  ret void
}

attributes #0 = { noreturn nounwind "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { noreturn nounwind }
attributes #4 = { nounwind allocsize(0) }

!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 336}
!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 8}
!15 = !{!6, !7, i64 20}
!16 = !{!6, !7, i64 36}
!17 = !{!6, !12, i64 352}


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