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

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

@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1

declare void @geometric_log_error(ptr noundef, ...) #0

; 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: nounwind uwtable
define dso_local void @simd_complex_multiply_accumulate(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.ComplexFloat, align 4
  %11 = alloca %struct.ComplexFloat, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %20

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

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %14, %4
  call void (ptr, ...) @geometric_log_error(ptr noundef @.str.1)
  br label %49

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %46, %21
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %49

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.ComplexFloat, ptr %28, i64 %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.ComplexFloat, ptr %31, i64 %32
  %34 = load <2 x float>, ptr %30, align 4
  %35 = load <2 x float>, ptr %33, align 4
  %36 = call <2 x float> @complex_float_multiply(<2 x float> %34, <2 x float> %35)
  store <2 x float> %36, ptr %10, align 4
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.ComplexFloat, ptr %37, i64 %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.ComplexFloat, ptr %40, i64 %41
  %43 = load <2 x float>, ptr %42, align 4
  %44 = load <2 x float>, ptr %10, align 4
  %45 = call <2 x float> @complex_float_add(<2 x float> %43, <2 x float> %44)
  store <2 x float> %45, ptr %11, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %39, ptr align 4 %11, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %46

46:                                               ; preds = %27
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %9, align 8, !tbaa !9
  br label %22, !llvm.loop !14

49:                                               ; preds = %26, %20
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @complex_float_multiply(<2 x float>, <2 x float>) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @complex_float_add(<2 x float>, <2 x float>) #4

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

attributes #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1

declare void @geometric_log_error(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @simd_complex_multiply_accumulate(ptr noundef %0, ptr noundef readonly %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  %7 = icmp ne ptr %2, null
  %or.cond3 = and i1 %or.cond, %7
  br i1 %or.cond3, label %.preheader, label %8

.preheader:                                       ; preds = %4
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

8:                                                ; preds = %4
  tail call void (ptr, ...) @geometric_log_error(ptr noundef nonnull @.str.1) #3
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.020 = phi i64 [ %17, %.lr.ph ], [ 0, %.preheader ]
  %9 = getelementptr inbounds %struct.ComplexFloat, ptr %1, i64 %.020
  %10 = getelementptr inbounds %struct.ComplexFloat, ptr %2, i64 %.020
  %11 = load <2 x float>, ptr %9, align 4
  %12 = load <2 x float>, ptr %10, align 4
  %13 = tail call <2 x float> @complex_float_multiply(<2 x float> %11, <2 x float> %12)
  %14 = getelementptr inbounds %struct.ComplexFloat, ptr %0, i64 %.020
  %15 = load <2 x float>, ptr %14, align 4
  %16 = tail call <2 x float> @complex_float_add(<2 x float> %15, <2 x float> %13)
  store <2 x float> %16, ptr %14, align 4
  %17 = add nuw i64 %.020, 1
  %exitcond.not = icmp eq i64 %17, %3
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %8
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @complex_float_multiply(<2 x float>, <2 x float>) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @complex_float_add(<2 x float>, <2 x float>) local_unnamed_addr #2

attributes #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 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 #2 = { inlinehint 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass