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

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

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9, %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 %54

13:                                               ; preds = %9
  %14 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 3), align 8, !tbaa !19
  %15 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 4), align 8, !tbaa !20
  %16 = icmp uge i64 %14, %15
  br i1 %16, label %17, label %38

17:                                               ; preds = %13
  %18 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 3), align 8, !tbaa !19
  %19 = load i64, ptr getelementptr inbounds (%struct.scheduler_config_t, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 1), i32 0, i32 1), align 8, !tbaa !21
  %20 = icmp uge i64 %18, %19
  br i1 %20, label %21, label %22

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

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %23 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 4), align 8, !tbaa !20
  %24 = mul i64 %23, 2
  store i64 %24, ptr %4, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %25 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !23
  %26 = load i64, ptr %4, align 8, !tbaa !22
  %27 = mul i64 %26, 8
  %28 = call ptr @realloc(ptr noundef %25, i64 noundef %27) #5
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %22
  store i32 5, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !18
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %35

32:                                               ; preds = %22
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %33, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !23
  %34 = load i64, ptr %4, align 8, !tbaa !22
  store i64 %34, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 4), align 8, !tbaa !20
  store i32 0, ptr %6, align 4
  br label %35

35:                                               ; preds = %32, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %36 = load i32, ptr %6, align 4
  switch i32 %36, label %56 [
    i32 0, label %37
    i32 1, label %54
  ]

37:                                               ; preds = %35
  br label %38

38:                                               ; preds = %37, %13
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call zeroext i1 @validate_task_dependencies(ptr noundef %39)
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %38
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !23
  %45 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 3), align 8, !tbaa !19
  %46 = add i64 %45, 1
  store i64 %46, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 3), align 8, !tbaa !19
  %47 = getelementptr inbounds ptr, ptr %44, i64 %45
  store ptr %43, ptr %47, align 8, !tbaa !5
  %48 = load i8, ptr getelementptr inbounds (%struct.scheduler_config_t, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 1), i32 0, i32 2), align 8, !tbaa !24, !range !16, !noundef !17
  %49 = trunc i8 %48 to i1
  br i1 %49, label %50, label %53

50:                                               ; preds = %42
  %51 = load i32, ptr getelementptr inbounds (%struct.scheduler_config_t, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 1), i32 0, i32 5), align 8, !tbaa !25
  %52 = call zeroext i1 @reorder_queue(i32 noundef %51)
  br label %53

53:                                               ; preds = %50, %42
  store i1 true, ptr %2, align 1
  br label %54

54:                                               ; preds = %53, %41, %35, %21, %12
  %55 = load i1, ptr %2, align 1
  ret i1 %55

56:                                               ; preds = %35
  unreachable
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @validate_task_dependencies(ptr noundef) #1

declare zeroext i1 @reorder_queue(i32 noundef) #3

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 allocsize(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 #3 = { "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(1) }

!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 = !{!10, !13, i64 56}
!20 = !{!10, !13, i64 64}
!21 = !{!10, !13, i64 16}
!22 = !{!13, !13, i64 0}
!23 = !{!10, !6, i64 48}
!24 = !{!10, !11, i64 24}
!25 = !{!10, !15, i64 40}


; 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: nounwind uwtable
define dso_local noundef zeroext i1 @submit_task(ptr noundef %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 %6, label %5

5:                                                ; preds = %1
  store i32 1, ptr getelementptr inbounds (i8, ptr @scheduler, i64 96), align 8, !tbaa !17
  br label %31

6:                                                ; preds = %1
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 56), align 8, !tbaa !18
  %8 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 64), align 8, !tbaa !19
  %.not = icmp ult i64 %7, %8
  br i1 %.not, label %18, label %9

9:                                                ; preds = %6
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 16), align 8, !tbaa !20
  %.not14 = icmp ult i64 %7, %10
  br i1 %.not14, label %12, label %11

11:                                               ; preds = %9
  store i32 3, ptr getelementptr inbounds (i8, ptr @scheduler, i64 96), align 8, !tbaa !17
  br label %31

12:                                               ; preds = %9
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !21
  %14 = shl i64 %8, 4
  %15 = tail call ptr @realloc(ptr noundef %13, i64 noundef %14) #3
  %.not15 = icmp eq ptr %15, null
  br i1 %.not15, label %17, label %.thread

.thread:                                          ; preds = %12
  %16 = shl i64 %8, 1
  store ptr %15, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !21
  store i64 %16, ptr getelementptr inbounds (i8, ptr @scheduler, i64 64), align 8, !tbaa !19
  br label %18

17:                                               ; preds = %12
  store i32 5, ptr getelementptr inbounds (i8, ptr @scheduler, i64 96), align 8, !tbaa !17
  br label %31

18:                                               ; preds = %.thread, %6
  %19 = tail call zeroext i1 @validate_task_dependencies(ptr noundef nonnull %0)
  br i1 %19, label %21, label %20

20:                                               ; preds = %18
  store i32 4, ptr getelementptr inbounds (i8, ptr @scheduler, i64 96), align 8, !tbaa !17
  br label %31

21:                                               ; preds = %18
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !21
  %23 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 56), align 8, !tbaa !18
  %24 = add i64 %23, 1
  store i64 %24, ptr getelementptr inbounds (i8, ptr @scheduler, i64 56), align 8, !tbaa !18
  %25 = getelementptr inbounds ptr, ptr %22, i64 %23
  store ptr %0, ptr %25, align 8, !tbaa !22
  %26 = load i8, ptr getelementptr inbounds (i8, ptr @scheduler, i64 24), align 8, !tbaa !23, !range !15, !noundef !16
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %28, label %31

28:                                               ; preds = %21
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @scheduler, i64 40), align 8, !tbaa !24
  %30 = tail call zeroext i1 @reorder_queue(i32 noundef %29) #4
  br label %31

31:                                               ; preds = %17, %21, %28, %20, %11, %5
  %.1 = phi i1 [ false, %11 ], [ false, %17 ], [ false, %20 ], [ false, %5 ], [ true, %28 ], [ true, %21 ]
  ret i1 %.1
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @validate_task_dependencies(ptr noundef) local_unnamed_addr #0

declare zeroext i1 @reorder_queue(i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #2 = { "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 allocsize(1) }
attributes #4 = { 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, !13, i64 96}
!18 = !{!6, !11, i64 56}
!19 = !{!6, !11, i64 64}
!20 = !{!6, !11, i64 16}
!21 = !{!6, !14, i64 48}
!22 = !{!14, !14, i64 0}
!23 = !{!6, !7, i64 24}
!24 = !{!6, !13, i64 40}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass