; 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 }
%struct.ComplexFloat = type { float, float }

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

; 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) #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 zeroext i1 @numerical_vector_dot(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.ComplexFloat, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %11 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 3), align 4, !tbaa !11, !range !18, !noundef !19
  %12 = trunc i8 %11 to i1
  br i1 %12, label %13, label %22

13:                                               ; preds = %4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %19, %16, %13, %4
  store i32 1, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 2), align 8, !tbaa !20
  store i1 false, ptr %5, align 1
  br label %29

23:                                               ; preds = %19
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = call <2 x float> @complex_vector_dot(ptr noundef %25, ptr noundef %26, i64 noundef %27)
  store <2 x float> %28, ptr %10, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  store i32 0, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 2), align 8, !tbaa !20
  store i1 true, ptr %5, align 1
  br label %29

29:                                               ; preds = %23, %22
  %30 = load i1, ptr %5, align 1
  ret i1 %30
}

declare <2 x float> @complex_vector_dot(ptr noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="64" "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 }

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


; 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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @numerical_vector_dot(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @backend_state, i64 84), align 4, !tbaa !5, !range !16, !noundef !17
  %6 = trunc nuw i8 %5 to i1
  %7 = icmp ne ptr %0, null
  %or.cond = and i1 %7, %6
  %8 = icmp ne ptr %1, null
  %or.cond3 = and i1 %8, %or.cond
  %9 = icmp ne ptr %2, null
  %or.cond5 = and i1 %9, %or.cond3
  br i1 %or.cond5, label %10, label %12

10:                                               ; preds = %4
  %11 = tail call <2 x float> @complex_vector_dot(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %3) #2
  store <2 x float> %11, ptr %2, align 4
  br label %12

12:                                               ; preds = %4, %10
  %storemerge = phi i32 [ 0, %10 ], [ 1, %4 ]
  store i32 %storemerge, ptr getelementptr inbounds (i8, ptr @backend_state, i64 80), align 8, !tbaa !18
  ret i1 %or.cond5
}

declare <2 x float> @complex_vector_dot(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { "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 }

!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, !12, i64 84}
!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 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!6, !8, i64 80}


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