; LLVM IR from qc-tum/chemtensor :: src/tensor (su2_graph)

; 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.su2_graph = type { ptr, ptr, i32, i32 }
%struct.su2_graph_edge = type { [2 x i32] }
%struct.su2_graph_node = type { i32, [2 x i32], i32 }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__.su2_graph_has_fuse_split_tree_topology = external hidden unnamed_addr constant [71 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @su2_graph_has_fuse_split_tree_topology(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.su2_graph, ptr %4, i32 0, i32 3
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 291, ptr noundef @__PRETTY_FUNCTION__.su2_graph_has_fuse_split_tree_topology) #4
  unreachable

10:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.su2_graph, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds %struct.su2_graph_edge, ptr %13, i64 0
  store ptr %14, ptr %3, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %32, %10
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.su2_graph_edge, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds [2 x i32], ptr %18, i64 0, i64 0
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = call zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef %16, i32 noundef %20)
  br i1 %21, label %22, label %30

22:                                               ; preds = %15
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.su2_graph_edge, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [2 x i32], ptr %25, i64 0, i64 1
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = call zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef %23, i32 noundef %27)
  %29 = xor i1 %28, true
  br label %30

30:                                               ; preds = %22, %15
  %31 = phi i1 [ false, %15 ], [ %29, %22 ]
  br i1 %31, label %32, label %49

32:                                               ; preds = %30
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.su2_graph, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.su2_graph, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.su2_graph_edge, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [2 x i32], ptr %40, i64 0, i64 1
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.su2_graph_node, ptr %38, i64 %43
  %45 = getelementptr inbounds %struct.su2_graph_node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !15
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.su2_graph_edge, ptr %35, i64 %47
  store ptr %48, ptr %3, align 8, !tbaa !5
  br label %15, !llvm.loop !17

49:                                               ; preds = %30
  br label %50

50:                                               ; preds = %67, %49
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.su2_graph_edge, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [2 x i32], ptr %53, i64 0, i64 1
  %55 = load i32, ptr %54, align 4, !tbaa !13
  %56 = call zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef %51, i32 noundef %55)
  br i1 %56, label %57, label %65

57:                                               ; preds = %50
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.su2_graph_edge, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds [2 x i32], ptr %60, i64 0, i64 0
  %62 = load i32, ptr %61, align 4, !tbaa !13
  %63 = call zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef %58, i32 noundef %62)
  %64 = xor i1 %63, true
  br label %65

65:                                               ; preds = %57, %50
  %66 = phi i1 [ false, %50 ], [ %64, %57 ]
  br i1 %66, label %67, label %84

67:                                               ; preds = %65
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.su2_graph, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !12
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.su2_graph, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !14
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.su2_graph_edge, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds [2 x i32], ptr %75, i64 0, i64 0
  %77 = load i32, ptr %76, align 4, !tbaa !13
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct.su2_graph_node, ptr %73, i64 %78
  %80 = getelementptr inbounds %struct.su2_graph_node, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 4, !tbaa !15
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %struct.su2_graph_edge, ptr %70, i64 %82
  store ptr %83, ptr %3, align 8, !tbaa !5
  br label %50, !llvm.loop !19

84:                                               ; preds = %65
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.su2_graph_edge, ptr %86, i32 0, i32 0
  %88 = getelementptr inbounds [2 x i32], ptr %87, i64 0, i64 0
  %89 = load i32, ptr %88, align 4, !tbaa !13
  %90 = call zeroext i1 @su2_subgraph_is_fuse_tree(ptr noundef %85, i32 noundef %89)
  br i1 %90, label %91, label %98

91:                                               ; preds = %84
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.su2_graph_edge, ptr %93, i32 0, i32 0
  %95 = getelementptr inbounds [2 x i32], ptr %94, i64 0, i64 1
  %96 = load i32, ptr %95, align 4, !tbaa !13
  %97 = call zeroext i1 @su2_subgraph_is_split_tree(ptr noundef %92, i32 noundef %96)
  br label %98

98:                                               ; preds = %91, %84
  %99 = phi i1 [ false, %84 ], [ %97, %91 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret i1 %99
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef, i32 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @su2_subgraph_is_fuse_tree(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @su2_subgraph_is_split_tree(ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { inlinehint 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 #4 = { noreturn nounwind }
attributes #5 = { 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, !11, i64 20}
!10 = !{!"su2_graph", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"su2_graph_node", !11, i64 0, !7, i64 4, !11, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

%struct.su2_graph_node = type { i32, [2 x i32], i32 }
%struct.su2_graph_edge = type { [2 x i32] }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__.su2_graph_has_fuse_split_tree_topology = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @su2_graph_has_fuse_split_tree_topology(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 291, ptr noundef nonnull @__PRETTY_FUNCTION__.su2_graph_has_fuse_split_tree_topology) #3
  unreachable

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = tail call zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef nonnull %0, i32 noundef %9)
  br i1 %10, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %6, %14
  %.022 = phi ptr [ %22, %14 ], [ %8, %6 ]
  %11 = getelementptr inbounds i8, ptr %.022, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = tail call zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef nonnull %0, i32 noundef %12)
  br i1 %13, label %.critedge, label %14

14:                                               ; preds = %.lr.ph
  %15 = load ptr, ptr %7, align 8, !tbaa !11
  %16 = load ptr, ptr %0, align 8, !tbaa !13
  %17 = load i32, ptr %11, align 4, !tbaa !12
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.su2_graph_node, ptr %16, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.su2_graph_edge, ptr %15, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = tail call zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef nonnull %0, i32 noundef %23)
  br i1 %24, label %.lr.ph, label %.critedge, !llvm.loop !16

.critedge:                                        ; preds = %.lr.ph, %14, %6
  %.0.lcssa = phi ptr [ %8, %6 ], [ %22, %14 ], [ %.022, %.lr.ph ]
  %25 = getelementptr inbounds i8, ptr %.0.lcssa, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = tail call zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef %0, i32 noundef %26)
  br i1 %27, label %.lr.ph27, label %.critedge2

.lr.ph27:                                         ; preds = %.critedge, %30
  %.126 = phi ptr [ %38, %30 ], [ %.0.lcssa, %.critedge ]
  %28 = load i32, ptr %.126, align 4, !tbaa !12
  %29 = tail call zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef %0, i32 noundef %28)
  br i1 %29, label %.critedge2, label %30

30:                                               ; preds = %.lr.ph27
  %31 = load ptr, ptr %7, align 8, !tbaa !11
  %32 = load ptr, ptr %0, align 8, !tbaa !13
  %33 = load i32, ptr %.126, align 4, !tbaa !12
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.su2_graph_node, ptr %32, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %struct.su2_graph_edge, ptr %31, i64 %37
  %39 = getelementptr inbounds i8, ptr %38, i64 4
  %40 = load i32, ptr %39, align 4, !tbaa !12
  %41 = tail call zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef nonnull %0, i32 noundef %40)
  br i1 %41, label %.lr.ph27, label %.critedge2, !llvm.loop !18

.critedge2:                                       ; preds = %.lr.ph27, %30, %.critedge
  %.1.lcssa25 = phi ptr [ %.0.lcssa, %.critedge ], [ %38, %30 ], [ %.126, %.lr.ph27 ]
  %42 = load i32, ptr %.1.lcssa25, align 4, !tbaa !12
  %43 = tail call zeroext i1 @su2_subgraph_is_fuse_tree(ptr noundef %0, i32 noundef %42)
  br i1 %43, label %44, label %48

44:                                               ; preds = %.critedge2
  %45 = getelementptr inbounds i8, ptr %.1.lcssa25, i64 4
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = tail call zeroext i1 @su2_subgraph_is_split_tree(ptr noundef %0, i32 noundef %46)
  br label %48

48:                                               ; preds = %44, %.critedge2
  %49 = phi i1 [ false, %.critedge2 ], [ %47, %44 ]
  ret i1 %49
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_graph_node_fuse_or_leaf(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_graph_node_split_or_leaf(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @su2_subgraph_is_fuse_tree(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @su2_subgraph_is_split_tree(ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { noreturn nounwind "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 = { inlinehint 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 = { noreturn 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, !10, i64 20}
!6 = !{!"su2_graph", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"su2_graph_node", !10, i64 0, !8, i64 4, !10, i64 12}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass