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

; 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.anon = type { [1024 x ptr], %struct.quantum_cache_t, i64, i64, i8, i32, ptr }
%struct.quantum_cache_t = type { i32, ptr, ptr, i64, %struct.quantum_protection_t }
%struct.quantum_protection_t = type { ptr, i64, float, i8 }
%struct.hardware_config_t = type { i32, ptr }
%struct.cache_config_t = type { i64, i64, i8, float, i32, ptr }

@cache_state = external hidden global %struct.anon, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @qg_cache_init(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.hardware_config_t, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %53

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.cache_config_t, ptr %12, i32 0, i32 4
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = call i32 @geometric_create_hardware(ptr noundef %4, i32 noundef %14, i64 noundef 1024)
  store i32 %15, ptr %5, align 4, !tbaa !15
  %16 = load i32, ptr %5, align 4, !tbaa !15
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %11
  store i32 -2, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %52

19:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %20 = getelementptr inbounds %struct.hardware_config_t, ptr %7, i32 0, i32 0
  store i32 0, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds %struct.hardware_config_t, ptr %7, i32 0, i32 1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cache_config_t, ptr %22, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  store ptr %24, ptr %21, align 8, !tbaa !19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call i32 @geometric_initialize_hardware(ptr noundef %25, ptr noundef %7)
  store i32 %26, ptr %5, align 4, !tbaa !15
  %27 = load i32, ptr %5, align 4, !tbaa !15
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %19
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void @geometric_destroy_hardware(ptr noundef %30)
  store i32 -2, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %51

31:                                               ; preds = %19
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.cache_config_t, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !9
  store i32 %34, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), align 8, !tbaa !20
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %35, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 1), align 8, !tbaa !24
  store ptr null, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 2), align 8, !tbaa !25
  store i64 0, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 3), align 8, !tbaa !26
  store ptr null, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 4), align 8, !tbaa !27
  store i64 0, ptr getelementptr inbounds (%struct.quantum_protection_t, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 4), i32 0, i32 1), align 8, !tbaa !28
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.cache_config_t, ptr %36, i32 0, i32 3
  %38 = load float, ptr %37, align 4, !tbaa !29
  store float %38, ptr getelementptr inbounds (%struct.quantum_protection_t, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 4), i32 0, i32 2), align 8, !tbaa !30
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cache_config_t, ptr %39, i32 0, i32 2
  %41 = load i8, ptr %40, align 8, !tbaa !31, !range !32, !noundef !33
  %42 = trunc i8 %41 to i1
  %43 = zext i1 %42 to i8
  store i8 %43, ptr getelementptr inbounds (%struct.quantum_protection_t, ptr getelementptr inbounds (%struct.quantum_cache_t, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 1), i32 0, i32 4), i32 0, i32 3), align 4, !tbaa !34
  call void @llvm.memset.p0.i64(ptr align 8 @cache_state, i8 0, i64 8192, i1 false)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cache_config_t, ptr %44, i32 0, i32 0
  %46 = load i64, ptr %45, align 8, !tbaa !35
  store i64 %46, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 2), align 8, !tbaa !36
  store i64 0, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 3), align 8, !tbaa !37
  store i8 1, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 4), align 8, !tbaa !38
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.cache_config_t, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !9
  store i32 %49, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 5), align 4, !tbaa !39
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %50, ptr getelementptr inbounds (%struct.anon, ptr @cache_state, i32 0, i32 6), align 8, !tbaa !40
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %51

51:                                               ; preds = %31, %29
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %52

52:                                               ; preds = %51, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %53

53:                                               ; preds = %52, %10
  %54 = load i32, ptr %2, align 4
  ret i32 %54
}

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

declare i32 @geometric_create_hardware(ptr noundef, i32 noundef, i64 noundef) #2

declare i32 @geometric_initialize_hardware(ptr noundef, ptr noundef) #2

declare void @geometric_destroy_hardware(ptr noundef) #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 24}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16, !13, i64 20, !14, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!17, !14, i64 0}
!17 = !{!"", !14, i64 0, !6, i64 8}
!18 = !{!10, !6, i64 32}
!19 = !{!17, !6, i64 8}
!20 = !{!21, !14, i64 8192}
!21 = !{!"", !7, i64 0, !22, i64 8192, !11, i64 8248, !11, i64 8256, !12, i64 8264, !14, i64 8268, !6, i64 8272}
!22 = !{!"", !14, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !23, i64 32}
!23 = !{!"", !6, i64 0, !11, i64 8, !13, i64 16, !12, i64 20}
!24 = !{!21, !6, i64 8200}
!25 = !{!21, !6, i64 8208}
!26 = !{!21, !11, i64 8216}
!27 = !{!21, !6, i64 8224}
!28 = !{!21, !11, i64 8232}
!29 = !{!10, !13, i64 20}
!30 = !{!21, !13, i64 8240}
!31 = !{!10, !12, i64 16}
!32 = !{i8 0, i8 2}
!33 = !{}
!34 = !{!21, !12, i64 8244}
!35 = !{!10, !11, i64 0}
!36 = !{!21, !11, i64 8248}
!37 = !{!21, !11, i64 8256}
!38 = !{!21, !12, i64 8264}
!39 = !{!21, !14, i64 8268}
!40 = !{!21, !6, i64 8272}


; 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.anon = type { [1024 x ptr], %struct.quantum_cache_t, i64, i64, i8, i32, ptr }
%struct.quantum_cache_t = type { i32, ptr, ptr, i64, %struct.quantum_protection_t }
%struct.quantum_protection_t = type { ptr, i64, float, i8 }
%struct.hardware_config_t = type { i32, ptr }

@cache_state = external hidden local_unnamed_addr global %struct.anon, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @qg_cache_init(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.hardware_config_t, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %27, label %4

4:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = call i32 @geometric_create_hardware(ptr noundef nonnull %2, i32 noundef %6, i64 noundef 1024) #4
  %.not11 = icmp eq i32 %7, 0
  br i1 %.not11, label %8, label %26

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  store i32 0, ptr %3, align 8, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  store ptr %11, ptr %9, align 8, !tbaa !18
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @geometric_initialize_hardware(ptr noundef %12, ptr noundef nonnull %3) #4
  %.not12 = icmp eq i32 %13, 0
  br i1 %.not12, label %16, label %14

14:                                               ; preds = %8
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  call void @geometric_destroy_hardware(ptr noundef %15) #4
  br label %25

16:                                               ; preds = %8
  %17 = load i32, ptr %5, align 8, !tbaa !9
  store i32 %17, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8192), align 8, !tbaa !19
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %18, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8200), align 8, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %0, i64 20
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) getelementptr inbounds (i8, ptr @cache_state, i64 8208), i8 0, i64 32, i1 false)
  %20 = load float, ptr %19, align 4, !tbaa !24
  store float %20, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8240), align 8, !tbaa !25
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load i8, ptr %21, align 8, !tbaa !26, !range !27, !noundef !28
  store i8 %22, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8244), align 4, !tbaa !29
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(8192) @cache_state, i8 0, i64 8192, i1 false)
  %23 = load i64, ptr %0, align 8, !tbaa !30
  store i64 %23, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8248), align 8, !tbaa !31
  store i64 0, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8256), align 8, !tbaa !32
  store i8 1, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8264), align 8, !tbaa !33
  %24 = load i32, ptr %5, align 8, !tbaa !9
  store i32 %24, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8268), align 4, !tbaa !34
  store ptr %18, ptr getelementptr inbounds (i8, ptr @cache_state, i64 8272), align 8, !tbaa !35
  br label %25

25:                                               ; preds = %16, %14
  %.0 = phi i32 [ -2, %14 ], [ 0, %16 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  br label %26

26:                                               ; preds = %4, %25
  %.1 = phi i32 [ %.0, %25 ], [ -2, %4 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %27

27:                                               ; preds = %1, %26
  %.2 = phi i32 [ %.1, %26 ], [ -1, %1 ]
  ret i32 %.2
}

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

declare i32 @geometric_create_hardware(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

declare i32 @geometric_initialize_hardware(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @geometric_destroy_hardware(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress 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 = { mustprogress 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 = { mustprogress 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, !14, i64 24}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16, !13, i64 20, !14, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"", !14, i64 0, !6, i64 8}
!17 = !{!10, !6, i64 32}
!18 = !{!16, !6, i64 8}
!19 = !{!20, !14, i64 8192}
!20 = !{!"", !7, i64 0, !21, i64 8192, !11, i64 8248, !11, i64 8256, !12, i64 8264, !14, i64 8268, !6, i64 8272}
!21 = !{!"", !14, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !22, i64 32}
!22 = !{!"", !6, i64 0, !11, i64 8, !13, i64 16, !12, i64 20}
!23 = !{!20, !6, i64 8200}
!24 = !{!10, !13, i64 20}
!25 = !{!20, !13, i64 8240}
!26 = !{!10, !12, i64 16}
!27 = !{i8 0, i8 2}
!28 = !{}
!29 = !{!20, !12, i64 8244}
!30 = !{!10, !11, i64 0}
!31 = !{!20, !11, i64 8248}
!32 = !{!20, !11, i64 8256}
!33 = !{!20, !12, i64 8264}
!34 = !{!20, !14, i64 8268}
!35 = !{!20, !6, i64 8272}


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