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

; 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_meqn_elem = type { ptr, ptr, ptr, ptr, i32, %union.libxsmm_meqn_info, i32, i32, %struct.libxsmm_meqn_tmp_info, i32, i32, i32, %union.libxsmm_meqn_fusion_info }
%union.libxsmm_meqn_info = type { %struct.libxsmm_meqn_arg }
%struct.libxsmm_meqn_arg = type { i32, i32, i32, i32, i32, i32, i32, %struct.libxsmm_matrix_arg_attributes }
%struct.libxsmm_matrix_arg_attributes = type { i32, i32, i32, i32 }
%struct.libxsmm_meqn_tmp_info = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%union.libxsmm_meqn_fusion_info = type { %struct.libxsmm_meqn_xgemm_fusion_info }
%struct.libxsmm_meqn_xgemm_fusion_info = type { i32, i32, i32, i32, i32 }
%struct.libxsmm_meqn_binary_op = type { i32, i32, i32, i32, i32, i32 }
%struct.libxsmm_meqn_unary_op = type { i32, i32, i32, i32 }

; 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 i32 @libxsmm_generator_matequation_find_xgemm_fusion_pattern_with_ancestors(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %131

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %13, i32 0, i32 4
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp eq i32 %15, 2
  br i1 %16, label %17, label %103

17:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %17
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  store ptr %30, ptr %4, align 8, !tbaa !5
  store i32 8, ptr %5, align 4, !tbaa !9
  br label %37

31:                                               ; preds = %17
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  store ptr %36, ptr %4, align 8, !tbaa !5
  store i32 4, ptr %5, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %31, %25
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %40, i32 0, i32 5
  %42 = getelementptr inbounds %struct.libxsmm_meqn_binary_op, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = icmp eq i32 %43, 1
  br i1 %44, label %45, label %102

45:                                               ; preds = %37
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = icmp eq i32 %48, 8
  br i1 %49, label %50, label %102

50:                                               ; preds = %45
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %53, i32 0, i32 5
  %55 = getelementptr inbounds %struct.libxsmm_meqn_binary_op, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !11
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = and i32 %56, %57
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = icmp eq i32 %58, %59
  br i1 %60, label %61, label %102

61:                                               ; preds = %50
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %64, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %100

68:                                               ; preds = %61
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %73, i32 0, i32 4
  %75 = load i32, ptr %74, align 8, !tbaa !11
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %98

77:                                               ; preds = %68
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %80, i32 0, i32 3
  %82 = load ptr, ptr %81, align 8, !tbaa !11
  %83 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %82, i32 0, i32 5
  %84 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 4, !tbaa !11
  %86 = icmp eq i32 %85, 5
  br i1 %86, label %97, label %87

87:                                               ; preds = %77
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %88, i32 0, i32 3
  %90 = load ptr, ptr %89, align 8, !tbaa !11
  %91 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %90, i32 0, i32 3
  %92 = load ptr, ptr %91, align 8, !tbaa !11
  %93 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %92, i32 0, i32 5
  %94 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %93, i32 0, i32 0
  %95 = load i32, ptr %94, align 4, !tbaa !11
  %96 = icmp eq i32 %95, 9
  br i1 %96, label %97, label %98

97:                                               ; preds = %87, %77
  store i32 3, ptr %3, align 4, !tbaa !9
  br label %99

98:                                               ; preds = %87, %68
  store i32 2, ptr %3, align 4, !tbaa !9
  br label %99

99:                                               ; preds = %98, %97
  br label %101

100:                                              ; preds = %61
  store i32 2, ptr %3, align 4, !tbaa !9
  br label %101

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

102:                                              ; preds = %101, %50, %45, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %130

103:                                              ; preds = %10
  %104 = load ptr, ptr %2, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %104, i32 0, i32 3
  %106 = load ptr, ptr %105, align 8, !tbaa !11
  %107 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %106, i32 0, i32 4
  %108 = load i32, ptr %107, align 8, !tbaa !11
  %109 = icmp eq i32 %108, 1
  br i1 %109, label %110, label %128

110:                                              ; preds = %103
  %111 = load ptr, ptr %2, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %111, i32 0, i32 3
  %113 = load ptr, ptr %112, align 8, !tbaa !11
  %114 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %113, i32 0, i32 5
  %115 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %114, i32 0, i32 0
  %116 = load i32, ptr %115, align 4, !tbaa !11
  %117 = icmp eq i32 %116, 5
  br i1 %117, label %126, label %118

118:                                              ; preds = %110
  %119 = load ptr, ptr %2, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %119, i32 0, i32 3
  %121 = load ptr, ptr %120, align 8, !tbaa !11
  %122 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %121, i32 0, i32 5
  %123 = getelementptr inbounds %struct.libxsmm_meqn_unary_op, ptr %122, i32 0, i32 0
  %124 = load i32, ptr %123, align 4, !tbaa !11
  %125 = icmp eq i32 %124, 9
  br i1 %125, label %126, label %127

126:                                              ; preds = %118, %110
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %127

127:                                              ; preds = %126, %118
  br label %129

128:                                              ; preds = %103
  br label %129

129:                                              ; preds = %128, %127
  br label %130

130:                                              ; preds = %129, %102
  br label %131

131:                                              ; preds = %130, %1
  %132 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %132
}

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 = !{!"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 = !{!7, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 4) i32 @libxsmm_generator_matequation_find_xgemm_fusion_pattern_with_ancestors(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %44, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 32
  %6 = load i32, ptr %5, align 8, !tbaa !5
  switch i32 %6, label %44 [
    i32 2, label %7
    i32 1, label %39
  ]

7:                                                ; preds = %4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, %0
  br i1 %9, label %10, label %13

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %7, %10
  %.018 = phi ptr [ %12, %10 ], [ %8, %7 ]
  %14 = phi i32 [ -9, %10 ], [ -5, %7 ]
  %15 = getelementptr inbounds i8, ptr %3, i64 36
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %44

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %.018, i64 32
  %20 = load i32, ptr %19, align 8, !tbaa !5
  %21 = icmp eq i32 %20, 8
  br i1 %21, label %22, label %44

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %3, i64 40
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = or i32 %24, %14
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %44

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %3, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %.not26 = icmp eq ptr %29, null
  br i1 %.not26, label %44, label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %29, i64 32
  %32 = load i32, ptr %31, align 8, !tbaa !5
  %33 = icmp eq i32 %32, 1
  br i1 %33, label %34, label %44

34:                                               ; preds = %30
  %35 = getelementptr inbounds i8, ptr %29, i64 36
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add i32 %36, -5
  %switch.and = and i32 %37, -5
  %switch.selectcmp = icmp eq i32 %switch.and, 0
  %38 = select i1 %switch.selectcmp, i32 3, i32 2
  br label %44

39:                                               ; preds = %4
  %40 = getelementptr inbounds i8, ptr %3, i64 36
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add i32 %41, -5
  %switch.and27 = and i32 %42, -5
  %switch.selectcmp28 = icmp eq i32 %switch.and27, 0
  %43 = zext i1 %switch.selectcmp28 to i32
  br label %44

44:                                               ; preds = %39, %30, %34, %4, %13, %18, %22, %27, %1
  %.1 = phi i32 [ 0, %1 ], [ 0, %22 ], [ 0, %18 ], [ 0, %13 ], [ 2, %27 ], [ 0, %4 ], [ %38, %34 ], [ 2, %30 ], [ %43, %39 ]
  ret i32 %.1
}

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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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