; 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: 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 void @geometric_core_shutdown() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = load i8, ptr @is_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc i8 %3 to i1
  br i1 %4, label %5, label %63

5:                                                ; preds = %0
  call void @geometric_cleanup_memory()
  store ptr null, ptr @global_pool, align 8, !tbaa !11
  %6 = load ptr, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 7), align 8, !tbaa !13
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  %9 = load ptr, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 7), align 8, !tbaa !13
  call void @geometric_free(ptr noundef %9)
  store ptr null, ptr getelementptr inbounds (%struct.quantum_geometric_config_t, ptr @global_config, i32 0, i32 7), align 8, !tbaa !13
  br label %10

10:                                               ; preds = %8, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !17
  br label %11

11:                                               ; preds = %33, %10
  %12 = load i32, ptr %1, align 4, !tbaa !17
  %13 = icmp slt i32 %12, 16
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %36

15:                                               ; preds = %11
  %16 = load i32, ptr %1, align 4, !tbaa !17
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.Stream, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 16, !tbaa !19
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %32

22:                                               ; preds = %15
  %23 = load i32, ptr %1, align 4, !tbaa !17
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.Stream, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 16, !tbaa !19
  call void @geometric_free(ptr noundef %27)
  %28 = load i32, ptr %1, align 4, !tbaa !17
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Stream, ptr %30, i32 0, i32 0
  store ptr null, ptr %31, align 16, !tbaa !19
  br label %32

32:                                               ; preds = %22, %15
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %1, align 4, !tbaa !17
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %1, align 4, !tbaa !17
  br label %11, !llvm.loop !21

36:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !17
  br label %37

37:                                               ; preds = %59, %36
  %38 = load i32, ptr %2, align 4, !tbaa !17
  %39 = icmp slt i32 %38, 32
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %62

41:                                               ; preds = %37
  %42 = load i32, ptr %2, align 4, !tbaa !17
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.Event, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %58

48:                                               ; preds = %41
  %49 = load i32, ptr %2, align 4, !tbaa !17
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Event, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !23
  call void @geometric_free(ptr noundef %53)
  %54 = load i32, ptr %2, align 4, !tbaa !17
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.Event, ptr %56, i32 0, i32 0
  store ptr null, ptr %57, align 8, !tbaa !23
  br label %58

58:                                               ; preds = %48, %41
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %2, align 4, !tbaa !17
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !17
  br label %37, !llvm.loop !25

62:                                               ; preds = %40
  store i8 0, ptr @is_initialized, align 1, !tbaa !5
  br label %63

63:                                               ; preds = %62, %0
  ret void
}

declare void @geometric_cleanup_memory() #2

declare void @geometric_free(ptr noundef) #2

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 = { "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 = !{!"_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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 40}
!14 = !{!"quantum_geometric_config_t", !15, i64 0, !15, i64 8, !15, i64 16, !16, i64 24, !16, i64 28, !6, i64 32, !6, i64 33, !12, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !12, i64 0}
!20 = !{!"Stream", !12, i64 0, !6, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!24, !12, i64 0}
!24 = !{!"Event", !12, i64 0, !6, i64 8, !12, i64 16}
!25 = distinct !{!25, !22}


; 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 void @geometric_core_shutdown() local_unnamed_addr #0 {
  %1 = load i8, ptr @is_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %2 = trunc nuw i8 %1 to i1
  br i1 %2, label %3, label %59

3:                                                ; preds = %0
  tail call void @geometric_cleanup_memory() #2
  store ptr null, ptr @global_pool, align 8, !tbaa !11
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @global_config, i64 40), align 8, !tbaa !13
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %3
  tail call void @geometric_free(ptr noundef nonnull %4) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @global_config, i64 40), align 8, !tbaa !13
  br label %6

6:                                                ; preds = %5, %3
  %7 = load ptr, ptr @streams, align 16, !tbaa !17
  %.not15 = icmp eq ptr %7, null
  br i1 %.not15, label %9, label %8

8:                                                ; preds = %6
  tail call void @geometric_free(ptr noundef nonnull %7) #2
  store ptr null, ptr @streams, align 16, !tbaa !17
  br label %9

9:                                                ; preds = %6, %8
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 16), align 16, !tbaa !17
  %.not15.1 = icmp eq ptr %10, null
  br i1 %.not15.1, label %12, label %11

11:                                               ; preds = %9
  tail call void @geometric_free(ptr noundef nonnull %10) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 16), align 16, !tbaa !17
  br label %12

12:                                               ; preds = %11, %9
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 32), align 16, !tbaa !17
  %.not15.2 = icmp eq ptr %13, null
  br i1 %.not15.2, label %15, label %14

14:                                               ; preds = %12
  tail call void @geometric_free(ptr noundef nonnull %13) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 32), align 16, !tbaa !17
  br label %15

15:                                               ; preds = %14, %12
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 48), align 16, !tbaa !17
  %.not15.3 = icmp eq ptr %16, null
  br i1 %.not15.3, label %18, label %17

17:                                               ; preds = %15
  tail call void @geometric_free(ptr noundef nonnull %16) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 48), align 16, !tbaa !17
  br label %18

18:                                               ; preds = %17, %15
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 64), align 16, !tbaa !17
  %.not15.4 = icmp eq ptr %19, null
  br i1 %.not15.4, label %21, label %20

20:                                               ; preds = %18
  tail call void @geometric_free(ptr noundef nonnull %19) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 64), align 16, !tbaa !17
  br label %21

