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

; 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.quantum_geometric_tensor_t = type { i32, ptr, i64, ptr, ptr, i8, i8, i8, i32, i64, i64 }
%struct.ComplexFloat = type { float, float }

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @llvm.prefetch.p0(ptr nocapture readonly, i32 immarg, i32 immarg, i32 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @geometric_tensor_conjugate(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  br label %86

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i32 -1, ptr %3, align 4
  br label %86

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 1024, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %19, i32 0, i32 10
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = udiv i64 %21, 1024
  store i64 %22, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %23, i32 0, i32 10
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = urem i64 %25, 1024
  store i64 %26, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %65, %18
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %68

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = mul i64 %33, 1024
  store i64 %34, ptr %10, align 8, !tbaa !9
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = add i64 %35, 1
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %39, label %54

39:                                               ; preds = %32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = add i64 %43, 1
  %45 = mul i64 %44, 1024
  %46 = getelementptr inbounds %struct.ComplexFloat, ptr %42, i64 %45
  call void @llvm.prefetch.p0(ptr %46, i32 0, i32 3, i32 1)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = add i64 %50, 1
  %52 = mul i64 %51, 1024
  %53 = getelementptr inbounds %struct.ComplexFloat, ptr %49, i64 %52
  call void @llvm.prefetch.p0(ptr %53, i32 1, i32 3, i32 1)
  br label %54

54:                                               ; preds = %39, %32
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.ComplexFloat, ptr %57, i64 %58
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.ComplexFloat, ptr %62, i64 %63
  call void @simd_tensor_conjugate(ptr noundef %59, ptr noundef %64, i64 noundef 1024)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %65

65:                                               ; preds = %54
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %9, align 8, !tbaa !9
  br label %27, !llvm.loop !16

68:                                               ; preds = %31
  %69 = load i64, ptr %8, align 8, !tbaa !9
  %70 = icmp ugt i64 %69, 0
  br i1 %70, label %71, label %85

71:                                               ; preds = %68
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = load i64, ptr %7, align 8, !tbaa !9
  %76 = mul i64 %75, 1024
  %77 = getelementptr inbounds %struct.ComplexFloat, ptr %74, i64 %76
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.quantum_geometric_tensor_t, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = mul i64 %81, 1024
  %83 = getelementptr inbounds %struct.ComplexFloat, ptr %80, i64 %82
  %84 = load i64, ptr %8, align 8, !tbaa !9
  call void @simd_tensor_conjugate(ptr noundef %77, ptr noundef %83, i64 noundef %84)
  br label %85

85:                                               ; preds = %71, %68
  store i32 0, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %86

86:                                               ; preds = %85, %17, %13
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

declare void @simd_tensor_conjugate(ptr noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: 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 = { "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, !10, i64 56}
!12 = !{!"quantum_geometric_tensor_t", !13, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !14, i64 41, !14, i64 42, !13, i64 44, !10, i64 48, !10, i64 56}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !6, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"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 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @llvm.prefetch.p0(ptr nocapture readonly, i32 immarg, i32 immarg, i32 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @geometric_tensor_conjugate(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %31, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 56
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = lshr i64 %7, 10
  %9 = and i64 %7, 1023
  %.not31 = icmp ult i64 %7, 1024
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %10 = getelementptr inbounds i8, ptr %1, i64 24
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  br label %12

._crit_edge:                                      ; preds = %20, %5
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %31, label %23

12:                                               ; preds = %.lr.ph, %20
  %.02430 = phi i64 [ 0, %.lr.ph ], [ %14, %20 ]
  %13 = shl nuw i64 %.02430, 10
  %14 = add nuw nsw i64 %.02430, 1
  %15 = icmp ult i64 %14, %8
  %.pre = load ptr, ptr %11, align 8, !tbaa !13
  %.pre32 = load ptr, ptr %10, align 8, !tbaa !13
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = shl nuw i64 %14, 10
  %18 = getelementptr inbounds %struct.ComplexFloat, ptr %.pre32, i64 %17
  tail call void @llvm.prefetch.p0(ptr nonnull %18, i32 0, i32 3, i32 1)
  %19 = getelementptr inbounds %struct.ComplexFloat, ptr %.pre, i64 %17
  tail call void @llvm.prefetch.p0(ptr nonnull %19, i32 1, i32 3, i32 1)
  br label %20

20:                                               ; preds = %16, %12
  %21 = getelementptr inbounds %struct.ComplexFloat, ptr %.pre, i64 %13
  %22 = getelementptr inbounds %struct.ComplexFloat, ptr %.pre32, i64 %13
  tail call void @simd_tensor_conjugate(ptr noundef %21, ptr noundef %22, i64 noundef 1024) #3
  %exitcond.not = icmp eq i64 %14, %8
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !14

23:                                               ; preds = %._crit_edge
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = and i64 %7, -1024
  %27 = getelementptr inbounds %struct.ComplexFloat, ptr %25, i64 %26
  %28 = getelementptr inbounds i8, ptr %1, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.ComplexFloat, ptr %29, i64 %26
  tail call void @simd_tensor_conjugate(ptr noundef %27, ptr noundef %30, i64 noundef %9) #3
  br label %31

31:                                               ; preds = %._crit_edge, %23, %2
  %.0 = phi i32 [ -1, %2 ], [ 0, %23 ], [ 0, %._crit_edge ]
  ret i32 %.0
}

declare void @simd_tensor_conjugate(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) }
attributes #1 = { 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 #2 = { "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 = !{!6, !11, i64 56}
!6 = !{!"quantum_geometric_tensor_t", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 24, !10, i64 32, !12, i64 40, !12, i64 41, !12, i64 42, !7, i64 44, !11, i64 48, !11, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!6, !10, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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