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

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

; Function Attrs: nounwind uwtable
define dso_local void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %7, i32 0, i32 4
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp eq i32 %9, 8
  br i1 %10, label %11, label %21

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %12, i32 0, i32 5
  %14 = getelementptr inbounds %struct.libxsmm_meqn_arg, ptr %13, i32 0, i32 5
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp ne i32 %15, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %18, %11
  br label %72

21:                                               ; preds = %3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %22, i32 0, i32 4
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %32

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %29, i32 noundef %30, ptr noundef %31)
  br label %71

32:                                               ; preds = %21
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %33, i32 0, i32 4
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %48

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %40, i32 noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %45, i32 noundef %46, ptr noundef %47)
  br label %70

48:                                               ; preds = %32
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %49, i32 0, i32 4
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = icmp eq i32 %51, 4
  br i1 %52, label %53, label %69

53:                                               ; preds = %48
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %56, i32 noundef %57, ptr noundef %58)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %61, i32 noundef %62, ptr noundef %63)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %66, i32 noundef %67, ptr noundef %68)
  br label %69

69:                                               ; preds = %53, %48
  br label %70

70:                                               ; preds = %69, %37
  br label %71

71:                                               ; preds = %70, %26
  br label %72

72:                                               ; preds = %71, %20
  ret void
}

attributes #0 = { 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" }

!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: nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @libxsmm_meqn_tree_all_args_dtype(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %3
  %.tr = phi ptr [ %0, %3 ], [ %.tr.be, %tailrecurse.backedge ]
  %4 = getelementptr inbounds i8, ptr %.tr, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  switch i32 %5, label %.loopexit [
    i32 8, label %6
    i32 1, label %tailrecurse.backedge
    i32 2, label %tailrecurse.backedge.sink.split
    i32 4, label %12
  ]

6:                                                ; preds = %tailrecurse
  %7 = getelementptr inbounds i8, ptr %.tr, i64 56
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %8, %1
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %6
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %.loopexit

tailrecurse.backedge.sink.split:                  ; preds = %tailrecurse, %12
  %.tr.sink = phi ptr [ %14, %12 ], [ %.tr, %tailrecurse ]
  %.sink = phi i64 [ 16, %12 ], [ 8, %tailrecurse ]
  %10 = load ptr, ptr %.tr.sink, align 8, !tbaa !5
  tail call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %10, i32 noundef %1, ptr noundef %2)
  %11 = getelementptr inbounds i8, ptr %.tr, i64 %.sink
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %tailrecurse.backedge.sink.split, %tailrecurse
  %.tr.be.in = phi ptr [ %.tr, %tailrecurse ], [ %11, %tailrecurse.backedge.sink.split ]
  %.tr.be = load ptr, ptr %.tr.be.in, align 8, !tbaa !5
  br label %tailrecurse

12:                                               ; preds = %tailrecurse
  %13 = load ptr, ptr %.tr, align 8, !tbaa !5
  tail call void @libxsmm_meqn_tree_all_args_dtype(ptr noundef %13, i32 noundef %1, ptr noundef %2)
  %14 = getelementptr inbounds i8, ptr %.tr, i64 8
  br label %tailrecurse.backedge.sink.split

.loopexit:                                        ; preds = %tailrecurse, %6, %9
  ret void
}

attributes #0 = { nofree nosync nounwind memory(readwrite, 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"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass