; 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.Stream = type { ptr, i8 }

@streams = external hidden global [16 x %struct.Stream], 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

declare void @geometric_free(ptr noundef) #1

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

7:                                                ; preds = %1
  %8 = load i8, ptr @is_initialized, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc i8 %8 to i1
  br i1 %9, label %11, label %10

10:                                               ; preds = %7, %1
  br label %43

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %12

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

15:                                               ; preds = %12
  store i32 2, ptr %4, align 4
  br label %42

16:                                               ; preds = %12
  %17 = load i32, ptr %3, align 4, !tbaa !13
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Stream, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 16, !tbaa !15
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %38

24:                                               ; preds = %16
  %25 = load i32, ptr %3, align 4, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Stream, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 16, !tbaa !15
  call void @geometric_free(ptr noundef %29)
  %30 = load i32, ptr %3, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.Stream, ptr %32, i32 0, i32 0
  store ptr null, ptr %33, align 16, !tbaa !15
  %34 = load i32, ptr %3, align 4, !tbaa !13
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Stream, ptr %36, i32 0, i32 1
  store i8 0, ptr %37, align 8, !tbaa !17
  store i32 2, ptr %4, align 4
  br label %42

38:                                               ; preds = %16
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %3, align 4, !tbaa !13
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !13
  br label %12, !llvm.loop !18

42:                                               ; preds = %24, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %43

43:                                               ; preds = %42, %10
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"Stream", !6, i64 0, !10, i64 8}
!17 = !{!16, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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.Stream = type { ptr, i8 }

@streams = external hidden local_unnamed_addr global [16 x %struct.Stream], align 16
@is_initialized = external hidden local_unnamed_addr global i8, align 1

declare void @geometric_free(ptr noundef) local_unnamed_addr #0

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

2:                                                ; preds = %1
  %3 = load i8, ptr @is_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %2
  %5 = load ptr, ptr @streams, align 16, !tbaa !11
  %6 = icmp eq ptr %5, %0
  br i1 %6, label %37, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 16), align 16, !tbaa !11
  %8 = icmp eq ptr %7, %0
  br i1 %8, label %37, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 32), align 16, !tbaa !11
  %10 = icmp eq ptr %9, %0
  br i1 %10, label %37, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 48), align 16, !tbaa !11
  %12 = icmp eq ptr %11, %0
  br i1 %12, label %37, label %.preheader.4

.preheader.4:                                     ; preds = %.preheader.3
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 64), align 16, !tbaa !11
  %14 = icmp eq ptr %13, %0
  br i1 %14, label %37, label %.preheader.5

.preheader.5:                                     ; preds = %.preheader.4
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 80), align 16, !tbaa !11
  %16 = icmp eq ptr %15, %0
  br i1 %16, label %37, label %.preheader.6

.preheader.6:                                     ; preds = %.preheader.5
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 96), align 16, !tbaa !11
  %18 = icmp eq ptr %17, %0
  br i1 %18, label %37, label %.preheader.7

.preheader.7:                                     ; preds = %.preheader.6
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 112), align 16, !tbaa !11
  %20 = icmp eq ptr %19, %0
  br i1 %20, label %37, label %.preheader.8

.preheader.8:                                     ; preds = %.preheader.7
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 128), align 16, !tbaa !11
  %22 = icmp eq ptr %21, %0
  br i1 %22, label %37, label %.preheader.9

.preheader.9:                                     ; preds = %.preheader.8
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 144), align 16, !tbaa !11
  %24 = icmp eq ptr %23, %0
  br i1 %24, label %37, label %.preheader.10

.preheader.10:                                    ; preds = %.preheader.9
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 160), align 16, !tbaa !11
  %26 = icmp eq ptr %25, %0
  br i1 %26, label %37, label %.preheader.11

.preheader.11:                                    ; preds = %.preheader.10
  %27 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 176), align 16, !tbaa !11
  %28 = icmp eq ptr %27, %0
  br i1 %28, label %37, label %.preheader.12

.preheader.12:                                    ; preds = %.preheader.11
  %29 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 192), align 16, !tbaa !11
  %30 = icmp eq ptr %29, %0
  br i1 %30, label %37, label %.preheader.13

.preheader.13:                                    ; preds = %.preheader.12
  %31 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 208), align 16, !tbaa !11
  %32 = icmp eq ptr %31, %0
  br i1 %32, label %37, label %.preheader.14

.preheader.14:                                    ; preds = %.preheader.13
  %33 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 224), align 16, !tbaa !11
  %34 = icmp eq ptr %33, %0
  br i1 %34, label %37, label %.preheader.15

.preheader.15:                                    ; preds = %.preheader.14
  %35 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 240), align 16, !tbaa !11
  %36 = icmp eq ptr %35, %0
  br i1 %36, label %37, label %.loopexit

37:                                               ; preds = %.preheader.15, %.preheader.14, %.preheader.13, %.preheader.12, %.preheader.11, %.preheader.10, %.preheader.9, %.preheader.8, %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.lcssa12 = phi ptr [ @streams, %.preheader.preheader ], [ getelementptr inbounds (i8, ptr @streams, i64 16), %.preheader.1 ], [ getelementptr inbounds (i8, ptr @streams, i64 32), %.preheader.2 ], [ getelementptr inbounds (i8, ptr @streams, i64 48), %.preheader.3 ], [ getelementptr inbounds (i8, ptr @streams, i64 64), %.preheader.4 ], [ getelementptr inbounds (i8, ptr @streams, i64 80), %.preheader.5 ], [ getelementptr inbounds (i8, ptr @streams, i64 96), %.preheader.6 ], [ getelementptr inbounds (i8, ptr @streams, i64 112), %.preheader.7 ], [ getelementptr inbounds (i8, ptr @streams, i64 128), %.preheader.8 ], [ getelementptr inbounds (i8, ptr @streams, i64 144), %.preheader.9 ], [ getelementptr inbounds (i8, ptr @streams, i64 160), %.preheader.10 ], [ getelementptr inbounds (i8, ptr @streams, i64 176), %.preheader.11 ], [ getelementptr inbounds (i8, ptr @streams, i64 192), %.preheader.12 ], [ getelementptr inbounds (i8, ptr @streams, i64 208), %.preheader.13 ], [ getelementptr inbounds (i8, ptr @streams, i64 224), %.preheader.14 ], [ getelementptr inbounds (i8, ptr @streams, i64 240), %.preheader.15 ]
  %.lcssa = phi ptr [ %5, %.preheader.preheader ], [ %7, %.preheader.1 ], [ %9, %.preheader.2 ], [ %11, %.preheader.3 ], [ %13, %.preheader.4 ], [ %15, %.preheader.5 ], [ %17, %.preheader.6 ], [ %19, %.preheader.7 ], [ %21, %.preheader.8 ], [ %23, %.preheader.9 ], [ %25, %.preheader.10 ], [ %27, %.preheader.11 ], [ %29, %.preheader.12 ], [ %31, %.preheader.13 ], [ %33, %.preheader.14 ], [ %35, %.preheader.15 ]
  tail call void @geometric_free(ptr noundef %.lcssa) #2
  store ptr null, ptr %.lcssa12, align 16, !tbaa !11
  %38 = getelementptr inbounds i8, ptr %.lcssa12, i64 8
  store i8 0, ptr %38, align 8, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.15, %37, %1, %2
  ret void
}

attributes #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 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !13, i64 0}
!12 = !{!"Stream", !13, i64 0, !6, i64 8}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !6, i64 8}


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