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

; 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 zeroext i1 @su2_graph_equal(ptr noalias noundef %0, ptr noalias noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.su2_graph, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.su2_graph, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp ne i32 %11, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %131

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.su2_graph, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.su2_graph, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = icmp ne i32 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %17
  store i1 false, ptr %3, align 1
  br label %131

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %27

27:                                               ; preds = %125, %26
  %28 = load i32, ptr %6, align 4, !tbaa !13
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.su2_graph, ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  store i32 2, ptr %7, align 4
  br label %128

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %35

35:                                               ; preds = %119, %34
  %36 = load i32, ptr %8, align 4, !tbaa !13
  %37 = icmp slt i32 %36, 2
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  store i32 5, ptr %7, align 4
  br label %122

39:                                               ; preds = %35
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.su2_graph, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load i32, ptr %6, align 4, !tbaa !13
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.su2_graph_edge, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.su2_graph_edge, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %8, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = icmp slt i32 %50, 0
  br i1 %51, label %52, label %67

52:                                               ; preds = %39
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.su2_graph, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load i32, ptr %6, align 4, !tbaa !13
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds %struct.su2_graph_edge, ptr %55, i64 %57
  %59 = getelementptr inbounds %struct.su2_graph_edge, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %8, align 4, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [2 x i32], ptr %59, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !13
  %64 = icmp sge i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %52
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %122

66:                                               ; preds = %52
  br label %118

67:                                               ; preds = %39
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.su2_graph, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !14
  %71 = load i32, ptr %6, align 4, !tbaa !13
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds %struct.su2_graph_edge, ptr %70, i64 %72
  %74 = getelementptr inbounds %struct.su2_graph_edge, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %8, align 4, !tbaa !13
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [2 x i32], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = icmp slt i32 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %67
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %122

81:                                               ; preds = %67
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.su2_graph, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !15
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.su2_graph, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !14
  %88 = load i32, ptr %6, align 4, !tbaa !13
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.su2_graph_edge, ptr %87, i64 %89
  %91 = getelementptr inbounds %struct.su2_graph_edge, ptr %90, i32 0, i32 0
  %92 = load i32, ptr %8, align 4, !tbaa !13
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [2 x i32], ptr %91, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !13
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds %struct.su2_graph_node, ptr %84, i64 %96
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.su2_graph, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.su2_graph, ptr %101, i32 0, i32 1
  %103 = load ptr, ptr %102, align 8, !tbaa !14
  %104 = load i32, ptr %6, align 4, !tbaa !13
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds %struct.su2_graph_edge, ptr %103, i64 %105
  %107 = getelementptr inbounds %struct.su2_graph_edge, ptr %106, i32 0, i32 0
  %108 = load i32, ptr %8, align 4, !tbaa !13
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [2 x i32], ptr %107, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !13
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds %struct.su2_graph_node, ptr %100, i64 %112
  %114 = call zeroext i1 @su2_graph_node_equal(ptr noundef %97, ptr noundef %113)
  br i1 %114, label %116, label %115

115:                                              ; preds = %81
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %122

116:                                              ; preds = %81
  br label %117

117:                                              ; preds = %116
  br label %118

118:                                              ; preds = %117, %66
  br label %119

119:                                              ; preds = %118
  %120 = load i32, ptr %8, align 4, !tbaa !13
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr %8, align 4, !tbaa !13
  br label %35, !llvm.loop !16

122:                                              ; preds = %115, %80, %65, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %123 = load i32, ptr %7, align 4
  switch i32 %123, label %128 [
    i32 5, label %124
  ]

124:                                              ; preds = %122
  br label %125

125:                                              ; preds = %124
  %126 = load i32, ptr %6, align 4, !tbaa !13
  %127 = add nsw i32 %126, 1
  store i32 %127, ptr %6, align 4, !tbaa !13
  br label %27, !llvm.loop !18

128:                                              ; preds = %122, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %129 = load i32, ptr %7, align 4
  switch i32 %129, label %133 [
    i32 2, label %130
    i32 1, label %131
  ]

130:                                              ; preds = %128
  store i1 true, ptr %3, align 1
  br label %131

131:                                              ; preds = %130, %128, %25, %16
  %132 = load i1, ptr %3, align 1
  ret i1 %132

133:                                              ; preds = %128
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_graph_node_equal(ptr noalias noundef, ptr noalias noundef) #2

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 = { 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 = { 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_graph", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 20}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @su2_graph_equal(ptr noalias nocapture noundef readonly %0, ptr noalias nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i32 %4, %6
  br i1 %.not, label %7, label %.thread

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %1, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %.not34 = icmp eq i32 %9, %11
  br i1 %.not34, label %.preheader36, label %.thread

.preheader36:                                     ; preds = %7
  %12 = icmp slt i32 %9, 1
  br i1 %12, label %.thread, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %.preheader36
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = zext nneg i32 %9 to i64
  %wide.trip.count = zext nneg i32 %9 to i64
  %17 = load ptr, ptr %15, align 8, !tbaa !12
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %53
  %indvars.iv = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next, %53 ]
  %18 = getelementptr inbounds %struct.su2_graph_edge, ptr %14, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = icmp slt i32 %19, 0
  %21 = getelementptr inbounds %struct.su2_graph_edge, ptr %17, i64 %indvars.iv
  %22 = load i32, ptr %21, align 4, !tbaa !13
  br i1 %20, label %23, label %25

23:                                               ; preds = %.preheader
  %24 = icmp sgt i32 %22, -1
  br i1 %24, label %.thread, label %35

25:                                               ; preds = %.preheader
  %26 = icmp slt i32 %22, 0
  br i1 %26, label %.thread, label %27

27:                                               ; preds = %25
  %28 = load ptr, ptr %0, align 8, !tbaa !14
  %29 = zext nneg i32 %19 to i64
  %30 = getelementptr inbounds %struct.su2_graph_node, ptr %28, i64 %29
  %31 = load ptr, ptr %1, align 8, !tbaa !14
  %32 = zext nneg i32 %22 to i64
  %33 = getelementptr inbounds %struct.su2_graph_node, ptr %31, i64 %32
  %34 = tail call zeroext i1 @su2_graph_node_equal(ptr noundef %30, ptr noundef %33)
  br i1 %34, label %35, label %.thread

35:                                               ; preds = %23, %27
  %36 = getelementptr inbounds i8, ptr %18, i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = icmp slt i32 %37, 0
  %39 = getelementptr inbounds %struct.su2_graph_edge, ptr %17, i64 %indvars.iv, i32 0, i64 1
  %40 = load i32, ptr %39, align 4, !tbaa !13
  br i1 %38, label %51, label %41

41:                                               ; preds = %35
  %42 = icmp slt i32 %40, 0
  br i1 %42, label %.thread, label %43

43:                                               ; preds = %41
  %44 = load ptr, ptr %0, align 8, !tbaa !14
  %45 = zext nneg i32 %37 to i64
  %46 = getelementptr inbounds %struct.su2_graph_node, ptr %44, i64 %45
  %47 = load ptr, ptr %1, align 8, !tbaa !14
  %48 = zext nneg i32 %40 to i64
  %49 = getelementptr inbounds %struct.su2_graph_node, ptr %47, i64 %48
  %50 = tail call zeroext i1 @su2_graph_node_equal(ptr noundef %46, ptr noundef %49)
  br i1 %50, label %53, label %.thread

51:                                               ; preds = %35
  %52 = icmp sgt i32 %40, -1
  br i1 %52, label %.thread, label %53

53:                                               ; preds = %51, %43
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %.thread.loopexit42, label %.preheader, !llvm.loop !15

.thread.loopexit42:                               ; preds = %53
  %54 = icmp uge i64 %indvars.iv.next, %16
  br label %.thread

.thread:                                          ; preds = %27, %25, %23, %41, %43, %51, %.thread.loopexit42, %.preheader36, %7, %2
  %.3 = phi i1 [ false, %2 ], [ false, %7 ], [ true, %.preheader36 ], [ %54, %.thread.loopexit42 ], [ false, %51 ], [ false, %43 ], [ false, %41 ], [ false, %23 ], [ false, %25 ], [ false, %27 ]
  ret i1 %.3
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_graph_node_equal(ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #1

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

!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_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, !10, i64 20}
!12 = !{!6, !7, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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