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

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

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

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

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

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

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %10, %2
  store i32 1, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !19
  store ptr null, ptr %3, align 8
  br label %44

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = call noalias ptr @malloc(i64 noundef 80) #4
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 5, ptr getelementptr inbounds (%struct.anon, ptr @scheduler, i32 0, i32 8), align 8, !tbaa !19
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %43

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.quantum_task_t, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !20
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.quantum_task_t, ptr %24, i32 0, i32 1
  store i32 %23, ptr %25, align 8, !tbaa !22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.quantum_task_t, ptr %26, i32 0, i32 2
  store ptr null, ptr %27, align 8, !tbaa !23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.quantum_task_t, ptr %28, i32 0, i32 3
  store i64 0, ptr %29, align 8, !tbaa !24
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.quantum_task_t, ptr %30, i32 0, i32 4
  store ptr null, ptr %31, align 8, !tbaa !25
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.quantum_task_t, ptr %32, i32 0, i32 5
  store i64 0, ptr %33, align 8, !tbaa !26
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.quantum_task_t, ptr %34, i32 0, i32 6
  store i32 0, ptr %35, align 8, !tbaa !27
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.quantum_task_t, ptr %36, i32 0, i32 7
  store ptr null, ptr %37, align 8, !tbaa !28
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.quantum_task_t, ptr %38, i32 0, i32 8
  store double 0.000000e+00, ptr %39, align 8, !tbaa !29
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.quantum_task_t, ptr %40, i32 0, i32 9
  store double 0.000000e+00, ptr %41, align 8, !tbaa !30
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %19, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %44

44:                                               ; preds = %43, %13
  %45 = load ptr, ptr %3, align 8
  ret ptr %45
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !14, i64 8, !6, i64 48, !15, i64 56, !15, i64 64, !6, i64 72, !15, i64 80, !6, i64 88, !10, i64 96, !13, i64 100, !16, i64 104}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8, !13, i64 16, !13, i64 17, !16, i64 24, !10, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !10, i64 96}
!20 = !{!21, !6, i64 0}
!21 = !{!"quantum_task_t", !6, i64 0, !10, i64 8, !6, i64 16, !15, i64 24, !6, i64 32, !15, i64 40, !10, i64 48, !6, i64 56, !16, i64 64, !16, i64 72}
!22 = !{!21, !10, i64 8}
!23 = !{!21, !6, i64 16}
!24 = !{!21, !15, i64 24}
!25 = !{!21, !6, i64 32}
!26 = !{!21, !15, i64 40}
!27 = !{!21, !10, i64 48}
!28 = !{!21, !6, i64 56}
!29 = !{!21, !16, i64 64}
!30 = !{!21, !16, 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @create_task(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load i8, ptr @scheduler, align 8, !tbaa !5, !range !15, !noundef !16
  %4 = trunc nuw i8 %3 to i1
  %5 = icmp ne ptr %0, null
  %or.cond = and i1 %5, %4
  br i1 %or.cond, label %7, label %6

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

7:                                                ; preds = %2
  %8 = tail call noalias dereferenceable_or_null(80) ptr @malloc(i64 noundef 80) #3
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %9, label %10

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

10:                                               ; preds = %7
  store ptr %0, ptr %8, align 8, !tbaa !18
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 %1, ptr %11, align 8, !tbaa !20
  %12 = getelementptr inbounds i8, ptr %8, i64 16
  %13 = getelementptr inbounds i8, ptr %8, i64 56
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(36) %12, i8 0, i64 36, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %13, i8 0, i64 24, i1 false)
  br label %14

14:                                               ; preds = %9, %10, %6
  %.1 = phi ptr [ null, %6 ], [ %8, %10 ], [ null, %9 ]
  ret ptr %.1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(readwrite, argmem: 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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind allocsize(0) }

!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 = !{!19, !14, i64 0}
!19 = !{!"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}
!20 = !{!19, !13, i64 8}


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