; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (numerical_backend_cpu)

; 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 { %struct.numerical_config_t, %struct.numerical_metrics_t, i32, i8, i8 }
%struct.numerical_config_t = type { i32, i64, i8, i8, i8, i64, ptr }
%struct.numerical_metrics_t = type { double, double, double, double, i64 }

@backend_state = external hidden global %struct.anon, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @initialize_numerical_backend(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 @backend_state, i32 0, i32 2), align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %27

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @backend_state, ptr align 8 %8, i64 40, i1 false), !tbaa.struct !17
  store i8 1, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 3), align 4, !tbaa !21
  store i32 0, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 2), align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 8 getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 1), i8 0, i64 40, i1 false)
  %9 = call zeroext i1 @lapack_has_capability(ptr noundef @.str)
  br i1 %9, label %10, label %24

10:                                               ; preds = %7
  %11 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.1)
  br i1 %11, label %12, label %24

12:                                               ; preds = %10
  %13 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.2)
  br i1 %13, label %14, label %24

14:                                               ; preds = %12
  %15 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.3)
  br i1 %15, label %16, label %24

16:                                               ; preds = %14
  %17 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.4)
  br i1 %17, label %18, label %24

18:                                               ; preds = %16
  %19 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.5)
  br i1 %19, label %20, label %24

20:                                               ; preds = %18
  %21 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.6)
  br i1 %21, label %22, label %24

22:                                               ; preds = %20
  %23 = call zeroext i1 @lapack_has_capability(ptr noundef @.str.7)
  br label %24

24:                                               ; preds = %22, %20, %18, %16, %14, %12, %10, %7
  %25 = phi i1 [ false, %20 ], [ false, %18 ], [ false, %16 ], [ false, %14 ], [ false, %12 ], [ false, %10 ], [ false, %7 ], [ %23, %22 ]
  %26 = zext i1 %25 to i8
  store i8 %26, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 4), align 1, !tbaa !22
  store i1 true, ptr %2, align 1
  br label %27

27:                                               ; preds = %24, %6
  %28 = load i1, ptr %2, align 1
  ret i1 %28
}

; 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) #1

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

declare zeroext i1 @lapack_has_capability(ptr noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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, !12, i64 80}
!10 = !{!"", !11, i64 0, !15, i64 40, !12, i64 80, !14, i64 84, !14, i64 85}
!11 = !{!"", !12, i64 0, !13, i64 8, !14, i64 16, !14, i64 17, !14, i64 18, !13, i64 24, !6, i64 32}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !13, i64 32}
!16 = !{!"double", !7, i64 0}
!17 = !{i64 0, i64 4, !18, i64 8, i64 8, !19, i64 16, i64 1, !20, i64 17, i64 1, !20, i64 18, i64 1, !20, i64 24, i64 8, !19, i64 32, i64 8, !5}
!18 = !{!12, !12, i64 0}
!19 = !{!13, !13, i64 0}
!20 = !{!14, !14, i64 0}
!21 = !{!10, !14, i64 84}
!22 = !{!10, !14, i64 85}


; 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 { %struct.numerical_config_t, %struct.numerical_metrics_t, i32, i8, i8 }
%struct.numerical_config_t = type { i32, i64, i8, i8, i8, i64, ptr }
%struct.numerical_metrics_t = type { double, double, double, double, i64 }

@backend_state = external hidden local_unnamed_addr global %struct.anon, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @initialize_numerical_backend(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp ne ptr %0, null
  br i1 %.not, label %3, label %2

2:                                                ; preds = %1
  store i32 1, ptr getelementptr inbounds (i8, ptr @backend_state, i64 80), align 8, !tbaa !5
  br label %22

3:                                                ; preds = %1
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) @backend_state, ptr noundef nonnull align 8 dereferenceable(40) %0, i64 40, i1 false), !tbaa.struct !16
  store i8 1, ptr getelementptr inbounds (i8, ptr @backend_state, i64 84), align 4, !tbaa !21
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(44) getelementptr inbounds (i8, ptr @backend_state, i64 40), i8 0, i64 44, i1 false)
  %4 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str) #4
  br i1 %4, label %5, label %20

5:                                                ; preds = %3
  %6 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.1) #4
  br i1 %6, label %7, label %20

7:                                                ; preds = %5
  %8 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.2) #4
  br i1 %8, label %9, label %20

9:                                                ; preds = %7
  %10 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.3) #4
  br i1 %10, label %11, label %20

11:                                               ; preds = %9
  %12 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.4) #4
  br i1 %12, label %13, label %20

13:                                               ; preds = %11
  %14 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.5) #4
  br i1 %14, label %15, label %20

15:                                               ; preds = %13
  %16 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.6) #4
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = tail call zeroext i1 @lapack_has_capability(ptr noundef nonnull @.str.7) #4
  %19 = zext i1 %18 to i8
  br label %20

20:                                               ; preds = %17, %15, %13, %11, %9, %7, %5, %3
  %21 = phi i8 [ 0, %15 ], [ 0, %13 ], [ 0, %11 ], [ 0, %9 ], [ 0, %7 ], [ 0, %5 ], [ 0, %3 ], [ %19, %17 ]
  store i8 %21, ptr getelementptr inbounds (i8, ptr @backend_state, i64 85), align 1, !tbaa !22
  br label %22

22:                                               ; preds = %20, %2
  ret i1 %.not
}

; 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) #1

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

declare zeroext i1 @lapack_has_capability(ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 }

!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, !8, i64 80}
!6 = !{!"", !7, i64 0, !14, i64 40, !8, i64 80, !12, i64 84, !12, i64 85}
!7 = !{!"", !8, i64 0, !11, i64 8, !12, i64 16, !12, i64 17, !12, i64 18, !11, i64 24, !13, i64 32}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"_Bool", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !11, i64 32}
!15 = !{!"double", !9, i64 0}
!16 = !{i64 0, i64 4, !17, i64 8, i64 8, !18, i64 16, i64 1, !19, i64 17, i64 1, !19, i64 18, i64 1, !19, i64 24, i64 8, !18, i64 32, i64 8, !20}
!17 = !{!8, !8, i64 0}
!18 = !{!11, !11, i64 0}
!19 = !{!12, !12, i64 0}
!20 = !{!13, !13, i64 0}
!21 = !{!6, !12, i64 84}
!22 = !{!6, !12, i64 85}


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