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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @register_resource_pool(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load i8, ptr @scheduler, align 8, !tbaa !9, !range !16, !noundef !17
  %5 = trunc i8 %4 to i1
  br i1 %5, label %6, label %9

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

9:                                                ; preds = %6, %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 %39

10:                                               ; preds = %6
  %11 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 6), align 8, !tbaa !19
  %12 = icmp uge i64 %11, 16
  br i1 %12, label %13, label %14

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

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.resource_pool_t, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !20
  %18 = call noalias ptr @calloc(i64 noundef %17, i64 noundef 1) #2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.resource_pool_t, ptr %19, i32 0, i32 4
  store ptr %18, ptr %20, align 8, !tbaa !22
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.resource_pool_t, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !22
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %14
  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
  br label %39

26:                                               ; preds = %14
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.resource_pool_t, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !20
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.resource_pool_t, ptr %30, i32 0, i32 2
  store i64 %29, ptr %31, align 8, !tbaa !23
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.resource_pool_t, ptr %32, i32 0, i32 3
  store double 0.000000e+00, ptr %33, align 8, !tbaa !24
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !25
  %36 = load i64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 6), align 8, !tbaa !19
  %37 = add i64 %36, 1
  store i64 %37, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 6), align 8, !tbaa !19
  %38 = getelementptr inbounds ptr, ptr %35, i64 %36
  store ptr %34, ptr %38, align 8, !tbaa !5
  store i1 true, ptr %2, align 1
  br label %39

39:                                               ; preds = %26, %25, %13, %9
  %40 = load i1, ptr %2, align 1
  ret i1 %40
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

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 = { nounwind allocsize(0,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 allocsize(0,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 80}
!20 = !{!21, !13, i64 8}
!21 = !{!"", !15, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !6, i64 32}
!22 = !{!21, !6, i64 32}
!23 = !{!21, !13, i64 16}
!24 = !{!21, !14, i64 24}
!25 = !{!10, !6, i64 72}


; 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 nofree nounwind willreturn uwtable
define dso_local noundef zeroext i1 @register_resource_pool(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 %22

6:                                                ; preds = %1
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 80), align 8, !tbaa !18
  %8 = icmp ugt i64 %7, 15
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !19
  %13 = tail call noalias ptr @calloc(i64 noundef %12, i64 noundef 1) #2
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %13, ptr %14, align 8, !tbaa !21
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %15, label %16

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

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %12, ptr %17, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  store double 0.000000e+00, ptr %18, align 8, !tbaa !23
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8, !tbaa !24
  %20 = add nuw nsw i64 %7, 1
  store i64 %20, ptr getelementptr inbounds (i8, ptr @scheduler, i64 80), align 8, !tbaa !18
  %21 = getelementptr inbounds ptr, ptr %19, i64 %7
  store ptr %0, ptr %21, align 8, !tbaa !25
  br label %22

22:                                               ; preds = %16, %15, %9, %5
  %.0 = phi i1 [ false, %9 ], [ true, %16 ], [ false, %15 ], [ false, %5 ]
  ret i1 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn 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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 = { nounwind allocsize(0,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, !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 80}
!19 = !{!20, !11, i64 8}
!20 = !{!"", !13, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !14, i64 32}
!21 = !{!20, !14, i64 32}
!22 = !{!20, !11, i64 16}
!23 = !{!20, !12, i64 24}
!24 = !{!6, !14, i64 72}
!25 = !{!14, !14, i64 0}


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