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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @ct_free(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_tree_node_is_leaf(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @su2_tree_axes_indicator(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ct_calloc(i64 noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @su2_fuse_split_tree_is_consistent(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp sle i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %133

14:                                               ; preds = %1
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = icmp eq ptr %17, null
  br i1 %18, label %24, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %19, %14
  store i1 false, ptr %2, align 1
  br label %133

25:                                               ; preds = %19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = getelementptr inbounds %struct.su2_tree_node, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct.su2_tree_node, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !14
  %36 = icmp ne i32 %30, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %25
  store i1 false, ptr %2, align 1
  br label %133

38:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.su2_tree_node, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !14
  store i32 %43, ptr %4, align 4, !tbaa !16
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !12
  %47 = call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %46)
  br i1 %47, label %48, label %54

48:                                               ; preds = %38
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %51)
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %132

54:                                               ; preds = %48, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = call ptr @ct_calloc(i64 noundef %58, i64 noundef 1)
  store ptr %59, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = call ptr @ct_calloc(i64 noundef %63, i64 noundef 1)
  store ptr %64, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  call void @su2_tree_axes_indicator(ptr noundef %67, ptr noundef %68)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  call void @su2_tree_axes_indicator(ptr noundef %71, ptr noundef %72)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !16
  br label %73

73:                                               ; preds = %123, %54
  %74 = load i32, ptr %8, align 4, !tbaa !16
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.su2_fuse_split_tree, ptr %75, i32 0, i32 2
  %77 = load i32, ptr %76, align 8, !tbaa !9
  %78 = icmp slt i32 %74, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %73
  store i32 2, ptr %5, align 4
  br label %126

80:                                               ; preds = %73
  %81 = load i32, ptr %8, align 4, !tbaa !16
  %82 = load i32, ptr %4, align 4, !tbaa !16
  %83 = icmp eq i32 %81, %82
  br i1 %83, label %84, label %102

84:                                               ; preds = %80
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load i32, ptr %8, align 4, !tbaa !16
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %85, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !17, !range !19, !noundef !20
  %90 = trunc i8 %89 to i1
  br i1 %90, label %91, label %98

91:                                               ; preds = %84
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = load i32, ptr %8, align 4, !tbaa !16
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i8, ptr %92, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !17, !range !19, !noundef !20
  %97 = trunc i8 %96 to i1
  br i1 %97, label %101, label %98

98:                                               ; preds = %91, %84
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ct_free(ptr noundef %99)
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ct_free(ptr noundef %100)
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %126

101:                                              ; preds = %91
  br label %122

102:                                              ; preds = %80
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load i32, ptr %8, align 4, !tbaa !16
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds i8, ptr %103, i64 %105
  %107 = load i8, ptr %106, align 1, !tbaa !17, !range !19, !noundef !20
  %108 = trunc i8 %107 to i1
  %109 = zext i1 %108 to i32
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = load i32, ptr %8, align 4, !tbaa !16
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds i8, ptr %110, i64 %112
  %114 = load i8, ptr %113, align 1, !tbaa !17, !range !19, !noundef !20
  %115 = trunc i8 %114 to i1
  %116 = zext i1 %115 to i32
  %117 = icmp eq i32 %109, %116
  br i1 %117, label %118, label %121

118:                                              ; preds = %102
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ct_free(ptr noundef %119)
  %120 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ct_free(ptr noundef %120)
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %126

121:                                              ; preds = %102
  br label %122

122:                                              ; preds = %121, %101
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %8, align 4, !tbaa !16
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %8, align 4, !tbaa !16
  br label %73, !llvm.loop !21

126:                                              ; preds = %118, %98, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %127 = load i32, ptr %5, align 4
  switch i32 %127, label %131 [
    i32 2, label %128
  ]

128:                                              ; preds = %126
  %129 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ct_free(ptr noundef %129)
  %130 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ct_free(ptr noundef %130)
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %131

131:                                              ; preds = %128, %126
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %132

132:                                              ; preds = %131, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %133

133:                                              ; preds = %132, %37, %24, %13
  %134 = load i1, ptr %2, align 1
  ret i1 %134
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 16}
!10 = !{!"su2_fuse_split_tree", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !11, i64 0}
!15 = !{!"su2_tree_node", !11, i64 0, !7, i64 8}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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: inlinehint nounwind uwtable
declare hidden void @ct_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_tree_node_is_leaf(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @su2_tree_axes_indicator(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ct_calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @su2_fuse_split_tree_is_consistent(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp slt i32 %3, 1
  br i1 %4, label %49, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr %0, align 8, !tbaa !11
  %7 = icmp eq ptr %6, null
  br i1 %7, label %49, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = icmp eq ptr %10, null
  br i1 %11, label %49, label %12

12:                                               ; preds = %8
  %13 = load i32, ptr %6, align 8, !tbaa !13
  %14 = load i32, ptr %10, align 8, !tbaa !13
  %.not = icmp eq i32 %13, %14
  br i1 %.not, label %15, label %49

15:                                               ; preds = %12
  %16 = tail call zeroext i1 @su2_tree_node_is_leaf(ptr noundef nonnull %6)
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = load ptr, ptr %9, align 8, !tbaa !12
  %19 = tail call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %18)
  br i1 %19, label %49, label %20

20:                                               ; preds = %17, %15
  %21 = load i32, ptr %2, align 8, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = tail call ptr @ct_calloc(i64 noundef %22, i64 noundef 1)
  %24 = load i32, ptr %2, align 8, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = tail call ptr @ct_calloc(i64 noundef %25, i64 noundef 1)
  %27 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @su2_tree_axes_indicator(ptr noundef %27, ptr noundef %23)
  %28 = load ptr, ptr %9, align 8, !tbaa !12
  tail call void @su2_tree_axes_indicator(ptr noundef %28, ptr noundef %26)
  %29 = load i32, ptr %2, align 8, !tbaa !5
  %.not39.not40 = icmp sgt i32 %29, 0
  br i1 %.not39.not40, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %20
  %30 = zext i32 %13 to i64
  %wide.trip.count = zext nneg i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %23, i64 %30
  %32 = getelementptr inbounds i8, ptr %26, i64 %30
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %48
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %48 ]
  %33 = icmp eq i64 %indvars.iv, %30
  br i1 %33, label %34, label %41

34:                                               ; preds = %.lr.ph
  %35 = load i8, ptr %31, align 1, !tbaa !15, !range !17, !noundef !18
  %36 = trunc nuw i8 %35 to i1
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load i8, ptr %32, align 1, !tbaa !15, !range !17, !noundef !18
  %39 = trunc nuw i8 %38 to i1
  br i1 %39, label %48, label %40

40:                                               ; preds = %37, %34
  tail call void @ct_free(ptr noundef %26)
  tail call void @ct_free(ptr noundef nonnull %23)
  br label %49

41:                                               ; preds = %.lr.ph
  %42 = getelementptr inbounds i8, ptr %23, i64 %indvars.iv
  %43 = load i8, ptr %42, align 1, !tbaa !15, !range !17, !noundef !18
  %44 = getelementptr inbounds i8, ptr %26, i64 %indvars.iv
  %45 = load i8, ptr %44, align 1, !tbaa !15, !range !17, !noundef !18
  %46 = icmp eq i8 %43, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  tail call void @ct_free(ptr noundef nonnull %26)
  tail call void @ct_free(ptr noundef nonnull %23)
  br label %49

48:                                               ; preds = %37, %41
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !19

.critedge:                                        ; preds = %48, %20
  tail call void @ct_free(ptr noundef %26)
  tail call void @ct_free(ptr noundef %23)
  br label %49

49:                                               ; preds = %40, %47, %17, %.critedge, %12, %5, %8, %1
  %.3 = phi i1 [ false, %1 ], [ false, %8 ], [ false, %5 ], [ false, %12 ], [ false, %17 ], [ true, %.critedge ], [ false, %47 ], [ false, %40 ]
  ret i1 %.3
}

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

!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 16}
!6 = !{!"su2_fuse_split_tree", !7, i64 0, !7, i64 8, !10, i64 16}
!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 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"su2_tree_node", !10, i64 0, !8, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass