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

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

@.str.12 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [43 x i8], align 1

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; 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 zeroext i1 @measure_quantum_state(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [1 x i64], align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

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

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

22:                                               ; preds = %19, %16, %4
  call void @set_error(ptr noundef @.str.12)
  store i1 false, ptr %5, align 1
  br label %73

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.quantum_geometric_tensor_network, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds [1 x i64], ptr %11, i64 0, i64 0
  %28 = call zeroext i1 @contract_full_network(ptr noundef %26, ptr noundef %10, ptr noundef %27, ptr noundef %12)
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  call void @set_error(ptr noundef @.str.13)
  store i1 false, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %72

30:                                               ; preds = %23
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ComplexFloat, ptr %31, i64 0
  %33 = getelementptr inbounds %struct.ComplexFloat, ptr %32, i32 0, i32 0
  %34 = load float, ptr %33, align 4, !tbaa !14
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ComplexFloat, ptr %35, i64 0
  %37 = getelementptr inbounds %struct.ComplexFloat, ptr %36, i32 0, i32 0
  %38 = load float, ptr %37, align 4, !tbaa !14
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ComplexFloat, ptr %39, i64 0
  %41 = getelementptr inbounds %struct.ComplexFloat, ptr %40, i32 0, i32 1
  %42 = load float, ptr %41, align 4, !tbaa !17
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ComplexFloat, ptr %43, i64 0
  %45 = getelementptr inbounds %struct.ComplexFloat, ptr %44, i32 0, i32 1
  %46 = load float, ptr %45, align 4, !tbaa !17
  %47 = fmul float %42, %46
  %48 = call float @llvm.fmuladd.f32(float %34, float %38, float %47)
  %49 = fpext float %48 to double
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  store double %49, ptr %50, align 8, !tbaa !18
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ComplexFloat, ptr %51, i64 1
  %53 = getelementptr inbounds %struct.ComplexFloat, ptr %52, i32 0, i32 0
  %54 = load float, ptr %53, align 4, !tbaa !14
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ComplexFloat, ptr %55, i64 1
  %57 = getelementptr inbounds %struct.ComplexFloat, ptr %56, i32 0, i32 0
  %58 = load float, ptr %57, align 4, !tbaa !14
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ComplexFloat, ptr %59, i64 1
  %61 = getelementptr inbounds %struct.ComplexFloat, ptr %60, i32 0, i32 1
  %62 = load float, ptr %61, align 4, !tbaa !17
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ComplexFloat, ptr %63, i64 1
  %65 = getelementptr inbounds %struct.ComplexFloat, ptr %64, i32 0, i32 1
  %66 = load float, ptr %65, align 4, !tbaa !17
  %67 = fmul float %62, %66
  %68 = call float @llvm.fmuladd.f32(float %54, float %58, float %67)
  %69 = fpext float %68 to double
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  store double %69, ptr %70, align 8, !tbaa !18
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %71) #5
  store i1 true, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %72

72:                                               ; preds = %30, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %73

73:                                               ; preds = %72, %22
  %74 = load i1, ptr %5, align 1
  ret i1 %74
}

declare zeroext i1 @contract_full_network(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!12, !6, i64 0}
!12 = !{!"quantum_geometric_tensor_network", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !13, i64 33}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 4}
!16 = !{!"float", !7, i64 0}
!17 = !{!15, !16, i64 4}
!18 = !{!19, !19, i64 0}
!19 = !{!"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"

@.str.12 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [43 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; 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 noundef zeroext i1 @measure_quantum_state(ptr noundef readonly %0, i64 noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca ptr, align 8
  %6 = alloca [1 x i64], align 8
  %7 = alloca i64, align 8
  %8 = icmp ne ptr %0, null
  %9 = icmp ne ptr %2, null
  %or.cond = and i1 %8, %9
  %10 = icmp ne ptr %3, null
  %or.cond3 = and i1 %or.cond, %10
  br i1 %or.cond3, label %12, label %11

11:                                               ; preds = %4
  tail call void @set_error(ptr noundef nonnull @.str.12)
  br label %32

12:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = call zeroext i1 @contract_full_network(ptr noundef %13, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %7) #5
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @set_error(ptr noundef nonnull @.str.13)
  br label %31

16:                                               ; preds = %12
  %17 = load ptr, ptr %5, align 8, !tbaa !12
  %18 = load float, ptr %17, align 4, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %17, i64 4
  %20 = load float, ptr %19, align 4, !tbaa !16
  %21 = fmul float %20, %20
  %22 = call float @llvm.fmuladd.f32(float %18, float %18, float %21)
  %23 = fpext float %22 to double
  store double %23, ptr %2, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %17, i64 8
  %25 = load float, ptr %24, align 4, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %17, i64 12
  %27 = load float, ptr %26, align 4, !tbaa !16
  %28 = fmul float %27, %27
  %29 = call float @llvm.fmuladd.f32(float %25, float %25, float %28)
  %30 = fpext float %29 to double
  store double %30, ptr %3, align 8, !tbaa !17
  call void @free(ptr noundef %17) #5
  br label %31

31:                                               ; preds = %16, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %32

32:                                               ; preds = %31, %11
  %.1 = phi i1 [ %14, %31 ], [ false, %11 ]
  ret i1 %.1
}

declare zeroext i1 @contract_full_network(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"quantum_geometric_tensor_network", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !11, i64 33}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 4}
!15 = !{!"float", !8, i64 0}
!16 = !{!14, !15, i64 4}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}


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