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

; 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_descriptor = type <{ i32, i32, i32, i32, i32, i32, i32, i8, [3 x i8], i8, i64, i64, i8, i32, i32, i32, i16, i16, i8, i8, i8, i8, i16, i16, i16, i16, i16, i16, i32, i32, i32, i8 }>

; 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

declare i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef) #1

declare i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_generator_gemm_init_micro_kernel_config_rv64(ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @libxsmm_generator_gemm_rv64_get_initial_m_blocking(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !9
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = icmp uge i32 %8, 3001
  br i1 %9, label %10, label %61

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %11, i32 0, i32 8
  %13 = getelementptr inbounds [3 x i8], ptr %12, i64 0, i64 0
  %14 = call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef %13)
  %15 = icmp eq i32 1, %14
  br i1 %15, label %28, label %16

16:                                               ; preds = %10
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %17, i32 0, i32 8
  %19 = getelementptr inbounds [3 x i8], ptr %18, i64 0, i64 0
  %20 = call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef %19)
  %21 = icmp eq i32 8, %20
  br i1 %21, label %28, label %22

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %23, i32 0, i32 8
  %25 = getelementptr inbounds [3 x i8], ptr %24, i64 0, i64 0
  %26 = call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef %25)
  %27 = icmp eq i32 2, %26
  br i1 %27, label %28, label %61

28:                                               ; preds = %22, %16, %10
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 1, !tbaa !11
  %32 = icmp uge i32 %31, 32
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i32 32, ptr %7, align 4, !tbaa !9
  br label %60

34:                                               ; preds = %28
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 1, !tbaa !11
  %38 = icmp uge i32 %37, 16
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i32 16, ptr %7, align 4, !tbaa !9
  br label %59

40:                                               ; preds = %34
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 1, !tbaa !11
  %44 = icmp uge i32 %43, 8
  br i1 %44, label %45, label %46

45:                                               ; preds = %40
  store i32 8, ptr %7, align 4, !tbaa !9
  br label %58

46:                                               ; preds = %40
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 1, !tbaa !11
  %50 = icmp uge i32 %49, 4
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  store i32 4, ptr %7, align 4, !tbaa !9
  br label %57

52:                                               ; preds = %46
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 1, !tbaa !11
  %56 = urem i32 %55, 4
  store i32 %56, ptr %7, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %52, %51
  br label %58

58:                                               ; preds = %57, %45
  br label %59

59:                                               ; preds = %58, %39
  br label %60

60:                                               ; preds = %59, %33
  br label %104

61:                                               ; preds = %22, %3
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp uge i32 %62, 3001
  br i1 %63, label %64, label %102

64:                                               ; preds = %61
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %65, i32 0, i32 8
  %67 = getelementptr inbounds [3 x i8], ptr %66, i64 0, i64 0
  %68 = call i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef %67)
  %69 = icmp eq i32 0, %68
  br i1 %69, label %70, label %102

70:                                               ; preds = %64
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 1, !tbaa !11
  %74 = icmp uge i32 %73, 16
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  store i32 16, ptr %7, align 4, !tbaa !9
  br label %101

76:                                               ; preds = %70
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %78, align 1, !tbaa !11
  %80 = icmp uge i32 %79, 8
  br i1 %80, label %81, label %82

81:                                               ; preds = %76
  store i32 8, ptr %7, align 4, !tbaa !9
  br label %100

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

87:                                               ; preds = %82
  store i32 4, ptr %7, align 4, !tbaa !9
  br label %99

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

93:                                               ; preds = %88
  store i32 2, ptr %7, align 4, !tbaa !9
  br label %98

94:                                               ; preds = %88
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.libxsmm_gemm_descriptor, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %96, align 1, !tbaa !11
  store i32 %97, ptr %7, align 4, !tbaa !9
  br label %98

98:                                               ; preds = %94, %93
  br label %99

99:                                               ; preds = %98, %87
  br label %100

100:                                              ; preds = %99, %81
  br label %101

101:                                              ; preds = %100, %75
  br label %103

102:                                              ; preds = %64, %61
  br label %103

103:                                              ; preds = %102, %101
  br label %104

