; 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.computational_graph_t = type { ptr, i64, i64, ptr, ptr, i64, i64, ptr }
%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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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 ptr @add_node(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %133

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.computational_graph_t, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.computational_graph_t, ptr %23, i32 0, i32 2
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = icmp uge i64 %22, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %19
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call zeroext i1 @resize_node_array(ptr noundef %28)
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store ptr null, ptr %5, align 8
  br label %133

31:                                               ; preds = %27
  br label %32

32:                                               ; preds = %31, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %33 = call noalias ptr @malloc(i64 noundef 72) #5
  store ptr %33, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %132

37:                                               ; preds = %32
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.computation_node_t, ptr %39, i32 0, i32 0
  store i32 %38, ptr %40, align 8, !tbaa !15
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.computation_node_t, ptr %42, i32 0, i32 1
  store i32 %41, ptr %43, align 4, !tbaa !17
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.computation_node_t, ptr %45, i32 0, i32 2
  store ptr %44, ptr %46, align 8, !tbaa !18
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.computation_node_t, ptr %47, i32 0, i32 3
  store i64 0, ptr %48, align 8, !tbaa !19
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.computation_node_t, ptr %49, i32 0, i32 4
  store i64 0, ptr %50, align 8, !tbaa !20
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.computation_node_t, ptr %51, i32 0, i32 5
  store ptr null, ptr %52, align 8, !tbaa !21
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.computation_node_t, ptr %53, i32 0, i32 6
  store ptr null, ptr %54, align 8, !tbaa !22
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.computation_node_t, ptr %55, i32 0, i32 7
  store ptr null, ptr %56, align 8, !tbaa !23
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.computation_node_t, ptr %57, i32 0, i32 8
  store ptr null, ptr %58, align 8, !tbaa !24
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.computation_node_t, ptr %59, i32 0, i32 9
  store ptr null, ptr %60, align 8, !tbaa !25
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.computational_graph_t, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !26
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.computational_graph_t, ptr %65, i32 0, i32 1
  %67 = load i64, ptr %66, align 8, !tbaa !11
  %68 = add i64 %67, 1
  store i64 %68, ptr %66, align 8, !tbaa !11
  %69 = getelementptr inbounds ptr, ptr %64, i64 %67
  store ptr %61, ptr %69, align 8, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %99

72:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.computational_graph_t, ptr %73, i32 0, i32 5
  %75 = load i64, ptr %74, align 8, !tbaa !27
  %76 = add i64 %75, 1
  %77 = mul i64 %76, 8
  store i64 %77, ptr %12, align 8, !tbaa !28
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.computational_graph_t, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !29
  %81 = load i64, ptr %12, align 8, !tbaa !28
  %82 = call ptr @realloc(ptr noundef %80, i64 noundef %81) #6
  store ptr %82, ptr %13, align 8, !tbaa !5
  %83 = load ptr, ptr %13, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %98

85:                                               ; preds = %72
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.computational_graph_t, ptr %87, i32 0, i32 3
  store ptr %86, ptr %88, align 8, !tbaa !29
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.computational_graph_t, ptr %90, i32 0, i32 3
  %92 = load ptr, ptr %91, align 8, !tbaa !29
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.computational_graph_t, ptr %93, i32 0, i32 5
  %95 = load i64, ptr %94, align 8, !tbaa !27
  %96 = add i64 %95, 1
  store i64 %96, ptr %94, align 8, !tbaa !27
  %97 = getelementptr inbounds ptr, ptr %92, i64 %95
  store ptr %89, ptr %97, align 8, !tbaa !5
  br label %98

98:                                               ; preds = %85, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %130

99:                                               ; preds = %37
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = icmp eq i32 %100, 4
  br i1 %101, label %102, label %129

102:                                              ; preds = %99
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.computational_graph_t, ptr %103, i32 0, i32 6
  %105 = load i64, ptr %104, align 8, !tbaa !30
  %106 = add i64 %105, 1
  %107 = mul i64 %106, 8
  store i64 %107, ptr %14, align 8, !tbaa !28
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.computational_graph_t, ptr %108, i32 0, i32 4
  %110 = load ptr, ptr %109, align 8, !tbaa !31
  %111 = load i64, ptr %14, align 8, !tbaa !28
  %112 = call ptr @realloc(ptr noundef %110, i64 noundef %111) #6
  store ptr %112, ptr %15, align 8, !tbaa !5
  %113 = load ptr, ptr %15, align 8, !tbaa !5
  %114 = icmp ne ptr %113, null
  br i1 %114, label %115, label %128

115:                                              ; preds = %102
  %116 = load ptr, ptr %15, align 8, !tbaa !5
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.computational_graph_t, ptr %117, i32 0, i32 4
  store ptr %116, ptr %118, align 8, !tbaa !31
  %119 = load ptr, ptr %10, align 8, !tbaa !5
  %120 = load ptr, ptr %6, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.computational_graph_t, ptr %120, i32 0, i32 4
  %122 = load ptr, ptr %121, align 8, !tbaa !31
  %123 = load ptr, ptr %6, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.computational_graph_t, ptr %123, i32 0, i32 6
  %125 = load i64, ptr %124, align 8, !tbaa !30
  %126 = add i64 %125, 1
  store i64 %126, ptr %124, align 8, !tbaa !30
  %127 = getelementptr inbounds ptr, ptr %122, i64 %125
  store ptr %119, ptr %127, align 8, !tbaa !5
  br label %128

128:                                              ; preds = %115, %102
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %129

129:                                              ; preds = %128, %99
  br label %130

130:                                              ; preds = %129, %98
  %131 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %131, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %132

132:                                              ; preds = %130, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %133

133:                                              ; preds = %132, %30, %18
  %134 = load ptr, ptr %5, align 8
  ret ptr %134
}

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

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

!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 = !{!12, !13, i64 8}
!12 = !{!"", !6, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 48, !6, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 16}
!15 = !{!16, !10, i64 0}
!16 = !{!"computation_node_t", !10, i64 0, !10, i64 4, !6, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !13, i64 16}
!20 = !{!16, !13, i64 24}
!21 = !{!16, !6, i64 32}
!22 = !{!16, !6, i64 40}
!23 = !{!16, !6, i64 48}
!24 = !{!16, !6, i64 56}
!25 = !{!16, !6, i64 64}
!26 = !{!12, !6, i64 0}
!27 = !{!12, !13, i64 40}
!28 = !{!13, !13, i64 0}
!29 = !{!12, !6, i64 24}
!30 = !{!12, !13, i64 48}
!31 = !{!12, !6, i64 32}


; 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 nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @add_node(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %43, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %.not47 = icmp ult i64 %7, %9
  br i1 %.not47, label %12, label %10

10:                                               ; preds = %5
  %11 = tail call zeroext i1 @resize_node_array(ptr noundef nonnull %0)
  br i1 %11, label %12, label %43

12:                                               ; preds = %10, %5
  %13 = tail call noalias dereferenceable_or_null(72) ptr @malloc(i64 noundef 72) #4
  %.not48 = icmp eq ptr %13, null
  br i1 %.not48, label %43, label %14

14:                                               ; preds = %12
  store i32 %1, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %13, i64 4
  store i32 %2, ptr %15, align 4, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %3, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %13, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %17, i8 0, i64 56, i1 false)
  %18 = load ptr, ptr %0, align 8, !tbaa !17
  %19 = load i64, ptr %6, align 8, !tbaa !5
  %20 = add i64 %19, 1
  store i64 %20, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds ptr, ptr %18, i64 %19
  store ptr %13, ptr %21, align 8, !tbaa !18
  switch i32 %1, label %43 [
    i32 0, label %22
    i32 4, label %31
  ]

22:                                               ; preds = %14
  %23 = getelementptr inbounds i8, ptr %0, i64 40
  %24 = load i64, ptr %23, align 8, !tbaa !19
  %25 = shl i64 %24, 3
  %26 = add i64 %25, 8
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = tail call ptr @realloc(ptr noundef %28, i64 noundef %26) #5
  %.not50 = icmp eq ptr %29, null
  br i1 %.not50, label %43, label %30

30:                                               ; preds = %22
  store ptr %29, ptr %27, align 8, !tbaa !20
  br label %.sink.split

31:                                               ; preds = %14
  %32 = getelementptr inbounds i8, ptr %0, i64 48
  %33 = load i64, ptr %32, align 8, !tbaa !21
  %34 = shl i64 %33, 3
  %35 = add i64 %34, 8
  %36 = getelementptr inbounds i8, ptr %0, i64 32
  %37 = load ptr, ptr %36, align 8, !tbaa !22
  %38 = tail call ptr @realloc(ptr noundef %37, i64 noundef %35) #5
  %.not49 = icmp eq ptr %38, null
  br i1 %.not49, label %43, label %39

39:                                               ; preds = %31
  store ptr %38, ptr %36, align 8, !tbaa !22
  br label %.sink.split

.sink.split:                                      ; preds = %30, %39
  %.sink = phi ptr [ %32, %39 ], [ %23, %30 ]
  %.sink51 = phi ptr [ %38, %39 ], [ %29, %30 ]
  %40 = load i64, ptr %.sink, align 8, !tbaa !23
  %41 = add i64 %40, 1
  store i64 %41, ptr %.sink, align 8, !tbaa !23
  %42 = getelementptr inbounds ptr, ptr %.sink51, i64 %40
  store ptr %13, ptr %42, align 8, !tbaa !18
  br label %43

43:                                               ; preds = %.sink.split, %12, %31, %14, %22, %10, %4
  %.1 = phi ptr [ null, %4 ], [ null, %10 ], [ null, %12 ], [ %13, %31 ], [ %13, %14 ], [ %13, %22 ], [ %13, %.sink.split ]
  ret ptr %.1
}

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { nounwind allocsize(1) }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass