; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (quantum_geometric_tensor_network)

; 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.quantum_geometric_tensor_network = type { ptr, ptr, i64, i64, i8, i8 }
%struct.quantum_circuit_t = type { ptr, i64, i64, i8 }
%struct.circuit_layer_t = type { ptr, i64, i8 }
%struct.quantum_gate_t = type { i64, ptr, ptr, ptr, i64, i8, i32, ptr, i64, i8 }

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare void @destroy_tensor_network(ptr noundef) #2

; 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 void @destroy_quantum_geometric_tensor_network(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  br label %101

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %20

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  call void @destroy_tensor_network(ptr noundef %19)
  br label %20

20:                                               ; preds = %16, %11
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %99

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !14
  br label %26

26:                                               ; preds = %87, %25
  %27 = load i64, ptr %3, align 8, !tbaa !14
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds %struct.quantum_circuit_t, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !15
  %33 = icmp ult i64 %27, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %26
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %90

35:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds %struct.quantum_circuit_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i64, ptr %3, align 8, !tbaa !14
  %42 = getelementptr inbounds ptr, ptr %40, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  store ptr %43, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %86

46:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !14
  br label %47

47:                                               ; preds = %78, %46
  %48 = load i64, ptr %6, align 8, !tbaa !14
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.circuit_layer_t, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = icmp ult i64 %48, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %81

54:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.circuit_layer_t, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = load i64, ptr %6, align 8, !tbaa !14
  %59 = getelementptr inbounds ptr, ptr %57, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  store ptr %60, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %77

63:                                               ; preds = %54
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.quantum_gate_t, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !21
  call void @free(ptr noundef %66) #4
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.quantum_gate_t, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !24
  call void @free(ptr noundef %69) #4
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.quantum_gate_t, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !25
  call void @free(ptr noundef %72) #4
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.quantum_gate_t, ptr %73, i32 0, i32 7
  %75 = load ptr, ptr %74, align 8, !tbaa !26
  call void @free(ptr noundef %75) #4
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %76) #4
  br label %77

77:                                               ; preds = %63, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %78

78:                                               ; preds = %77
  %79 = load i64, ptr %6, align 8, !tbaa !14
  %80 = add i64 %79, 1
  store i64 %80, ptr %6, align 8, !tbaa !14
  br label %47, !llvm.loop !27

81:                                               ; preds = %53
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.circuit_layer_t, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !20
  call void @free(ptr noundef %84) #4
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %85) #4
  br label %86

86:                                               ; preds = %81, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %87

87:                                               ; preds = %86
  %88 = load i64, ptr %3, align 8, !tbaa !14
  %89 = add i64 %88, 1
  store i64 %89, ptr %3, align 8, !tbaa !14
  br label %26, !llvm.loop !29

90:                                               ; preds = %34
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %91, i32 0, i32 1
  %93 = load ptr, ptr %92, align 8, !tbaa !13
  %94 = getelementptr inbounds %struct.quantum_circuit_t, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !17
  call void @free(ptr noundef %95) #4
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %96, i32 0, i32 1
  %98 = load ptr, ptr %97, align 8, !tbaa !13
  call void @free(ptr noundef %98) #4
  br label %99

99:                                               ; preds = %90, %20
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %100) #4
  br label %101

101:                                              ; preds = %99, %10
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 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 = { 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, !6, i64 0}
!10 = !{!"quantum_geometric_tensor_network", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !12, i64 33}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 8}
!16 = !{!"quantum_circuit_t", !6, i64 0, !11, i64 8, !11, i64 16, !12, i64 24}
!17 = !{!16, !6, i64 0}
!18 = !{!19, !11, i64 8}
!19 = !{!"circuit_layer_t", !6, i64 0, !11, i64 8, !12, i64 16}
!20 = !{!19, !6, i64 0}
!21 = !{!22, !6, i64 8}
!22 = !{!"quantum_gate_t", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !23, i64 44, !6, i64 48, !11, i64 56, !12, i64 64}
!23 = !{!"int", !7, i64 0}
!24 = !{!22, !6, i64 16}
!25 = !{!22, !6, i64 24}
!26 = !{!22, !6, i64 48}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = distinct !{!29, !28}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

declare void @destroy_tensor_network(ptr noundef) local_unnamed_addr #1

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

2:                                                ; preds = %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not30 = icmp eq ptr %3, null
  br i1 %.not30, label %5, label %4

4:                                                ; preds = %2
  tail call void @destroy_tensor_network(ptr noundef nonnull %3) #3
  br label %5

5:                                                ; preds = %4, %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not31 = icmp eq ptr %7, null
  br i1 %.not31, label %42, label %.preheader34

.preheader34:                                     ; preds = %5
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %.not39 = icmp eq i64 %9, 0
  br i1 %.not39, label %._crit_edge38, label %.lr.ph37

._crit_edge38:                                    ; preds = %36, %.preheader34
  %.lcssa = phi ptr [ %7, %.preheader34 ], [ %37, %36 ]
  %10 = load ptr, ptr %.lcssa, align 8, !tbaa !15
  tail call void @free(ptr noundef %10) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !12
  tail call void @free(ptr noundef %11) #3
  br label %42

.lr.ph37:                                         ; preds = %.preheader34, %36
  %12 = phi ptr [ %37, %36 ], [ %7, %.preheader34 ]
  %.036 = phi i64 [ %38, %36 ], [ 0, %.preheader34 ]
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds ptr, ptr %13, i64 %.036
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %.not32 = icmp eq ptr %15, null
  br i1 %.not32, label %36, label %.preheader

.preheader:                                       ; preds = %.lr.ph37
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !17
  %.not40 = icmp eq i64 %17, 0
  br i1 %.not40, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %32, %.preheader
  %18 = load ptr, ptr %15, align 8, !tbaa !19
  tail call void @free(ptr noundef %18) #3
  tail call void @free(ptr noundef nonnull %15) #3
  %.pre42 = load ptr, ptr %6, align 8, !tbaa !12
  br label %36

.lr.ph:                                           ; preds = %.preheader, %32
  %19 = phi i64 [ %33, %32 ], [ %17, %.preheader ]
  %.02535 = phi i64 [ %34, %32 ], [ 0, %.preheader ]
  %20 = load ptr, ptr %15, align 8, !tbaa !19
  %21 = getelementptr inbounds ptr, ptr %20, i64 %.02535
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %.not33 = icmp eq ptr %22, null
  br i1 %.not33, label %32, label %23

23:                                               ; preds = %.lr.ph
  %24 = getelementptr inbounds i8, ptr %22, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  tail call void @free(ptr noundef %25) #3
  %26 = getelementptr inbounds i8, ptr %22, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  tail call void @free(ptr noundef %27) #3
  %28 = getelementptr inbounds i8, ptr %22, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !24
  tail call void @free(ptr noundef %29) #3
  %30 = getelementptr inbounds i8, ptr %22, i64 48
  %31 = load ptr, ptr %30, align 8, !tbaa !25
  tail call void @free(ptr noundef %31) #3
  tail call void @free(ptr noundef nonnull %22) #3
  %.pre = load i64, ptr %16, align 8, !tbaa !17
  br label %32

32:                                               ; preds = %23, %.lr.ph
  %33 = phi i64 [ %.pre, %23 ], [ %19, %.lr.ph ]
  %34 = add nuw i64 %.02535, 1
  %35 = icmp ult i64 %34, %33
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !26

36:                                               ; preds = %._crit_edge, %.lr.ph37
  %37 = phi ptr [ %.pre42, %._crit_edge ], [ %12, %.lr.ph37 ]
  %38 = add nuw i64 %.036, 1
  %39 = getelementptr inbounds i8, ptr %37, i64 8
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = icmp ult i64 %38, %40
  br i1 %41, label %.lr.ph37, label %._crit_edge38, !llvm.loop !28

42:                                               ; preds = %._crit_edge38, %5
  tail call void @free(ptr noundef nonnull %0) #3
  br label %43

43:                                               ; preds = %1, %42
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") 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 #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 #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, !7, i64 0}
!6 = !{!"quantum_geometric_tensor_network", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !11, i64 33}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !10, i64 8}
!14 = !{!"quantum_circuit_t", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24}
!15 = !{!14, !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !10, i64 8}
!18 = !{!"circuit_layer_t", !7, i64 0, !10, i64 8, !11, i64 16}
!19 = !{!18, !7, i64 0}
!20 = !{!21, !7, i64 8}
!21 = !{!"quantum_gate_t", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !22, i64 44, !7, i64 48, !10, i64 56, !11, i64 64}
!22 = !{!"int", !8, i64 0}
!23 = !{!21, !7, i64 16}
!24 = !{!21, !7, i64 24}
!25 = !{!21, !7, i64 48}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}


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