104:                                              ; preds = %103, %60
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = load i32, ptr %6, align 4, !tbaa !9
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  call void @libxsmm_generator_gemm_init_micro_kernel_config_rv64(ptr noundef %105, i32 noundef %106, ptr noundef %107)
  %108 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %108
}

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}
!11 = !{!12, !10, i64 0}
!12 = !{!"libxsmm_gemm_descriptor", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 28, !7, i64 29, !7, i64 32, !13, i64 33, !13, i64 41, !7, i64 49, !10, i64 50, !10, i64 54, !10, i64 58, !14, i64 62, !14, i64 64, !7, i64 66, !7, i64 67, !7, i64 68, !7, i64 69, !14, i64 70, !14, i64 72, !14, i64 74, !14, i64 76, !14, i64 78, !14, i64 80, !10, i64 82, !10, i64 86, !10, i64 90, !7, i64 94}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"short", !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_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef) local_unnamed_addr #0

declare i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @libxsmm_generator_gemm_init_micro_kernel_config_rv64(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 33) i32 @libxsmm_generator_gemm_rv64_get_initial_m_blocking(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp ugt i32 %2, 3000
  br i1 %4, label %5, label %.critedge

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %1, i64 29
  %7 = tail call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef nonnull %6) #3
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %15, label %9

9:                                                ; preds = %5
  %10 = tail call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef nonnull %6) #3
  %11 = icmp eq i32 %10, 8
  br i1 %11, label %15, label %12

12:                                               ; preds = %9
  %13 = tail call i32 @LIBXSMM_GEMM_GETENUM_C_PREC(ptr noundef nonnull %6) #3
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %23

15:                                               ; preds = %12, %9, %5
  %16 = load i32, ptr %1, align 1, !tbaa !5
  %17 = icmp ugt i32 %16, 31
  br i1 %17, label %.critedge, label %18

18:                                               ; preds = %15
  %19 = icmp ugt i32 %16, 15
  br i1 %19, label %.critedge, label %20

20:                                               ; preds = %18
  %21 = icmp ugt i32 %16, 7
  br i1 %21, label %.critedge, label %22

22:                                               ; preds = %20
  %. = tail call i32 @llvm.umin.i32(i32 %16, i32 4)
  br label %.critedge

23:                                               ; preds = %12
  %24 = tail call i32 @LIBXSMM_GEMM_GETENUM_AB_COMMON_PREC(ptr noundef nonnull %6) #3
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %.critedge

26:                                               ; preds = %23
  %27 = load i32, ptr %1, align 1, !tbaa !5
  %28 = icmp ugt i32 %27, 15
  br i1 %28, label %.critedge, label %29

29:                                               ; preds = %26
  %30 = icmp ugt i32 %27, 7
  br i1 %30, label %.critedge, label %31

31:                                               ; preds = %29
  %32 = icmp ugt i32 %27, 3
  br i1 %32, label %.critedge, label %33

33:                                               ; preds = %31
  %.21 = tail call i32 @llvm.umin.i32(i32 %27, i32 2)
  br label %.critedge

.critedge:                                        ; preds = %3, %33, %31, %29, %26, %22, %20, %18, %15, %23
  %.0 = phi i32 [ 1, %23 ], [ 32, %15 ], [ 16, %18 ], [ 8, %20 ], [ %., %22 ], [ 16, %26 ], [ 8, %29 ], [ 4, %31 ], [ %.21, %33 ], [ 1, %3 ]
  tail call void @libxsmm_generator_gemm_init_micro_kernel_config_rv64(ptr noundef %0, i32 noundef %2, ptr noundef %1)
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"libxsmm_gemm_descriptor", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !8, i64 28, !8, i64 29, !8, i64 32, !10, i64 33, !10, i64 41, !8, i64 49, !7, i64 50, !7, i64 54, !7, i64 58, !11, i64 62, !11, i64 64, !8, i64 66, !8, i64 67, !8, i64 68, !8, i64 69, !11, i64 70, !11, i64 72, !11, i64 74, !11, i64 76, !11, i64 78, !11, i64 80, !7, i64 82, !7, i64 86, !7, i64 90, !8, i64 94}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"short", !8, i64 0}


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