; 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 }
%struct.libxsmm_meqn_binary_op = type { i32, i32, 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_meqn_can_overwrite_binary_input(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = 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 1, ptr %3, align 4, !tbaa !9
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %4, i32 0, i32 5
  %6 = getelementptr inbounds %struct.libxsmm_meqn_binary_op, ptr %5, i32 0, i32 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %15, label %9

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

15:                                               ; preds = %9, %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %15, %9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %19, i32 0, i32 8
  %21 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %80, label %24

24:                                               ; preds = %16
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %27, i32 0, i32 8
  %29 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %80, label %32

32:                                               ; preds = %24
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %35, i32 0, i32 8
  %37 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = icmp eq i32 %38, 3
  br i1 %39, label %80, label %40

40:                                               ; preds = %32
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %43, i32 0, i32 8
  %45 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %44, i32 0, i32 4
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = icmp eq i32 %46, 3
  br i1 %47, label %80, label %48

48:                                               ; preds = %40
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %51, i32 0, i32 8
  %53 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = icmp eq i32 %54, 5
  br i1 %55, label %80, label %56

56:                                               ; preds = %48
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %59, i32 0, i32 8
  %61 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %60, i32 0, i32 4
  %62 = load i32, ptr %61, align 8, !tbaa !11
  %63 = icmp eq i32 %62, 5
  br i1 %63, label %80, label %64

64:                                               ; preds = %56
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %67, i32 0, i32 8
  %69 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %68, i32 0, i32 4
  %70 = load i32, ptr %69, align 8, !tbaa !11
  %71 = icmp eq i32 %70, 4
  br i1 %71, label %80, label %72

72:                                               ; preds = %64
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %75, i32 0, i32 8
  %77 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %76, i32 0, i32 4
  %78 = load i32, ptr %77, align 8, !tbaa !11
  %79 = icmp eq i32 %78, 4
  br i1 %79, label %80, label %93

80:                                               ; preds = %72, %64, %56, %48, %40, %32, %24, %16
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %81, i32 0, i32 8
  %83 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %82, i32 0, i32 4
  %84 = load i32, ptr %83, align 8, !tbaa !11
  %85 = icmp eq i32 %84, 1
  br i1 %85, label %92, label %86

86:                                               ; preds = %80
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.libxsmm_meqn_elem, ptr %87, i32 0, i32 8
  %89 = getelementptr inbounds %struct.libxsmm_meqn_tmp_info, ptr %88, i32 0, i32 4
  %90 = load i32, ptr %89, align 8, !tbaa !11
  %91 = icmp eq i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %86, %80
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %92, %86, %72
  %94 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %94
}

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, 2) i32 @libxsmm_meqn_can_overwrite_binary_input(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 52
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %9, label %5

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

9:                                                ; preds = %5, %1
  br label %10

10:                                               ; preds = %9, %5
  %.0 = phi i32 [ 0, %9 ], [ 1, %5 ]
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 104
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %27, label %15

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 104
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = icmp eq i32 %13, 3
  %21 = and i32 %19, -2
  %22 = icmp eq i32 %21, 2
  %or.cond15 = or i1 %20, %22
  %23 = icmp eq i32 %13, 5
  %or.cond16 = or i1 %23, %or.cond15
  %24 = icmp eq i32 %19, 5
  %or.cond17 = or i1 %24, %or.cond16
  %25 = icmp eq i32 %13, 4
  %or.cond18 = or i1 %25, %or.cond17
  %26 = icmp eq i32 %19, 4
  %or.cond19 = or i1 %26, %or.cond18
  br i1 %or.cond19, label %27, label %30

27:                                               ; preds = %15, %10
  %28 = getelementptr inbounds i8, ptr %0, i64 104
  %29 = load i32, ptr %28, align 8, !tbaa !5
  %switch = icmp ult i32 %29, 2
  %spec.select = select i1 %switch, i32 0, i32 %.0
  br label %30

30:                                               ; preds = %27, %15
  %.1 = phi i32 [ %.0, %15 ], [ %spec.select, %27 ]
  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,ReassociatePass,SROAPass,SimplifyCFGPass