; 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

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

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

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

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

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 0, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %15

15:                                               ; preds = %29, %14
  %16 = load i32, ptr %5, align 4, !tbaa !13
  %17 = icmp slt i32 %16, 16
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %6, align 4
  br label %32

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

27:                                               ; preds = %19
  store i8 1, ptr %4, align 1, !tbaa !9
  store i32 2, ptr %6, align 4
  br label %32

28:                                               ; preds = %19
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %5, align 4, !tbaa !13
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %5, align 4, !tbaa !13
  br label %15, !llvm.loop !17

32:                                               ; preds = %27, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %33

33:                                               ; preds = %32
  %34 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %35 = trunc i8 %34 to i1
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %38

37:                                               ; preds = %33
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %38

38:                                               ; preds = %37, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  br label %39

39:                                               ; preds = %38, %13, %9
  %40 = load i32, ptr %2, align 4
  ret i32 %40
}

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 = { 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 = distinct !{!17, !18}
!18 = !{!"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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local range(i32 -4, 1) i32 @geometric_core_synchronize_stream(ptr noundef readnone %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %44, label %3

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

.preheader.preheader:                             ; preds = %3
  %6 = load ptr, ptr @streams, align 16, !tbaa !11
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 16), align 16
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 32), align 16
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 48), align 16
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 64), align 16
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 80), align 16
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 96), align 16
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 112), align 16
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 128), align 16
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 144), align 16
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 160), align 16
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 176), align 16
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 192), align 16
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 208), align 16
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 224), align 16
  %21 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 240), align 16
  %22 = insertelement <16 x ptr> poison, ptr %6, i64 0
  %23 = insertelement <16 x ptr> %22, ptr %7, i64 1
  %24 = insertelement <16 x ptr> %23, ptr %8, i64 2
  %25 = insertelement <16 x ptr> %24, ptr %9, i64 3
  %26 = insertelement <16 x ptr> %25, ptr %10, i64 4
  %27 = insertelement <16 x ptr> %26, ptr %11, i64 5
  %28 = insertelement <16 x ptr> %27, ptr %12, i64 6
  %29 = insertelement <16 x ptr> %28, ptr %13, i64 7
  %30 = insertelement <16 x ptr> %29, ptr %14, i64 8
  %31 = insertelement <16 x ptr> %30, ptr %15, i64 9
  %32 = insertelement <16 x ptr> %31, ptr %16, i64 10
  %33 = insertelement <16 x ptr> %32, ptr %17, i64 11
  %34 = insertelement <16 x ptr> %33, ptr %18, i64 12
  %35 = insertelement <16 x ptr> %34, ptr %19, i64 13
  %36 = insertelement <16 x ptr> %35, ptr %20, i64 14
  %37 = insertelement <16 x ptr> %36, ptr %21, i64 15
  %38 = insertelement <16 x ptr> poison, ptr %0, i64 0
  %39 = shufflevector <16 x ptr> %38, <16 x ptr> poison, <16 x i32> zeroinitializer
  %40 = icmp ne <16 x ptr> %37, %39
  %41 = freeze <16 x i1> %40
  %42 = bitcast <16 x i1> %41 to i16
  %43 = icmp eq i16 %42, -1
  %spec.select = sext i1 %43 to i32
  br label %44

44:                                               ; preds = %.preheader.preheader, %3, %1
  %.1 = phi i32 [ -1, %1 ], [ -4, %3 ], [ %spec.select, %.preheader.preheader ]
  ret i32 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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" }

!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}


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