; 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_pool_t = type { i32, i64, i64, double, ptr }

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @shutdown_quantum_scheduler() #1 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = load i8, ptr @scheduler, align 8, !tbaa !5, !range !15, !noundef !16
  %5 = trunc i8 %4 to i1
  br i1 %5, label %7, label %6

6:                                                ; preds = %0
  br label %68

7:                                                ; preds = %0
  %8 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 9), align 4, !tbaa !17, !range !15, !noundef !16
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = call zeroext i1 @stop_scheduler()
  br label %12

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

13:                                               ; preds = %34, %12
  %14 = load i64, ptr %1, align 8, !tbaa !18
  %15 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 3), align 8, !tbaa !19
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  br label %37

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %19 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !20
  %20 = load i64, ptr %1, align 8, !tbaa !18
  %21 = getelementptr inbounds ptr, ptr %19, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  store ptr %22, ptr %2, align 8, !tbaa !21
  %23 = load ptr, ptr %2, align 8, !tbaa !21
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %33

25:                                               ; preds = %18
  %26 = load ptr, ptr %2, align 8, !tbaa !21
  %27 = getelementptr inbounds %struct.quantum_task_t, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  call void @free(ptr noundef %28) #3
  %29 = load ptr, ptr %2, align 8, !tbaa !21
  %30 = getelementptr inbounds %struct.quantum_task_t, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !24
  call void @free(ptr noundef %31) #3
  %32 = load ptr, ptr %2, align 8, !tbaa !21
  call void @free(ptr noundef %32) #3
  br label %33

33:                                               ; preds = %25, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %1, align 8, !tbaa !18
  %36 = add i64 %35, 1
  store i64 %36, ptr %1, align 8, !tbaa !18
  br label %13, !llvm.loop !25

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

38:                                               ; preds = %61, %37
  %39 = load i64, ptr %3, align 8, !tbaa !18
  %40 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 6), align 8, !tbaa !27
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %64

43:                                               ; preds = %38
  %44 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !28
  %45 = load i64, ptr %3, align 8, !tbaa !18
  %46 = getelementptr inbounds ptr, ptr %44, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %60

49:                                               ; preds = %43
  %50 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !28
  %51 = load i64, ptr %3, align 8, !tbaa !18
  %52 = getelementptr inbounds ptr, ptr %50, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !21
  %54 = getelementptr inbounds %struct.resource_pool_t, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !29
  call void @free(ptr noundef %55) #3
  %56 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !28
  %57 = load i64, ptr %3, align 8, !tbaa !18
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  call void @free(ptr noundef %59) #3
  br label %60

60:                                               ; preds = %49, %43
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %3, align 8, !tbaa !18
  %63 = add i64 %62, 1
  store i64 %63, ptr %3, align 8, !tbaa !18
  br label %38, !llvm.loop !31

64:                                               ; preds = %42
  %65 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !20
  call void @free(ptr noundef %65) #3
  %66 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !28
  call void @free(ptr noundef %66) #3
  %67 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 7), align 8, !tbaa !32
  call void @free(ptr noundef %67) #3
  store i8 0, ptr @scheduler, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %64, %6
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @stop_scheduler() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!6, !7, i64 100}
!18 = !{!11, !11, i64 0}
!19 = !{!6, !11, i64 56}
!20 = !{!6, !14, i64 48}
!21 = !{!14, !14, i64 0}
!22 = !{!23, !14, i64 16}
!23 = !{!"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}
!24 = !{!23, !14, i64 32}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!6, !11, i64 80}
!28 = !{!6, !14, i64 72}
!29 = !{!30, !14, i64 32}
!30 = !{!"", !13, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !14, i64 32}
!31 = distinct !{!31, !26}
!32 = !{!6, !14, i64 88}


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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @shutdown_quantum_scheduler() local_unnamed_addr #1 {
  %1 = load i8, ptr @scheduler, align 8, !tbaa !5, !range !15, !noundef !16
  %2 = trunc nuw i8 %1 to i1
  br i1 %2, label %3, label %43

3:                                                ; preds = %0
  %4 = load i8, ptr getelementptr inbounds (i8, ptr @scheduler, i64 100), align 4, !tbaa !17, !range !15, !noundef !16
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %8

6:                                                ; preds = %3
  %7 = tail call zeroext i1 @stop_scheduler()
  br label %8

8:                                                ; preds = %6, %3
  %9 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 56), align 8, !tbaa !18
  %.not18 = icmp eq i64 %9, 0
  br i1 %.not18, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %8
  %.pre20 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !19
  br label %.lr.ph

.preheader:                                       ; preds = %20, %8
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 80), align 8, !tbaa !20
  %.not19 = icmp eq i64 %10, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph17.preheader

.lr.ph17.preheader:                               ; preds = %.preheader
  %.pre23 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8, !tbaa !21
  br label %.lr.ph17

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %11 = phi i64 [ %21, %20 ], [ %9, %.lr.ph.preheader ]
  %12 = phi ptr [ %22, %20 ], [ %.pre20, %.lr.ph.preheader ]
  %.01115 = phi i64 [ %23, %20 ], [ 0, %.lr.ph.preheader ]
  %13 = getelementptr inbounds ptr, ptr %12, i64 %.01115
  %14 = load ptr, ptr %13, align 8, !tbaa !22
  %.not14 = icmp eq ptr %14, null
  br i1 %.not14, label %20, label %15

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %14, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !23
  tail call void @free(ptr noundef %17) #2
  %18 = getelementptr inbounds i8, ptr %14, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !25
  tail call void @free(ptr noundef %19) #2
  tail call void @free(ptr noundef nonnull %14) #2
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !19
  %.pre21 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 56), align 8, !tbaa !18
  br label %20

20:                                               ; preds = %15, %.lr.ph
  %21 = phi i64 [ %.pre21, %15 ], [ %11, %.lr.ph ]
  %22 = phi ptr [ %.pre, %15 ], [ %12, %.lr.ph ]
  %23 = add nuw i64 %.01115, 1
  %24 = icmp ult i64 %23, %21
  br i1 %24, label %.lr.ph, label %.preheader, !llvm.loop !26

._crit_edge:                                      ; preds = %38, %.preheader
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !19
  tail call void @free(ptr noundef %25) #2
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8, !tbaa !21
  tail call void @free(ptr noundef %26) #2
  %27 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 88), align 8, !tbaa !28
  tail call void @free(ptr noundef %27) #2
  store i8 0, ptr @scheduler, align 8, !tbaa !5
  br label %43

.lr.ph17:                                         ; preds = %.lr.ph17.preheader, %38
  %28 = phi i64 [ %39, %38 ], [ %10, %.lr.ph17.preheader ]
  %29 = phi ptr [ %40, %38 ], [ %.pre23, %.lr.ph17.preheader ]
  %.016 = phi i64 [ %41, %38 ], [ 0, %.lr.ph17.preheader ]
  %30 = getelementptr inbounds ptr, ptr %29, i64 %.016
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %.not = icmp eq ptr %31, null
  br i1 %.not, label %38, label %32

32:                                               ; preds = %.lr.ph17
  %33 = getelementptr inbounds i8, ptr %31, i64 32
  %34 = load ptr, ptr %33, align 8, !tbaa !29
  tail call void @free(ptr noundef %34) #2
  %35 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8, !tbaa !21
  %36 = getelementptr inbounds ptr, ptr %35, i64 %.016
  %37 = load ptr, ptr %36, align 8, !tbaa !22
  tail call void @free(ptr noundef %37) #2
  %.pre22 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8, !tbaa !21
  %.pre24 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 80), align 8, !tbaa !20
  br label %38

38:                                               ; preds = %.lr.ph17, %32
  %39 = phi i64 [ %28, %.lr.ph17 ], [ %.pre24, %32 ]
  %40 = phi ptr [ %29, %.lr.ph17 ], [ %.pre22, %32 ]
  %41 = add nuw i64 %.016, 1
  %42 = icmp ult i64 %41, %39
  br i1 %42, label %.lr.ph17, label %._crit_edge, !llvm.loop !31

43:                                               ; preds = %0, %._crit_edge
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @stop_scheduler() local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !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 = !{!6, !7, i64 100}
!18 = !{!6, !11, i64 56}
!19 = !{!6, !14, i64 48}
!20 = !{!6, !11, i64 80}
!21 = !{!6, !14, i64 72}
!22 = !{!14, !14, i64 0}
!23 = !{!24, !14, i64 16}
!24 = !{!"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}
!25 = !{!24, !14, i64 32}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!6, !14, i64 88}
!29 = !{!30, !14, i64 32}
!30 = !{!"", !13, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !14, i64 32}
!31 = distinct !{!31, !27}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass