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

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

@global_memory_pool = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @geometric_get_memory_stats(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %18

9:                                                ; preds = %3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %18

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

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15, %12, %9, %3
  br label %29

19:                                               ; preds = %15
  %20 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %21 = call i64 @get_total_allocated(ptr noundef %20)
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 %21, ptr %22, align 8, !tbaa !9
  %23 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %24 = call i64 @get_peak_allocated(ptr noundef %23)
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %24, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %27 = call i64 @get_num_allocations(ptr noundef %26)
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %27, ptr %28, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %19, %18
  ret void
}

declare i64 @get_total_allocated(ptr noundef) #1

declare i64 @get_peak_allocated(ptr noundef) #1

declare i64 @get_num_allocations(ptr noundef) #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 = { "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, !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}


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

@global_memory_pool = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @geometric_get_memory_stats(ptr noundef writeonly %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %5 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %6 = insertelement <4 x ptr> %5, ptr %4, i64 1
  %7 = insertelement <4 x ptr> %6, ptr %1, i64 2
  %8 = insertelement <4 x ptr> %7, ptr %2, i64 3
  %9 = icmp eq <4 x ptr> %8, zeroinitializer
  %10 = bitcast <4 x i1> %9 to i4
  %11 = icmp eq i4 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %3
  %13 = tail call i64 @get_total_allocated(ptr noundef nonnull %4) #2
  store i64 %13, ptr %0, align 8, !tbaa !9
  %14 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %15 = tail call i64 @get_peak_allocated(ptr noundef %14) #2
  store i64 %15, ptr %1, align 8, !tbaa !9
  %16 = load ptr, ptr @global_memory_pool, align 8, !tbaa !5
  %17 = tail call i64 @get_num_allocations(ptr noundef %16) #2
  store i64 %17, ptr %2, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %3, %12
  ret void
}

declare i64 @get_total_allocated(ptr noundef) local_unnamed_addr #1

declare i64 @get_peak_allocated(ptr noundef) local_unnamed_addr #1

declare i64 @get_num_allocations(ptr 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 = { "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 }

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


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass