; 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 zeroext i8 @libxsmm_calculate_zpt(i32 noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  %8 = load ptr, ptr %6, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %8, i32 0, i32 25
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %24

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %13, i32 0, i32 35
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds ptr, ptr %15, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !11
  store i8 %23, ptr %7, align 1, !tbaa !11
  br label %87

24:                                               ; preds = %3
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %25, i32 0, i32 25
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = icmp eq i32 %27, 2
  br i1 %28, label %29, label %51

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %30, i32 0, i32 36
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = load ptr, ptr %6, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %33, i32 0, i32 55
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i64, ptr %35, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !20
  %40 = mul nsw i64 %39, 2
  %41 = load ptr, ptr %6, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %41, i32 0, i32 6
  %43 = load i32, ptr %42, align 8, !tbaa !21
  %44 = sext i32 %43 to i64
  %45 = sdiv i64 %40, %44
  %46 = getelementptr inbounds i8, ptr %32, i64 %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  store i8 %50, ptr %7, align 1, !tbaa !11
  br label %86

51:                                               ; preds = %24
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %52, i32 0, i32 25
  %54 = load i32, ptr %53, align 4, !tbaa !12
  %55 = icmp eq i32 %54, 3
  br i1 %55, label %56, label %77

56:                                               ; preds = %51
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %57, i32 0, i32 36
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %60, i32 0, i32 53
  %62 = load i64, ptr %61, align 8, !tbaa !22
  %63 = mul nsw i64 %62, 2
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %64, i32 0, i32 6
  %66 = load i32, ptr %65, align 8, !tbaa !21
  %67 = sext i32 %66 to i64
  %68 = sdiv i64 %63, %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = mul nsw i64 %68, %70
  %72 = getelementptr inbounds i8, ptr %59, i64 %71
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !11
  store i8 %76, ptr %7, align 1, !tbaa !11
  br label %85

77:                                               ; preds = %51
  %78 = load ptr, ptr %6, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.libxsmm_gemm_def, ptr %78, i32 0, i32 36
  %80 = load ptr, ptr %79, align 8, !tbaa !18
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !11
  store i8 %84, ptr %7, align 1, !tbaa !11
  br label %85

85:                                               ; preds = %77, %56
  br label %86

86:                                               ; preds = %85, %29
  br label %87

87:                                               ; preds = %86, %12
  %88 = load i8, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i8 %88
}

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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 108}
!13 = !{!"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, !14, i64 48, !14, 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, !15, 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}
!14 = !{!"double", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!13, !10, i64 168}
!18 = !{!13, !10, i64 176}
!19 = !{!13, !10, i64 280}
!20 = !{!16, !16, i64 0}
!21 = !{!13, !6, i64 24}
!22 = !{!13, !16, 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 zeroext i8 @libxsmm_calculate_zpt(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 108
  %5 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %5, label %39 [
    i32 1, label %6
    i32 2, label %12
    i32 3, label %26
  ]

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %2, i64 168
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds ptr, ptr %8, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  br label %42

12:                                               ; preds = %3
  %13 = getelementptr inbounds i8, ptr %2, i64 176
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %2, i64 280
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  %17 = sext i32 %0 to i64
  %18 = getelementptr inbounds i64, ptr %16, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !18
  %20 = shl nsw i64 %19, 1
  %21 = getelementptr inbounds i8, ptr %2, i64 24
  %22 = load i32, ptr %21, align 8, !tbaa !19
  %23 = sext i32 %22 to i64
  %24 = sdiv i64 %20, %23
  %25 = getelementptr inbounds i8, ptr %14, i64 %24
  br label %42

26:                                               ; preds = %3
  %27 = getelementptr inbounds i8, ptr %2, i64 176
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = getelementptr inbounds i8, ptr %2, i64 264
  %30 = load i64, ptr %29, align 8, !tbaa !20
  %31 = shl nsw i64 %30, 1
  %32 = getelementptr inbounds i8, ptr %2, i64 24
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = sext i32 %33 to i64
  %35 = sdiv i64 %31, %34
  %36 = sext i32 %0 to i64
  %37 = mul nsw i64 %35, %36
  %38 = getelementptr inbounds i8, ptr %28, i64 %37
  br label %42

39:                                               ; preds = %3
  %40 = getelementptr inbounds i8, ptr %2, i64 176
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  br label %42

42:                                               ; preds = %12, %39, %26, %6
  %.sink = phi ptr [ %25, %12 ], [ %41, %39 ], [ %38, %26 ], [ %11, %6 ]
  %43 = sext i32 %1 to i64
  %44 = getelementptr inbounds i8, ptr %.sink, i64 %43
  %.0 = load i8, ptr %44, align 1, !tbaa !21
  ret i8 %.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 108}
!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, !12, i64 168}
!15 = !{!12, !12, i64 0}
!16 = !{!6, !12, i64 176}
!17 = !{!6, !12, i64 280}
!18 = !{!13, !13, i64 0}
!19 = !{!6, !7, i64 24}
!20 = !{!6, !13, i64 264}
!21 = !{!8, !8, i64 0}


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