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

; 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.ProfileData = type { i64, i64, double, double }

@is_initialized = external hidden global i8, align 1
@operation_count = external hidden global i64, align 8
@total_flops = external hidden global i64, align 8
@total_time = external hidden global double, align 8

; 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 i32 @geometric_core_get_profile_data(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %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
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i32 -1, ptr %3, align 4
  br label %48

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

13:                                               ; preds = %10
  store i32 -1, ptr %3, align 4
  br label %48

14:                                               ; preds = %10
  %15 = load i8, ptr @is_initialized, align 1, !tbaa !9, !range !11, !noundef !12
  %16 = trunc i8 %15 to i1
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 -4, ptr %3, align 4
  br label %48

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = icmp ult i64 %20, 32
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 32, ptr %23, align 8, !tbaa !13
  store i32 -1, ptr %3, align 4
  br label %48

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr @operation_count, align 8, !tbaa !13
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ProfileData, ptr %27, i32 0, i32 0
  store i64 %26, ptr %28, align 8, !tbaa !15
  %29 = load i64, ptr @total_flops, align 8, !tbaa !13
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ProfileData, ptr %30, i32 0, i32 1
  store i64 %29, ptr %31, align 8, !tbaa !18
  %32 = load double, ptr @total_time, align 8, !tbaa !19
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ProfileData, ptr %33, i32 0, i32 2
  store double %32, ptr %34, align 8, !tbaa !20
  %35 = load double, ptr @total_time, align 8, !tbaa !19
  %36 = fcmp ogt double %35, 0.000000e+00
  br i1 %36, label %37, label %42

37:                                               ; preds = %24
  %38 = load i64, ptr @total_flops, align 8, !tbaa !13
  %39 = uitofp i64 %38 to double
  %40 = load double, ptr @total_time, align 8, !tbaa !19
  %41 = fdiv double %39, %40
  br label %43

42:                                               ; preds = %24
  br label %43

43:                                               ; preds = %42, %37
  %44 = phi double [ %41, %37 ], [ 0.000000e+00, %42 ]
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ProfileData, ptr %45, i32 0, i32 3
  store double %44, ptr %46, align 8, !tbaa !21
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 32, ptr %47, align 8, !tbaa !13
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %48

48:                                               ; preds = %43, %22, %17, %13, %9
  %49 = load i32, ptr %3, align 4
  ret i32 %49
}

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 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"", !14, i64 0, !14, i64 8, !17, i64 16, !17, i64 24}
!17 = !{!"double", !7, i64 0}
!18 = !{!16, !14, i64 8}
!19 = !{!17, !17, i64 0}
!20 = !{!16, !17, i64 16}
!21 = !{!16, !17, i64 24}


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

@is_initialized = external hidden local_unnamed_addr global i8, align 1
@operation_count = external hidden local_unnamed_addr global i64, align 8
@total_flops = external hidden local_unnamed_addr global i64, align 8
@total_time = external hidden local_unnamed_addr global double, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -4, 1) i32 @geometric_core_get_profile_data(ptr noundef writeonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %22, label %5

5:                                                ; preds = %2
  %6 = load i8, ptr @is_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %22

8:                                                ; preds = %5
  %9 = load i64, ptr %1, align 8, !tbaa !11
  %10 = icmp ult i64 %9, 32
  br i1 %10, label %.sink.split, label %11

11:                                               ; preds = %8
  %12 = load i64, ptr @operation_count, align 8, !tbaa !11
  store i64 %12, ptr %0, align 8, !tbaa !13
  %13 = load i64, ptr @total_flops, align 8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %13, ptr %14, align 8, !tbaa !16
  %15 = load double, ptr @total_time, align 8
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  store double %15, ptr %16, align 8, !tbaa !17
  %17 = fcmp ogt double %15, 0.000000e+00
  %18 = uitofp i64 %13 to double
  %19 = fdiv double %18, %15
  %20 = select i1 %17, double %19, double 0.000000e+00
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  store double %20, ptr %21, align 8, !tbaa !18
  br label %.sink.split

.sink.split:                                      ; preds = %8, %11
  %.0.ph = phi i32 [ 0, %11 ], [ -1, %8 ]
  store i64 32, ptr %1, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %.sink.split, %5, %2
  %.0 = phi i32 [ -1, %2 ], [ -4, %5 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: 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" }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 8, !15, i64 16, !15, i64 24}
!15 = !{!"double", !7, i64 0}
!16 = !{!14, !12, i64 8}
!17 = !{!14, !15, i64 16}
!18 = !{!14, !15, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass