; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (quantum_scheduler)

; 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.anon = type { i8, %struct.scheduler_config_t, ptr, i64, i64, ptr, i64, ptr, i32, i8, double }
%struct.scheduler_config_t = type { i64, i64, i8, i8, double, i32 }
%struct.quantum_task_t = type { ptr, i32, ptr, i64, ptr, i64, i32, ptr, double, double }
%struct.resource_requirement_t = type { i32, i64, double, i8 }
%struct.resource_pool_t = type { i32, i64, i64, double, ptr }

@scheduler = external hidden global %struct.anon, align 8

; 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 zeroext i1 @release_resources(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load i8, ptr @scheduler, align 8, !tbaa !9, !range !16, !noundef !17
  %12 = trunc i8 %11 to i1
  br i1 %12, label %13, label %16

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %13, %1
  store i32 1, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !18
  store i1 false, ptr %2, align 1
  br label %118

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 0, ptr %4, align 8, !tbaa !19
  br label %18

18:                                               ; preds = %114, %17
  %19 = load i64, ptr %4, align 8, !tbaa !19
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.quantum_task_t, ptr %20, i32 0, i32 3
  %22 = load i64, ptr %21, align 8, !tbaa !20
  %23 = icmp ult i64 %19, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %117

25:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.quantum_task_t, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = load i64, ptr %4, align 8, !tbaa !19
  %30 = getelementptr inbounds %struct.resource_requirement_t, ptr %28, i64 %29
  store ptr %30, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !19
  br label %31

31:                                               ; preds = %109, %25
  %32 = load i64, ptr %7, align 8, !tbaa !19
  %33 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 6), align 8, !tbaa !23
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %5, align 4
  br label %112

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %37 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !24
  %38 = load i64, ptr %7, align 8, !tbaa !19
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.resource_pool_t, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !25
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.resource_requirement_t, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !27
  %47 = icmp eq i32 %43, %46
  br i1 %47, label %48, label %105

48:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !19
  br label %49

49:                                               ; preds = %81, %48
  %50 = load i64, ptr %10, align 8, !tbaa !19
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.resource_pool_t, ptr %51, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !29
  %54 = icmp ult i64 %50, %53
  br i1 %54, label %55, label %61

55:                                               ; preds = %49
  %56 = load i64, ptr %9, align 8, !tbaa !19
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.resource_requirement_t, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !30
  %60 = icmp ult i64 %56, %59
  br label %61

61:                                               ; preds = %55, %49
  %62 = phi i1 [ false, %49 ], [ %60, %55 ]
  br i1 %62, label %64, label %63

63:                                               ; preds = %61
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %84

64:                                               ; preds = %61
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.resource_pool_t, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !31
  %68 = load i64, ptr %10, align 8, !tbaa !19
  %69 = getelementptr inbounds i8, ptr %67, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !32, !range !16, !noundef !17
  %71 = trunc i8 %70 to i1
  br i1 %71, label %72, label %80

72:                                               ; preds = %64
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.resource_pool_t, ptr %73, i32 0, i32 4
  %75 = load ptr, ptr %74, align 8, !tbaa !31
  %76 = load i64, ptr %10, align 8, !tbaa !19
  %77 = getelementptr inbounds i8, ptr %75, i64 %76
  store i8 0, ptr %77, align 1, !tbaa !32
  %78 = load i64, ptr %9, align 8, !tbaa !19
  %79 = add i64 %78, 1
  store i64 %79, ptr %9, align 8, !tbaa !19
  br label %80

80:                                               ; preds = %72, %64
  br label %81

81:                                               ; preds = %80
  %82 = load i64, ptr %10, align 8, !tbaa !19
  %83 = add i64 %82, 1
  store i64 %83, ptr %10, align 8, !tbaa !19
  br label %49, !llvm.loop !33

84:                                               ; preds = %63
  %85 = load i64, ptr %9, align 8, !tbaa !19
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.resource_pool_t, ptr %86, i32 0, i32 2
  %88 = load i64, ptr %87, align 8, !tbaa !35
  %89 = add i64 %88, %85
  store i64 %89, ptr %87, align 8, !tbaa !35
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.resource_pool_t, ptr %90, i32 0, i32 1
  %92 = load i64, ptr %91, align 8, !tbaa !29
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.resource_pool_t, ptr %93, i32 0, i32 2
  %95 = load i64, ptr %94, align 8, !tbaa !35
  %96 = sub i64 %92, %95
  %97 = uitofp i64 %96 to double
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.resource_pool_t, ptr %98, i32 0, i32 1
  %100 = load i64, ptr %99, align 8, !tbaa !29
  %101 = uitofp i64 %100 to double
  %102 = fdiv double %97, %101
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.resource_pool_t, ptr %103, i32 0, i32 3
  store double %102, ptr %104, align 8, !tbaa !36
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %106

105:                                              ; preds = %36
  store i32 0, ptr %5, align 4
  br label %106

106:                                              ; preds = %105, %84
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %107 = load i32, ptr %5, align 4
  switch i32 %107, label %112 [
    i32 0, label %108
  ]

108:                                              ; preds = %106
  br label %109

109:                                              ; preds = %108
  %110 = load i64, ptr %7, align 8, !tbaa !19
  %111 = add i64 %110, 1
  store i64 %111, ptr %7, align 8, !tbaa !19
  br label %31, !llvm.loop !37

112:                                              ; preds = %106, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %113

113:                                              ; preds = %112
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %114

114:                                              ; preds = %113
  %115 = load i64, ptr %4, align 8, !tbaa !19
  %116 = add i64 %115, 1
  store i64 %116, ptr %4, align 8, !tbaa !19
  br label %18, !llvm.loop !38

117:                                              ; preds = %24
  store i1 true, ptr %2, align 1
  br label %118

118:                                              ; preds = %117, %16
  %119 = load i1, ptr %2, align 1
  ret i1 %119
}

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, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 48, !13, i64 56, !13, i64 64, !6, i64 72, !13, i64 80, !6, i64 88, !15, i64 96, !11, i64 100, !14, i64 104}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !11, i64 16, !11, i64 17, !14, i64 24, !15, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !15, i64 96}
!19 = !{!13, !13, i64 0}
!20 = !{!21, !13, i64 24}
!21 = !{!"quantum_task_t", !6, i64 0, !15, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !13, i64 40, !15, i64 48, !6, i64 56, !14, i64 64, !14, i64 72}
!22 = !{!21, !6, i64 16}
!23 = !{!10, !13, i64 80}
!24 = !{!10, !6, i64 72}
!25 = !{!26, !15, i64 0}
!26 = !{!"", !15, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !6, i64 32}
!27 = !{!28, !15, i64 0}
!28 = !{!"", !15, i64 0, !13, i64 8, !14, i64 16, !11, i64 24}
!29 = !{!26, !13, i64 8}
!30 = !{!28, !13, i64 8}
!31 = !{!26, !6, i64 32}
!32 = !{!11, !11, i64 0}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}
!35 = !{!26, !13, i64 16}
!36 = !{!26, !14, i64 24}
!37 = distinct !{!37, !34}
!38 = distinct !{!38, !34}


; 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.anon = type { i8, %struct.scheduler_config_t, ptr, i64, i64, ptr, i64, ptr, i32, i8, double }
%struct.scheduler_config_t = type { i64, i64, i8, i8, double, i32 }
%struct.resource_requirement_t = type { i32, i64, double, i8 }

@scheduler = external hidden local_unnamed_addr global %struct.anon, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @release_resources(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr @scheduler, align 8, !tbaa !5, !range !15, !noundef !16
  %3 = trunc nuw i8 %2 to i1
  %4 = icmp ne ptr %0, null
  %or.cond = and i1 %4, %3
  br i1 %or.cond, label %.preheader37, label %43

.preheader37:                                     ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !17
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %.loopexit, label %.lr.ph47

.lr.ph47:                                         ; preds = %.preheader37
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !19
  %9 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 80), align 8, !tbaa !20
  %.not48 = icmp eq i64 %9, 0
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8
  br i1 %.not48, label %.loopexit, label %.lr.ph45.us

.lr.ph45.us:                                      ; preds = %.lr.ph47, %._crit_edge.us
  %.03246.us = phi i64 [ %29, %._crit_edge.us ], [ 0, %.lr.ph47 ]
  %11 = getelementptr inbounds %struct.resource_requirement_t, ptr %8, i64 %.03246.us
  %12 = load i32, ptr %11, align 8, !tbaa !21
  %13 = getelementptr inbounds i8, ptr %11, i64 8
  br label %14

14:                                               ; preds = %.lr.ph45.us, %.critedge36.us
  %.03144.us = phi i64 [ 0, %.lr.ph45.us ], [ %28, %.critedge36.us ]
  %15 = getelementptr inbounds ptr, ptr %10, i64 %.03144.us
  %16 = load ptr, ptr %15, align 8, !tbaa !23
  %17 = load i32, ptr %16, align 8, !tbaa !24
  %.not.us = icmp eq i32 %17, %12
  br i1 %.not.us, label %.preheader.us, label %.critedge36.us

18:                                               ; preds = %.lr.ph.us, %37
  %.039.us = phi i64 [ 0, %.lr.ph.us ], [ %38, %37 ]
  %.02938.us = phi i64 [ 0, %.lr.ph.us ], [ %.1.us, %37 ]
  %19 = icmp ult i64 %.02938.us, %41
  br i1 %19, label %30, label %.critedge.us

.critedge.us:                                     ; preds = %18, %37, %.preheader.us
  %.029.lcssa.us = phi i64 [ 0, %.preheader.us ], [ %.1.us, %37 ], [ %.02938.us, %18 ]
  %20 = getelementptr inbounds i8, ptr %16, i64 16
  %21 = load i64, ptr %20, align 8, !tbaa !26
  %22 = add i64 %21, %.029.lcssa.us
  store i64 %22, ptr %20, align 8, !tbaa !26
  %23 = sub i64 %40, %22
  %24 = uitofp i64 %23 to double
  %25 = uitofp i64 %40 to double
  %26 = fdiv double %24, %25
  %27 = getelementptr inbounds i8, ptr %16, i64 24
  store double %26, ptr %27, align 8, !tbaa !27
  br label %._crit_edge.us

.critedge36.us:                                   ; preds = %14
  %28 = add nuw i64 %.03144.us, 1
  %exitcond.not = icmp eq i64 %28, %9
  br i1 %exitcond.not, label %._crit_edge.us, label %14, !llvm.loop !28

._crit_edge.us:                                   ; preds = %.critedge36.us, %.critedge.us
  %29 = add nuw i64 %.03246.us, 1
  %exitcond53.not = icmp eq i64 %29, %6
  br i1 %exitcond53.not, label %.loopexit, label %.lr.ph45.us, !llvm.loop !30

30:                                               ; preds = %18
  %31 = load ptr, ptr %42, align 8, !tbaa !31
  %32 = getelementptr inbounds i8, ptr %31, i64 %.039.us
  %33 = load i8, ptr %32, align 1, !tbaa !32, !range !15, !noundef !16
  %34 = trunc nuw i8 %33 to i1
  br i1 %34, label %35, label %37

35:                                               ; preds = %30
  store i8 0, ptr %32, align 1, !tbaa !32
  %36 = add nuw i64 %.02938.us, 1
  br label %37

37:                                               ; preds = %35, %30
  %.1.us = phi i64 [ %36, %35 ], [ %.02938.us, %30 ]
  %38 = add nuw i64 %.039.us, 1
  %exitcond52.not = icmp eq i64 %38, %40
  br i1 %exitcond52.not, label %.critedge.us, label %18, !llvm.loop !33

.preheader.us:                                    ; preds = %14
  %39 = getelementptr inbounds i8, ptr %16, i64 8
  %40 = load i64, ptr %39, align 8, !tbaa !34
  %.not49 = icmp eq i64 %40, 0
  br i1 %.not49, label %.critedge.us, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.preheader.us
  %41 = load i64, ptr %13, align 8, !tbaa !35
  %42 = getelementptr inbounds i8, ptr %16, i64 32
  br label %18

43:                                               ; preds = %1
  store i32 1, ptr getelementptr inbounds (i8, ptr @scheduler, i64 96), align 8, !tbaa !36
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.us, %.lr.ph47, %.preheader37, %43
  ret i1 %or.cond
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !14, i64 48, !11, i64 56, !11, i64 64, !14, i64 72, !11, i64 80, !14, i64 88, !13, i64 96, !7, i64 100, !12, i64 104}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16, !7, i64 17, !12, i64 24, !13, i64 32}
!11 = !{!"long", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !11, i64 24}
!18 = !{!"quantum_task_t", !14, i64 0, !13, i64 8, !14, i64 16, !11, i64 24, !14, i64 32, !11, i64 40, !13, i64 48, !14, i64 56, !12, i64 64, !12, i64 72}
!19 = !{!18, !14, i64 16}
!20 = !{!6, !11, i64 80}
!21 = !{!22, !13, i64 0}
!22 = !{!"", !13, i64 0, !11, i64 8, !12, i64 16, !7, i64 24}
!23 = !{!14, !14, i64 0}
!24 = !{!25, !13, i64 0}
!25 = !{!"", !13, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !14, i64 32}
!26 = !{!25, !11, i64 16}
!27 = !{!25, !12, i64 24}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = distinct !{!30, !29}
!31 = !{!25, !14, i64 32}
!32 = !{!7, !7, i64 0}
!33 = distinct !{!33, !29}
!34 = !{!25, !11, i64 8}
!35 = !{!22, !11, i64 8}
!36 = !{!6, !13, i64 96}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass