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

@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 i32 @geometric_core_synchronize_event(ptr noundef %0) #1 {
  %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
  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 %48

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 %48

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr null, ptr %4, align 8, !tbaa !5
  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 = %32, %14
  %16 = load i32, ptr %5, align 4, !tbaa !13
  %17 = icmp slt i32 %16, 32
  br i1 %17, label %19, label %18

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

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

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %29
  store ptr %30, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %6, align 4
  br label %35

31:                                               ; preds = %19
  br label %32

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

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

36:                                               ; preds = %35
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Event, ptr %41, i32 0, i32 1
  %43 = load i8, ptr %42, align 8, !tbaa !19, !range !11, !noundef !12
  %44 = trunc i8 %43 to i1
  br i1 %44, label %46, label %45

45:                                               ; preds = %40
  store i32 -4, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %47

46:                                               ; preds = %40
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %47

47:                                               ; preds = %46, %45, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %48

48:                                               ; preds = %47, %13, %9
  %49 = load i32, ptr %2, align 4
  ret i32 %49
}

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 = !{!"Event", !6, i64 0, !10, i64 8, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!16, !10, i64 8}


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

@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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 -4, 1) i32 @geometric_core_synchronize_event(ptr noundef readnone %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.thread, 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 %.thread

.preheader.preheader:                             ; preds = %3
  %6 = load ptr, ptr @events, align 16, !tbaa !11
  %7 = icmp eq ptr %6, %0
  br i1 %7, label %70, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 24), align 8, !tbaa !11
  %9 = icmp eq ptr %8, %0
  br i1 %9, label %70, label %.preheader.2

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

.preheader.3:                                     ; preds = %.preheader.2
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 72), align 8, !tbaa !11
  %13 = icmp eq ptr %12, %0
  br i1 %13, label %70, label %.preheader.4

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

.preheader.5:                                     ; preds = %.preheader.4
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 120), align 8, !tbaa !11
  %17 = icmp eq ptr %16, %0
  br i1 %17, label %70, label %.preheader.6

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

.preheader.7:                                     ; preds = %.preheader.6
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 168), align 8, !tbaa !11
  %21 = icmp eq ptr %20, %0
  br i1 %21, label %70, label %.preheader.8

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

.preheader.9:                                     ; preds = %.preheader.8
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 216), align 8, !tbaa !11
  %25 = icmp eq ptr %24, %0
  br i1 %25, label %70, label %.preheader.10

.preheader.10:                                    ; preds = %.preheader.9
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 240), align 16, !tbaa !11
  %27 = icmp eq ptr %26, %0
  br i1 %27, label %70, label %.preheader.11

.preheader.11:                                    ; preds = %.preheader.10
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 264), align 8, !tbaa !11
  %29 = icmp eq ptr %28, %0
  br i1 %29, label %70, label %.preheader.12

.preheader.12:                                    ; preds = %.preheader.11
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 288), align 16, !tbaa !11
  %31 = icmp eq ptr %30, %0
  br i1 %31, label %70, label %.preheader.13

.preheader.13:                                    ; preds = %.preheader.12
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 312), align 8, !tbaa !11
  %33 = icmp eq ptr %32, %0
  br i1 %33, label %70, label %.preheader.14

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

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

.preheader.16:                                    ; preds = %.preheader.15
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 384), align 16, !tbaa !11
  %39 = icmp eq ptr %38, %0
  br i1 %39, label %70, label %.preheader.17

.preheader.17:                                    ; preds = %.preheader.16
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 408), align 8, !tbaa !11
  %41 = icmp eq ptr %40, %0
  br i1 %41, label %70, label %.preheader.18

.preheader.18:                                    ; preds = %.preheader.17
  %42 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 432), align 16, !tbaa !11
  %43 = icmp eq ptr %42, %0
  br i1 %43, label %70, label %.preheader.19

.preheader.19:                                    ; preds = %.preheader.18
  %44 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 456), align 8, !tbaa !11
  %45 = icmp eq ptr %44, %0
  br i1 %45, label %70, label %.preheader.20

.preheader.20:                                    ; preds = %.preheader.19
  %46 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 480), align 16, !tbaa !11
  %47 = icmp eq ptr %46, %0
  br i1 %47, label %70, label %.preheader.21

.preheader.21:                                    ; preds = %.preheader.20
  %48 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 504), align 8, !tbaa !11
  %49 = icmp eq ptr %48, %0
  br i1 %49, label %70, label %.preheader.22

.preheader.22:                                    ; preds = %.preheader.21
  %50 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 528), align 16, !tbaa !11
  %51 = icmp eq ptr %50, %0
  br i1 %51, label %70, label %.preheader.23

.preheader.23:                                    ; preds = %.preheader.22
  %52 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 552), align 8, !tbaa !11
  %53 = icmp eq ptr %52, %0
  br i1 %53, label %70, label %.preheader.24

.preheader.24:                                    ; preds = %.preheader.23
  %54 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 576), align 16, !tbaa !11
  %55 = icmp eq ptr %54, %0
  br i1 %55, label %70, label %.preheader.25

.preheader.25:                                    ; preds = %.preheader.24
  %56 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 600), align 8, !tbaa !11
  %57 = icmp eq ptr %56, %0
  br i1 %57, label %70, label %.preheader.26

.preheader.26:                                    ; preds = %.preheader.25
  %58 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 624), align 16, !tbaa !11
  %59 = icmp eq ptr %58, %0
  br i1 %59, label %70, label %.preheader.27

.preheader.27:                                    ; preds = %.preheader.26
  %60 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 648), align 8, !tbaa !11
  %61 = icmp eq ptr %60, %0
  br i1 %61, label %70, label %.preheader.28

.preheader.28:                                    ; preds = %.preheader.27
  %62 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 672), align 16, !tbaa !11
  %63 = icmp eq ptr %62, %0
  br i1 %63, label %70, label %.preheader.29

.preheader.29:                                    ; preds = %.preheader.28
  %64 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 696), align 8, !tbaa !11
  %65 = icmp eq ptr %64, %0
  br i1 %65, label %70, label %.preheader.30

.preheader.30:                                    ; preds = %.preheader.29
  %66 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 720), align 16, !tbaa !11
  %67 = icmp eq ptr %66, %0
  br i1 %67, label %70, label %.preheader.31

.preheader.31:                                    ; preds = %.preheader.30
  %68 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 744), align 8, !tbaa !11
  %69 = icmp eq ptr %68, %0
  br i1 %69, label %70, label %.thread

70:                                               ; preds = %.preheader.31, %.preheader.30, %.preheader.29, %.preheader.28, %.preheader.27, %.preheader.26, %.preheader.25, %.preheader.24, %.preheader.23, %.preheader.22, %.preheader.21, %.preheader.20, %.preheader.19, %.preheader.18, %.preheader.17, %.preheader.16, %.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
  %.lcssa = phi ptr [ @events, %.preheader.preheader ], [ getelementptr inbounds (i8, ptr @events, i64 24), %.preheader.1 ], [ getelementptr inbounds (i8, ptr @events, i64 48), %.preheader.2 ], [ getelementptr inbounds (i8, ptr @events, i64 72), %.preheader.3 ], [ getelementptr inbounds (i8, ptr @events, i64 96), %.preheader.4 ], [ getelementptr inbounds (i8, ptr @events, i64 120), %.preheader.5 ], [ getelementptr inbounds (i8, ptr @events, i64 144), %.preheader.6 ], [ getelementptr inbounds (i8, ptr @events, i64 168), %.preheader.7 ], [ getelementptr inbounds (i8, ptr @events, i64 192), %.preheader.8 ], [ getelementptr inbounds (i8, ptr @events, i64 216), %.preheader.9 ], [ getelementptr inbounds (i8, ptr @events, i64 240), %.preheader.10 ], [ getelementptr inbounds (i8, ptr @events, i64 264), %.preheader.11 ], [ getelementptr inbounds (i8, ptr @events, i64 288), %.preheader.12 ], [ getelementptr inbounds (i8, ptr @events, i64 312), %.preheader.13 ], [ getelementptr inbounds (i8, ptr @events, i64 336), %.preheader.14 ], [ getelementptr inbounds (i8, ptr @events, i64 360), %.preheader.15 ], [ getelementptr inbounds (i8, ptr @events, i64 384), %.preheader.16 ], [ getelementptr inbounds (i8, ptr @events, i64 408), %.preheader.17 ], [ getelementptr inbounds (i8, ptr @events, i64 432), %.preheader.18 ], [ getelementptr inbounds (i8, ptr @events, i64 456), %.preheader.19 ], [ getelementptr inbounds (i8, ptr @events, i64 480), %.preheader.20 ], [ getelementptr inbounds (i8, ptr @events, i64 504), %.preheader.21 ], [ getelementptr inbounds (i8, ptr @events, i64 528), %.preheader.22 ], [ getelementptr inbounds (i8, ptr @events, i64 552), %.preheader.23 ], [ getelementptr inbounds (i8, ptr @events, i64 576), %.preheader.24 ], [ getelementptr inbounds (i8, ptr @events, i64 600), %.preheader.25 ], [ getelementptr inbounds (i8, ptr @events, i64 624), %.preheader.26 ], [ getelementptr inbounds (i8, ptr @events, i64 648), %.preheader.27 ], [ getelementptr inbounds (i8, ptr @events, i64 672), %.preheader.28 ], [ getelementptr inbounds (i8, ptr @events, i64 696), %.preheader.29 ], [ getelementptr inbounds (i8, ptr @events, i64 720), %.preheader.30 ], [ getelementptr inbounds (i8, ptr @events, i64 744), %.preheader.31 ]
  %71 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %72 = load i8, ptr %71, align 8, !tbaa !14, !range !9, !noundef !10
  %73 = trunc nuw i8 %72 to i1
  %. = select i1 %73, i32 0, i32 -4
  br label %.thread

.thread:                                          ; preds = %.preheader.31, %70, %3, %1
  %.1 = phi i32 [ -1, %1 ], [ -4, %3 ], [ %., %70 ], [ -1, %.preheader.31 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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 = !{!"Event", !13, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !6, i64 8}


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