; 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: nounwind uwtable
define dso_local zeroext i1 @initialize_quantum_scheduler(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 ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %7, label %6

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

7:                                                ; preds = %1
  %8 = call noalias ptr @malloc(i64 noundef 512) #4
  store ptr %8, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !16
  %9 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !16
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i32 5, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %27

12:                                               ; preds = %7
  %13 = call noalias ptr @malloc(i64 noundef 128) #4
  store ptr %13, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !17
  %14 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !17
  %15 = icmp ne ptr %14, null
  br i1 %15, label %18, label %16

16:                                               ; preds = %12
  %17 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !16
  call void @free(ptr noundef %17) #5
  store i32 5, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %27

18:                                               ; preds = %12
  %19 = call noalias ptr @malloc(i64 noundef 256) #4
  store ptr %19, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 7), align 8, !tbaa !18
  %20 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 7), align 8, !tbaa !18
  %21 = icmp ne ptr %20, null
  br i1 %21, label %25, label %22

22:                                               ; preds = %18
  %23 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 2), align 8, !tbaa !16
  call void @free(ptr noundef %23) #5
  %24 = load ptr, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 5), align 8, !tbaa !17
  call void @free(ptr noundef %24) #5
  store i32 5, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %27

25:                                               ; preds = %18
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 1), ptr align 8 %26, i64 40, i1 false), !tbaa.struct !19
  store i64 0, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 3), align 8, !tbaa !24
  store i64 64, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 4), align 8, !tbaa !25
  store i64 0, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 6), align 8, !tbaa !26
  store i8 1, ptr @scheduler, align 8, !tbaa !27
  store i8 0, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 9), align 4, !tbaa !28
  store i32 0, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !9
  store i1 true, ptr %2, align 1
  br label %27

27:                                               ; preds = %25, %22, %16, %11, %6
  %28 = load i1, ptr %2, align 1
  ret i1 %28
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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) "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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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, !15, i64 96}
!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 = !{!10, !6, i64 48}
!17 = !{!10, !6, i64 72}
!18 = !{!10, !6, i64 88}
!19 = !{i64 0, i64 8, !20, i64 8, i64 8, !20, i64 16, i64 1, !21, i64 17, i64 1, !21, i64 24, i64 8, !22, i64 32, i64 4, !23}
!20 = !{!13, !13, i64 0}
!21 = !{!11, !11, i64 0}
!22 = !{!14, !14, i64 0}
!23 = !{!15, !15, i64 0}
!24 = !{!10, !13, i64 56}
!25 = !{!10, !13, i64 64}
!26 = !{!10, !13, i64 80}
!27 = !{!10, !11, i64 0}
!28 = !{!10, !11, i64 100}


; 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 uwtable
define dso_local noundef zeroext i1 @initialize_quantum_scheduler(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %11, label %2

2:                                                ; preds = %1
  %3 = tail call noalias dereferenceable_or_null(512) ptr @malloc(i64 noundef 512) #4
  store ptr %3, ptr getelementptr inbounds (i8, ptr @scheduler, i64 48), align 8, !tbaa !5
  %.not4 = icmp eq ptr %3, null
  br i1 %.not4, label %11, label %4

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(128) ptr @malloc(i64 noundef 128) #4
  store ptr %5, ptr getelementptr inbounds (i8, ptr @scheduler, i64 72), align 8, !tbaa !15
  %.not5 = icmp eq ptr %5, null
  br i1 %.not5, label %6, label %7

6:                                                ; preds = %4
  tail call void @free(ptr noundef nonnull %3) #5
  br label %11

7:                                                ; preds = %4
  %8 = tail call noalias dereferenceable_or_null(256) ptr @malloc(i64 noundef 256) #4
  store ptr %8, ptr getelementptr inbounds (i8, ptr @scheduler, i64 88), align 8, !tbaa !16
  %.not6 = icmp eq ptr %8, null
  br i1 %.not6, label %9, label %10

9:                                                ; preds = %7
  tail call void @free(ptr noundef nonnull %3) #5
  tail call void @free(ptr noundef nonnull %5) #5
  br label %11

10:                                               ; preds = %7
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) getelementptr inbounds (i8, ptr @scheduler, i64 8), ptr noundef nonnull align 8 dereferenceable(40) %0, i64 40, i1 false), !tbaa.struct !17
  store i64 0, ptr getelementptr inbounds (i8, ptr @scheduler, i64 56), align 8, !tbaa !22
  store i64 64, ptr getelementptr inbounds (i8, ptr @scheduler, i64 64), align 8, !tbaa !23
  store i64 0, ptr getelementptr inbounds (i8, ptr @scheduler, i64 80), align 8, !tbaa !24
  store i8 1, ptr @scheduler, align 8, !tbaa !25
  store i8 0, ptr getelementptr inbounds (i8, ptr @scheduler, i64 100), align 4, !tbaa !26
  br label %11

11:                                               ; preds = %2, %1, %10, %9, %6
  %.sink = phi i32 [ 0, %10 ], [ 5, %9 ], [ 5, %6 ], [ 1, %1 ], [ 5, %2 ]
  %.0 = phi i1 [ true, %10 ], [ false, %9 ], [ false, %6 ], [ false, %1 ], [ false, %2 ]
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @scheduler, i64 96), align 8, !tbaa !27
  ret i1 %.0
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress 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,uninitialized") allocsize(0) 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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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, !14, i64 48}
!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 = !{!6, !14, i64 72}
!16 = !{!6, !14, i64 88}
!17 = !{i64 0, i64 8, !18, i64 8, i64 8, !18, i64 16, i64 1, !19, i64 17, i64 1, !19, i64 24, i64 8, !20, i64 32, i64 4, !21}
!18 = !{!11, !11, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!12, !12, i64 0}
!21 = !{!13, !13, i64 0}
!22 = !{!6, !11, i64 56}
!23 = !{!6, !11, i64 64}
!24 = !{!6, !11, i64 80}
!25 = !{!6, !7, i64 0}
!26 = !{!6, !7, i64 100}
!27 = !{!6, !13, i64 96}


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