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

; 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.profiling_span_t = type { [256 x i8], i32, i64, i64, double }
%struct.profiling_context_t = type { [1024 x %struct.profiling_span_t], i64, i64 }

@global_profiling_context = external hidden global ptr, align 8

; Function Attrs: nounwind
declare i64 @clock() #0

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

5:                                                ; preds = %1
  br label %29

6:                                                ; preds = %1
  %7 = call i64 @clock() #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.profiling_span_t, ptr %8, i32 0, i32 3
  store i64 %7, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.profiling_span_t, ptr %10, i32 0, i32 3
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.profiling_span_t, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = sub nsw i64 %12, %15
  %17 = sitofp i64 %16 to double
  %18 = fdiv double %17, 1.000000e+06
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.profiling_span_t, ptr %19, i32 0, i32 4
  store double %18, ptr %20, align 8, !tbaa !15
  %21 = load ptr, ptr @global_profiling_context, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.profiling_context_t, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !16
  %24 = add i64 %23, -1
  store i64 %24, ptr %22, align 8, !tbaa !16
  %25 = load ptr, ptr @global_profiling_context, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.profiling_context_t, ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = add i64 %27, 1
  store i64 %28, ptr %26, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %6, %5
  ret void
}

attributes #0 = { 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 #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, !12, i64 272}
!10 = !{!"", !7, i64 0, !11, i64 256, !12, i64 264, !12, i64 272, !13, i64 280}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!10, !12, i64 264}
!15 = !{!10, !13, i64 280}
!16 = !{!17, !12, i64 294912}
!17 = !{!"", !7, i64 0, !12, i64 294912, !12, i64 294920}
!18 = !{!17, !12, i64 294920}


; 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_profiling_context = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #0

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

2:                                                ; preds = %1
  %3 = tail call i64 @clock() #2
  %4 = getelementptr inbounds i8, ptr %0, i64 272
  store i64 %3, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 264
  %6 = load i64, ptr %5, align 8, !tbaa !12
  %7 = sub nsw i64 %3, %6
  %8 = sitofp i64 %7 to double
  %9 = fdiv double %8, 1.000000e+06
  %10 = getelementptr inbounds i8, ptr %0, i64 280
  store double %9, ptr %10, align 8, !tbaa !13
  %11 = load ptr, ptr @global_profiling_context, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %11, i64 294912
  %13 = load <2 x i64>, ptr %12, align 8, !tbaa !16
  %14 = add <2 x i64> %13, <i64 -1, i64 1>
  store <2 x i64> %14, ptr %12, align 8, !tbaa !16
  br label %15

15:                                               ; preds = %1, %2
  ret void
}

attributes #0 = { 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 #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, !10, i64 272}
!6 = !{!"", !7, i64 0, !9, i64 256, !10, i64 264, !10, i64 272, !11, i64 280}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = !{!6, !10, i64 264}
!13 = !{!6, !11, i64 280}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!10, !10, i64 0}


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