21:                                               ; preds = %20, %18
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 80), align 16, !tbaa !17
  %.not15.5 = icmp eq ptr %22, null
  br i1 %.not15.5, label %24, label %23

23:                                               ; preds = %21
  tail call void @geometric_free(ptr noundef nonnull %22) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 80), align 16, !tbaa !17
  br label %24

24:                                               ; preds = %23, %21
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 96), align 16, !tbaa !17
  %.not15.6 = icmp eq ptr %25, null
  br i1 %.not15.6, label %27, label %26

26:                                               ; preds = %24
  tail call void @geometric_free(ptr noundef nonnull %25) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 96), align 16, !tbaa !17
  br label %27

27:                                               ; preds = %26, %24
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 112), align 16, !tbaa !17
  %.not15.7 = icmp eq ptr %28, null
  br i1 %.not15.7, label %30, label %29

29:                                               ; preds = %27
  tail call void @geometric_free(ptr noundef nonnull %28) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 112), align 16, !tbaa !17
  br label %30

30:                                               ; preds = %29, %27
  %31 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 128), align 16, !tbaa !17
  %.not15.8 = icmp eq ptr %31, null
  br i1 %.not15.8, label %33, label %32

32:                                               ; preds = %30
  tail call void @geometric_free(ptr noundef nonnull %31) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 128), align 16, !tbaa !17
  br label %33

33:                                               ; preds = %32, %30
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 144), align 16, !tbaa !17
  %.not15.9 = icmp eq ptr %34, null
  br i1 %.not15.9, label %36, label %35

35:                                               ; preds = %33
  tail call void @geometric_free(ptr noundef nonnull %34) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 144), align 16, !tbaa !17
  br label %36

36:                                               ; preds = %35, %33
  %37 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 160), align 16, !tbaa !17
  %.not15.10 = icmp eq ptr %37, null
  br i1 %.not15.10, label %39, label %38

38:                                               ; preds = %36
  tail call void @geometric_free(ptr noundef nonnull %37) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 160), align 16, !tbaa !17
  br label %39

39:                                               ; preds = %38, %36
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 176), align 16, !tbaa !17
  %.not15.11 = icmp eq ptr %40, null
  br i1 %.not15.11, label %42, label %41

41:                                               ; preds = %39
  tail call void @geometric_free(ptr noundef nonnull %40) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 176), align 16, !tbaa !17
  br label %42

42:                                               ; preds = %41, %39
  %43 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 192), align 16, !tbaa !17
  %.not15.12 = icmp eq ptr %43, null
  br i1 %.not15.12, label %45, label %44

44:                                               ; preds = %42
  tail call void @geometric_free(ptr noundef nonnull %43) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 192), align 16, !tbaa !17
  br label %45

45:                                               ; preds = %44, %42
  %46 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 208), align 16, !tbaa !17
  %.not15.13 = icmp eq ptr %46, null
  br i1 %.not15.13, label %48, label %47

47:                                               ; preds = %45
  tail call void @geometric_free(ptr noundef nonnull %46) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 208), align 16, !tbaa !17
  br label %48

48:                                               ; preds = %47, %45
  %49 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 224), align 16, !tbaa !17
  %.not15.14 = icmp eq ptr %49, null
  br i1 %.not15.14, label %51, label %50

50:                                               ; preds = %48
  tail call void @geometric_free(ptr noundef nonnull %49) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 224), align 16, !tbaa !17
  br label %51

51:                                               ; preds = %50, %48
  %52 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 240), align 16, !tbaa !17
  %.not15.15 = icmp eq ptr %52, null
  br i1 %.not15.15, label %.preheader.preheader, label %53

.preheader.preheader:                             ; preds = %53, %51
  br label %.preheader

53:                                               ; preds = %51
  tail call void @geometric_free(ptr noundef nonnull %52) #2
  store ptr null, ptr getelementptr inbounds (i8, ptr @streams, i64 240), align 16, !tbaa !17
  br label %.preheader.preheader

54:                                               ; preds = %58
  store i8 0, ptr @is_initialized, align 1, !tbaa !5
  br label %59

.preheader:                                       ; preds = %.preheader.preheader, %58
  %indvars.iv = phi i64 [ %indvars.iv.next, %58 ], [ 0, %.preheader.preheader ]
  %55 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %indvars.iv
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %.not14 = icmp eq ptr %56, null
  br i1 %.not14, label %58, label %57

57:                                               ; preds = %.preheader
  tail call void @geometric_free(ptr noundef nonnull %56) #2
  store ptr null, ptr %55, align 8, !tbaa !19
  br label %58

58:                                               ; preds = %.preheader, %57
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 32
  br i1 %exitcond.not, label %54, label %.preheader, !llvm.loop !21

59:                                               ; preds = %54, %0
  ret void
}

declare void @geometric_cleanup_memory() local_unnamed_addr #1

declare void @geometric_free(ptr noundef) local_unnamed_addr #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 = { "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 = !{!"_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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 40}
!14 = !{!"quantum_geometric_config_t", !15, i64 0, !15, i64 8, !15, i64 16, !16, i64 24, !16, i64 28, !6, i64 32, !6, i64 33, !12, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !12, i64 0}
!18 = !{!"Stream", !12, i64 0, !6, i64 8}
!19 = !{!20, !12, i64 0}
!20 = !{!"Event", !12, i64 0, !6, i64 8, !12, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass