; 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

declare ptr @geometric_allocate(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @geometric_core_create_event(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %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 %66

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

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 -1, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  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, 32
  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 [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 = icmp ne ptr %24, null
  br i1 %25, label %28, label %26

26:                                               ; preds = %19
  %27 = load i32, ptr %5, align 4, !tbaa !13
  store i32 %27, ptr %4, align 4, !tbaa !13
  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 = %26, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %4, align 4, !tbaa !13
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %36, label %37

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

37:                                               ; preds = %33
  %38 = call ptr @geometric_allocate(i64 noundef 8)
  %39 = load i32, ptr %4, align 4, !tbaa !13
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Event, ptr %41, i32 0, i32 0
  store ptr %38, ptr %42, align 8, !tbaa !15
  %43 = load i32, ptr %4, align 4, !tbaa !13
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Event, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = icmp ne ptr %47, null
  br i1 %48, label %50, label %49

49:                                               ; preds = %37
  store i32 -2, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %65

50:                                               ; preds = %37
  %51 = load i32, ptr %4, align 4, !tbaa !13
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.Event, ptr %53, i32 0, i32 1
  store i8 0, ptr %54, align 8, !tbaa !19
  %55 = load i32, ptr %4, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Event, ptr %57, i32 0, i32 2
  store ptr null, ptr %58, align 8, !tbaa !20
  %59 = load i32, ptr %4, align 4, !tbaa !13
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.Event, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %63, ptr %64, align 8, !tbaa !5
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %65

65:                                               ; preds = %50, %49, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %66

66:                                               ; preds = %65, %13, %9
  %67 = load i32, ptr %2, align 4
  ret i32 %67
}

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


; 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

declare ptr @geometric_allocate(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -14, 1) i32 @geometric_core_create_event(ptr noundef writeonly %0) local_unnamed_addr #1 {
  %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
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %38, label %.preheader.1

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

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

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

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

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

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

.preheader.7:                                     ; preds = %.preheader.6
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 168), align 8, !tbaa !11
  %.not.7 = icmp eq ptr %13, null
  br i1 %.not.7, label %38, label %.preheader.8

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

.preheader.9:                                     ; preds = %.preheader.8
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 216), align 8, !tbaa !11
  %.not.9 = icmp eq ptr %15, null
  br i1 %.not.9, label %38, label %.preheader.10

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

.preheader.11:                                    ; preds = %.preheader.10
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 264), align 8, !tbaa !11
  %.not.11 = icmp eq ptr %17, null
  br i1 %.not.11, label %38, label %.preheader.12

.preheader.12:                                    ; preds = %.preheader.11
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @events, i64 288), align 16, !tbaa !11
  %.not.12 = icmp eq ptr %18, null
  br i1 %.not.12, label %38, label %.preheader.13

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

38:                                               ; 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
  %.018.lcssa.wide = phi i64 [ 0, %.preheader.preheader ], [ 1, %.preheader.1 ], [ 2, %.preheader.2 ], [ 3, %.preheader.3 ], [ 4, %.preheader.4 ], [ 5, %.preheader.5 ], [ 6, %.preheader.6 ], [ 7, %.preheader.7 ], [ 8, %.preheader.8 ], [ 9, %.preheader.9 ], [ 10, %.preheader.10 ], [ 11, %.preheader.11 ], [ 12, %.preheader.12 ], [ 13, %.preheader.13 ], [ 14, %.preheader.14 ], [ 15, %.preheader.15 ], [ 16, %.preheader.16 ], [ 17, %.preheader.17 ], [ 18, %.preheader.18 ], [ 19, %.preheader.19 ], [ 20, %.preheader.20 ], [ 21, %.preheader.21 ], [ 22, %.preheader.22 ], [ 23, %.preheader.23 ], [ 24, %.preheader.24 ], [ 25, %.preheader.25 ], [ 26, %.preheader.26 ], [ 27, %.preheader.27 ], [ 28, %.preheader.28 ], [ 29, %.preheader.29 ], [ 30, %.preheader.30 ], [ 31, %.preheader.31 ]
  %39 = tail call ptr @geometric_allocate(i64 noundef 8) #2
  %40 = getelementptr inbounds [32 x %struct.Event], ptr @events, i64 0, i64 %.018.lcssa.wide
  store ptr %39, ptr %40, align 8, !tbaa !11
  %.not15 = icmp eq ptr %39, null
  br i1 %.not15, label %.thread, label %41

41:                                               ; preds = %38
  %42 = getelementptr inbounds i8, ptr %40, i64 8
  store i8 0, ptr %42, align 8, !tbaa !14
  %43 = getelementptr inbounds i8, ptr %40, i64 16
  store ptr null, ptr %43, align 8, !tbaa !15
  store ptr %39, ptr %0, align 8, !tbaa !16
  br label %.thread

.thread:                                          ; preds = %.preheader.31, %41, %38, %3, %1
  %.1 = phi i32 [ -1, %1 ], [ -4, %3 ], [ 0, %41 ], [ -2, %38 ], [ -14, %.preheader.31 ]
  ret i32 %.1
}

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 = !{!"Event", !13, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !13, i64 16}
!16 = !{!13, !13, i64 0}


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