; 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.quantum_geometric_config_t = type { i64, i64, i64, float, float, i8, i8, ptr }
%struct.Stream = type { ptr, i8 }
%struct.Event = type { ptr, i8, ptr }

@global_config = external hidden global %struct.quantum_geometric_config_t, align 8
@global_pool = external hidden global ptr, align 8
@streams = external hidden global [16 x %struct.Stream], align 16
@events = external hidden global [32 x %struct.Event], align 16
@is_initialized = external hidden global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @geometric_core_initialize() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i64 1, ptr @global_config, align 8, !tbaa !5
  store i64 32, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 1), align 8, !tbaa !13
  store i64 1000, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 2), align 8, !tbaa !14
  store float 0x3F50624DE0000000, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 3), align 8, !tbaa !15
  store float 0x3E45798EE0000000, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 4), align 4, !tbaa !16
  store i8 0, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 5), align 8, !tbaa !17
  store i8 0, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 6), align 1, !tbaa !18
  store ptr null, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 7), align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %4 = call i32 @geometric_init_memory()
  store i32 %4, ptr %2, align 4, !tbaa !20
  %5 = load i32, ptr %2, align 4, !tbaa !20
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %0
  %8 = load i32, ptr %2, align 4, !tbaa !20
  store i32 %8, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %11

9:                                                ; preds = %0
  %10 = call ptr @geometric_get_memory_pool()
  store ptr %10, ptr @global_pool, align 8, !tbaa !22
  store i64 1, ptr @global_config, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @streams, i8 0, i64 256, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @events, i8 0, i64 768, i1 false)
  store i8 1, ptr @is_initialized, align 1, !tbaa !23
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %11

11:                                               ; preds = %9, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %12 = load i32, ptr %1, align 4
  ret i32 %12
}

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

declare i32 @geometric_init_memory() #2

declare ptr @geometric_get_memory_pool() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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 = { "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, !7, i64 0}
!6 = !{!"quantum_geometric_config_t", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !11, i64 32, !11, i64 33, !12, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !10, i64 28}
!17 = !{!6, !11, i64 32}
!18 = !{!6, !11, i64 33}
!19 = !{!6, !12, i64 40}
!20 = !{!21, !21, i64 0}
!21 = !{!"int", !8, i64 0}
!22 = !{!12, !12, i64 0}
!23 = !{!11, !11, 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"

%struct.quantum_geometric_config_t = type { i64, i64, i64, float, float, i8, i8, ptr }
%struct.Stream = type { ptr, i8 }
%struct.Event = type { ptr, i8, ptr }

@global_config = external hidden local_unnamed_addr global %struct.quantum_geometric_config_t, align 8
@global_pool = external hidden local_unnamed_addr global ptr, align 8
@streams = external hidden local_unnamed_addr global [16 x %struct.Stream], align 16
@events = external hidden local_unnamed_addr global [32 x %struct.Event], align 16
@is_initialized = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @geometric_core_initialize() local_unnamed_addr #0 {
  store i64 1, ptr @global_config, align 8, !tbaa !5
  store i64 32, ptr getelementptr inbounds (i8, ptr @global_config, i64 8), align 8, !tbaa !13
  store i64 1000, ptr getelementptr inbounds (i8, ptr @global_config, i64 16), align 8, !tbaa !14
  store <2 x float> <float 0x3F50624DE0000000, float 0x3E45798EE0000000>, ptr getelementptr inbounds (i8, ptr @global_config, i64 24), align 8, !tbaa !15
  store i8 0, ptr getelementptr inbounds (i8, ptr @global_config, i64 32), align 8, !tbaa !16
  store i8 0, ptr getelementptr inbounds (i8, ptr @global_config, i64 33), align 1, !tbaa !17
  store ptr null, ptr getelementptr inbounds (i8, ptr @global_config, i64 40), align 8, !tbaa !18
  %1 = tail call i32 @geometric_init_memory() #3
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %2, label %4

2:                                                ; preds = %0
  %3 = tail call ptr @geometric_get_memory_pool() #3
  store ptr %3, ptr @global_pool, align 8, !tbaa !19
  store i64 1, ptr @global_config, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) @streams, i8 0, i64 256, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(768) @events, i8 0, i64 768, i1 false)
  store i8 1, ptr @is_initialized, align 1, !tbaa !20
  br label %4

4:                                                ; preds = %0, %2
  ret i32 %1
}

declare i32 @geometric_init_memory() local_unnamed_addr #1

declare ptr @geometric_get_memory_pool() local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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_config_t", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !11, i64 32, !11, i64 33, !12, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 16}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !11, i64 32}
!17 = !{!6, !11, i64 33}
!18 = !{!6, !12, i64 40}
!19 = !{!12, !12, i64 0}
!20 = !{!11, !11, i64 0}


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