; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (computational_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.computation_node_t = type { i32, i32, ptr, i64, i64, ptr, ptr, ptr, ptr, ptr }

; 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 @disconnect_nodes(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  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 = icmp ne ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %11, %2
  store i1 false, ptr %3, align 1
  br label %106

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %56, %15
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.computation_node_t, ptr %18, i32 0, i32 4
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i64 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  br label %59

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.computation_node_t, ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %26, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = icmp eq ptr %29, %30
  br i1 %31, label %32, label %55

32:                                               ; preds = %23
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.computation_node_t, ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = getelementptr inbounds ptr, ptr %35, i64 %36
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.computation_node_t, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = add i64 %41, 1
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.computation_node_t, ptr %44, i32 0, i32 4
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = sub i64 %46, %47
  %49 = sub i64 %48, 1
  %50 = mul i64 %49, 8
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %37, ptr align 8 %43, i64 %50, i1 false)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.computation_node_t, ptr %51, i32 0, i32 4
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = add i64 %53, -1
  store i64 %54, ptr %52, align 8, !tbaa !11
  store i32 2, ptr %7, align 4
  br label %59

55:                                               ; preds = %23
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %6, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %6, align 8, !tbaa !9
  br label %16, !llvm.loop !15

59:                                               ; preds = %32, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %60

60:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %101, %60
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.computation_node_t, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !17
  %66 = icmp ult i64 %62, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %61
  store i32 5, ptr %7, align 4
  br label %104

68:                                               ; preds = %61
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.computation_node_t, ptr %69, i32 0, i32 5
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = getelementptr inbounds ptr, ptr %71, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = icmp eq ptr %74, %75
  br i1 %76, label %77, label %100

77:                                               ; preds = %68
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.computation_node_t, ptr %78, i32 0, i32 5
  %80 = load ptr, ptr %79, align 8, !tbaa !18
  %81 = load i64, ptr %8, align 8, !tbaa !9
  %82 = getelementptr inbounds ptr, ptr %80, i64 %81
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.computation_node_t, ptr %83, i32 0, i32 5
  %85 = load ptr, ptr %84, align 8, !tbaa !18
  %86 = load i64, ptr %8, align 8, !tbaa !9
  %87 = add i64 %86, 1
  %88 = getelementptr inbounds ptr, ptr %85, i64 %87
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.computation_node_t, ptr %89, i32 0, i32 3
  %91 = load i64, ptr %90, align 8, !tbaa !17
  %92 = load i64, ptr %8, align 8, !tbaa !9
  %93 = sub i64 %91, %92
  %94 = sub i64 %93, 1
  %95 = mul i64 %94, 8
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %82, ptr align 8 %88, i64 %95, i1 false)
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.computation_node_t, ptr %96, i32 0, i32 3
  %98 = load i64, ptr %97, align 8, !tbaa !17
  %99 = add i64 %98, -1
  store i64 %99, ptr %97, align 8, !tbaa !17
  store i32 5, ptr %7, align 4
  br label %104

100:                                              ; preds = %68
  br label %101

101:                                              ; preds = %100
  %102 = load i64, ptr %8, align 8, !tbaa !9
  %103 = add i64 %102, 1
  store i64 %103, ptr %8, align 8, !tbaa !9
  br label %61, !llvm.loop !19

104:                                              ; preds = %77, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %105

105:                                              ; preds = %104
  store i1 true, ptr %3, align 1
  br label %106

106:                                              ; preds = %105, %14
  %107 = load i1, ptr %3, align 1
  ret i1 %107
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"computation_node_t", !13, i64 0, !13, i64 4, !6, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !10, i64 16}
!18 = !{!12, !6, i64 32}
!19 = distinct !{!19, !16}


; 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 norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @disconnect_nodes(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %.loopexit35, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  br label %9

9:                                                ; preds = %.lr.ph, %21
  %.02946 = phi i64 [ 0, %.lr.ph ], [ %22, %21 ]
  %10 = getelementptr inbounds ptr, ptr %8, i64 %.02946
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, %1
  br i1 %12, label %13, label %21

13:                                               ; preds = %9
  %14 = getelementptr inbounds ptr, ptr %8, i64 %.02946
  %15 = getelementptr i8, ptr %14, i64 8
  %16 = xor i64 %.02946, -1
  %17 = add i64 %6, %16
  %18 = shl i64 %17, 3
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %14, ptr align 8 %15, i64 %18, i1 false)
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = add i64 %19, -1
  store i64 %20, ptr %5, align 8, !tbaa !5
  br label %.loopexit35

21:                                               ; preds = %9
  %22 = add nuw i64 %.02946, 1
  %exitcond.not = icmp eq i64 %22, %6
  br i1 %exitcond.not, label %.loopexit35, label %9, !llvm.loop !14

.loopexit35:                                      ; preds = %21, %.preheader, %13
  %23 = getelementptr inbounds i8, ptr %1, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %.not50 = icmp eq i64 %24, 0
  br i1 %.not50, label %.loopexit, label %.lr.ph49

.lr.ph49:                                         ; preds = %.loopexit35
  %25 = getelementptr inbounds i8, ptr %1, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  br label %27

27:                                               ; preds = %.lr.ph49, %39
  %.048 = phi i64 [ 0, %.lr.ph49 ], [ %40, %39 ]
  %28 = getelementptr inbounds ptr, ptr %26, i64 %.048
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = icmp eq ptr %29, %0
  br i1 %30, label %31, label %39

31:                                               ; preds = %27
  %32 = getelementptr inbounds ptr, ptr %26, i64 %.048
  %33 = getelementptr i8, ptr %32, i64 8
  %34 = xor i64 %.048, -1
  %35 = add i64 %24, %34
  %36 = shl i64 %35, 3
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %32, ptr align 8 %33, i64 %36, i1 false)
  %37 = load i64, ptr %23, align 8, !tbaa !16
  %38 = add i64 %37, -1
  store i64 %38, ptr %23, align 8, !tbaa !16
  br label %.loopexit

39:                                               ; preds = %27
  %40 = add nuw i64 %.048, 1
  %exitcond53.not = icmp eq i64 %40, %24
  br i1 %exitcond53.not, label %.loopexit, label %27, !llvm.loop !18

.loopexit:                                        ; preds = %39, %.loopexit35, %31, %2
  ret i1 %or.cond
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

attributes #0 = { nofree norecurse 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !11, i64 24}
!6 = !{!"computation_node_t", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 40}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !11, i64 16}
!17 = !{!6, !10, i64 32}
!18 = distinct !{!18, !15}


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