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

@global_profiling_context = external hidden global ptr, align 8

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

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

12:                                               ; preds = %9, %2
  store ptr null, ptr %3, align 8
  br label %46

13:                                               ; preds = %9
  %14 = load ptr, ptr @global_profiling_context, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.profiling_context_t, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = icmp uge i64 %16, 1024
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  store ptr null, ptr %3, align 8
  br label %46

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %20 = load ptr, ptr @global_profiling_context, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.profiling_context_t, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr @global_profiling_context, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.profiling_context_t, ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = add i64 %24, 1
  store i64 %25, ptr %23, align 8, !tbaa !11
  %26 = getelementptr inbounds [1024 x %struct.profiling_span_t], ptr %21, i64 0, i64 %24
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.profiling_span_t, ptr %28, i32 0, i32 1
  store i32 %27, ptr %29, align 8, !tbaa !14
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.profiling_span_t, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [256 x i8], ptr %31, i64 0, i64 0
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call ptr @strncpy(ptr noundef %32, ptr noundef %33, i64 noundef 255) #3
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.profiling_span_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [256 x i8], ptr %36, i64 0, i64 255
  store i8 0, ptr %37, align 1, !tbaa !17
  %38 = call i64 @clock() #3
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.profiling_span_t, ptr %39, i32 0, i32 2
  store i64 %38, ptr %40, align 8, !tbaa !18
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.profiling_span_t, ptr %41, i32 0, i32 3
  store i64 0, ptr %42, align 8, !tbaa !19
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.profiling_span_t, ptr %43, i32 0, i32 4
  store double 0.000000e+00, ptr %44, align 8, !tbaa !20
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %45, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %46

46:                                               ; preds = %19, %18, %12
  %47 = load ptr, ptr %3, align 8
  ret ptr %47
}

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !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 294912}
!12 = !{!"", !7, i64 0, !13, i64 294912, !13, i64 294920}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !10, i64 256}
!15 = !{!"", !7, i64 0, !10, i64 256, !13, i64 264, !13, i64 272, !16, i64 280}
!16 = !{!"double", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!15, !13, i64 264}
!19 = !{!15, !13, i64 272}
!20 = !{!15, !16, i64 280}


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

%struct.profiling_span_t = type { [256 x i8], i32, i64, i64, double }

@global_profiling_context = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @geometric_start_span(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @global_profiling_context, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  %5 = icmp ne ptr %0, null
  %or.cond = and i1 %5, %4
  br i1 %or.cond, label %6, label %19

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %3, i64 294912
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp ugt i64 %8, 1023
  br i1 %9, label %19, label %10

10:                                               ; preds = %6
  %11 = add nuw nsw i64 %8, 1
  store i64 %11, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds [1024 x %struct.profiling_span_t], ptr %3, i64 0, i64 %8
  %13 = getelementptr inbounds i8, ptr %12, i64 256
  store i32 %1, ptr %13, align 8, !tbaa !12
  %14 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 255) #4
  %15 = getelementptr inbounds i8, ptr %12, i64 255
  store i8 0, ptr %15, align 1, !tbaa !16
  %16 = tail call i64 @clock() #4
  %17 = getelementptr inbounds i8, ptr %12, i64 264
  store i64 %16, ptr %17, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %12, i64 272
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %18, i8 0, i64 16, i1 false)
  br label %19

19:                                               ; preds = %6, %2, %10
  %.0 = phi ptr [ %12, %10 ], [ null, %2 ], [ null, %6 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @clock() 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 = { 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 "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 }

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


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