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

; 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_state_t = type { i32, i64, i64, ptr, ptr, ptr, ptr, i8, i32 }

; 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: nounwind uwtable
define dso_local i32 @calculate_curvature(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca { double, double }, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %20

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

20:                                               ; preds = %17, %6
  store i32 -1, ptr %7, align 4
  br label %59

21:                                               ; preds = %17
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.quantum_geometric_state_t, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = icmp uge i64 %22, %25
  br i1 %26, label %45, label %27

27:                                               ; preds = %21
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.quantum_geometric_state_t, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = icmp uge i64 %28, %31
  br i1 %32, label %45, label %33

33:                                               ; preds = %27
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.quantum_geometric_state_t, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = icmp uge i64 %34, %37
  br i1 %38, label %45, label %39

39:                                               ; preds = %33
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.quantum_geometric_state_t, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = icmp uge i64 %40, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %39, %33, %27, %21
  store i32 -22, ptr %7, align 4
  br label %59

46:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #2
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.quantum_geometric_state_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 = load i64, ptr %10, align 8, !tbaa !9
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = load i64, ptr %12, align 8, !tbaa !9
  call void @compute_quantum_curvature_cpu(ptr noundef %49, ptr noundef %14, i64 noundef %50, i64 noundef %51, i64 noundef %52, i64 noundef %53)
  %54 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %55 = load double, ptr %54, align 8
  %56 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %57 = load double, ptr %56, align 8
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  store double %55, ptr %58, align 8, !tbaa !16
  store i32 0, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #2
  br label %59

59:                                               ; preds = %46, %45, %20
  %60 = load i32, ptr %7, align 4
  ret i32 %60
}

; Function Attrs: nounwind uwtable
declare hidden void @compute_quantum_curvature_cpu(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: 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 = { 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 8}
!12 = !{!"quantum_geometric_state_t", !13, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !14, i64 56, !13, i64 60}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !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"

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -22, 1) i32 @calculate_curvature(ptr noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef writeonly %5) local_unnamed_addr #1 {
  %7 = alloca { double, double }, align 8
  %8 = icmp ne ptr %0, null
  %9 = icmp ne ptr %5, null
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %10, label %17

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %.not = icmp ugt i64 %12, %1
  %.not24 = icmp ugt i64 %12, %2
  %or.cond27 = and i1 %.not, %.not24
  %.not25 = icmp ugt i64 %12, %3
  %or.cond28 = and i1 %.not25, %or.cond27
  %.not26 = icmp ugt i64 %12, %4
  %or.cond29 = and i1 %.not26, %or.cond28
  br i1 %or.cond29, label %13, label %17

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #2
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  call void @compute_quantum_curvature_cpu(ptr noundef %15, ptr noundef nonnull %7, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4)
  %16 = load double, ptr %7, align 8
  store double %16, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #2
  br label %17

17:                                               ; preds = %10, %6, %13
  %.0 = phi i32 [ 0, %13 ], [ -1, %6 ], [ -22, %10 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @compute_quantum_curvature_cpu(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: 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 = { 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, !10, i64 8}
!6 = !{!"quantum_geometric_state_t", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !12, i64 56, !7, i64 60}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!6, !11, i64 24}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}


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