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

; 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 }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @compute_quantum_gradient(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; 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 @compute_quantum_natural_gradient(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %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 i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  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
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %24

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

21:                                               ; preds = %18
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %21, %18, %4
  store i1 false, ptr %5, align 1
  br label %102

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = call zeroext i1 @compute_quantum_gradient(ptr noundef %26, i64 noundef %27, ptr noundef %10, ptr noundef %11)
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %101

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = mul i64 %31, %32
  %34 = mul i64 %33, 8
  %35 = call noalias ptr @malloc(i64 noundef %34) #6
  store ptr %35, ptr %13, align 8, !tbaa !5
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %40, label %38

38:                                               ; preds = %30
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %39) #5
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %100

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

41:                                               ; preds = %74, %40
  %42 = load i64, ptr %14, align 8, !tbaa !9
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = icmp ult i64 %42, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 2, ptr %12, align 4
  br label %77

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

47:                                               ; preds = %68, %46
  %48 = load i64, ptr %15, align 8, !tbaa !9
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = icmp ult i64 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 5, ptr %12, align 4
  br label %71

52:                                               ; preds = %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %14, align 8, !tbaa !9
  %55 = load i64, ptr %15, align 8, !tbaa !9
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load i64, ptr %14, align 8, !tbaa !9
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = mul i64 %57, %58
  %60 = load i64, ptr %15, align 8, !tbaa !9
  %61 = add i64 %59, %60
  %62 = getelementptr inbounds %struct.ComplexFloat, ptr %56, i64 %61
  %63 = call zeroext i1 @compute_quantum_geometric_tensor(ptr noundef %53, i64 noundef %54, i64 noundef %55, ptr noundef %62)
  br i1 %63, label %67, label %64

64:                                               ; preds = %52
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %65) #5
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %66) #5
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %71

67:                                               ; preds = %52
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %15, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %15, align 8, !tbaa !9
  br label %47, !llvm.loop !11

71:                                               ; preds = %64, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  %72 = load i32, ptr %12, align 4
  switch i32 %72, label %77 [
    i32 5, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load i64, ptr %14, align 8, !tbaa !9
  %76 = add i64 %75, 1
  store i64 %76, ptr %14, align 8, !tbaa !9
  br label %41, !llvm.loop !13

77:                                               ; preds = %71, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %78 = load i32, ptr %12, align 4
  switch i32 %78, label %100 [
    i32 2, label %79
  ]

79:                                               ; preds = %77
  %80 = load i64, ptr %11, align 8, !tbaa !9
  %81 = mul i64 %80, 8
  %82 = call noalias ptr @malloc(i64 noundef %81) #6
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %82, ptr %83, align 8, !tbaa !5
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = icmp ne ptr %85, null
  br i1 %86, label %90, label %87

87:                                               ; preds = %79
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %88) #5
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %89) #5
  store i1 false, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %100

90:                                               ; preds = %79
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  %95 = load i64, ptr %11, align 8, !tbaa !9
  call void @compute_natural_gradient(ptr noundef null, ptr noundef %91, ptr noundef %92, ptr noundef %94, i64 noundef %95)
  %96 = load i64, ptr %11, align 8, !tbaa !9
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %96, ptr %97, align 8, !tbaa !9
  %98 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %98) #5
  %99 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %99) #5
  store i1 true, ptr %5, align 1
  store i32 1, ptr %12, align 4
  br label %100

100:                                              ; preds = %90, %87, %77, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %101

101:                                              ; preds = %100, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %102

102:                                              ; preds = %101, %24
  %103 = load i1, ptr %5, align 1
  ret i1 %103
}

declare zeroext i1 @compute_quantum_geometric_tensor(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { 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 #4 = { "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 }
attributes #6 = { nounwind allocsize(0) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: nounwind uwtable
declare dso_local zeroext i1 @compute_quantum_gradient(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress 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 noundef zeroext i1 @compute_quantum_natural_gradient(ptr noundef %0, i64 noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = icmp ne ptr %0, null
  %8 = icmp ne ptr %2, null
  %or.cond = and i1 %7, %8
  %9 = icmp ne ptr %3, null
  %or.cond4 = and i1 %or.cond, %9
  br i1 %or.cond4, label %10, label %40

10:                                               ; 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
  %11 = call zeroext i1 @compute_quantum_gradient(ptr noundef nonnull %0, i64 noundef %1, ptr noundef nonnull %5, ptr noundef nonnull %6)
  br i1 %11, label %12, label %39

12:                                               ; preds = %10
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = shl i64 %13, 3
  %15 = mul i64 %14, %13
  %16 = call noalias ptr @malloc(i64 noundef %15) #6
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %17, label %.preheader45

.preheader45:                                     ; preds = %12
  %.not4148.not = icmp eq i64 %13, 0
  br i1 %.not4148.not, label %.critedge44, label %.lr.ph.preheader

17:                                               ; preds = %12
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  br label %.sink.split

.lr.ph.preheader:                                 ; preds = %.preheader45, %.critedge
  %19 = phi i64 [ %22, %.critedge ], [ %13, %.preheader45 ]
  %.03049 = phi i64 [ %28, %.critedge ], [ 0, %.preheader45 ]
  br label %.lr.ph

20:                                               ; preds = %.lr.ph
  %21 = add nuw i64 %.047, 1
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %.not40 = icmp ult i64 %21, %22
  br i1 %.not40, label %.lr.ph, label %.critedge, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %23 = phi i64 [ %22, %20 ], [ %19, %.lr.ph.preheader ]
  %.047 = phi i64 [ %21, %20 ], [ 0, %.lr.ph.preheader ]
  %24 = mul i64 %23, %.03049
  %25 = getelementptr %struct.ComplexFloat, ptr %16, i64 %24
  %26 = getelementptr %struct.ComplexFloat, ptr %25, i64 %.047
  %27 = call zeroext i1 @compute_quantum_geometric_tensor(ptr noundef nonnull %0, i64 noundef %.03049, i64 noundef %.047, ptr noundef %26) #5
  br i1 %27, label %20, label %29

.critedge:                                        ; preds = %20
  %28 = add nuw i64 %.03049, 1
  %.not41 = icmp ult i64 %28, %22
  br i1 %.not41, label %.lr.ph.preheader, label %.critedge44, !llvm.loop !13

29:                                               ; preds = %.lr.ph
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %30) #5
  br label %.sink.split

.critedge44:                                      ; preds = %.critedge, %.preheader45
  %31 = phi i64 [ 0, %.preheader45 ], [ %22, %.critedge ]
  %32 = shl i64 %31, 3
  %33 = call noalias ptr @malloc(i64 noundef %32) #6
  store ptr %33, ptr %2, align 8, !tbaa !9
  %.not42 = icmp eq ptr %33, null
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  br i1 %.not42, label %35, label %36

35:                                               ; preds = %.critedge44
  call void @free(ptr noundef %34) #5
  br label %.sink.split

36:                                               ; preds = %.critedge44
  call void @compute_natural_gradient(ptr noundef null, ptr noundef nonnull %16, ptr noundef %34, ptr noundef nonnull %33, i64 noundef %31)
  %37 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %37, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  call void @free(ptr noundef %38) #5
  br label %.sink.split

.sink.split:                                      ; preds = %36, %35, %17, %29
  %.sink = phi ptr [ %16, %29 ], [ %18, %17 ], [ %16, %35 ], [ %16, %36 ]
  %.4.ph = phi i1 [ false, %29 ], [ false, %17 ], [ false, %35 ], [ true, %36 ]
  call void @free(ptr noundef %.sink) #5
  br label %39

39:                                               ; preds = %.sink.split, %10
  %.4 = phi i1 [ false, %10 ], [ %.4.ph, %.sink.split ]
  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 %40

40:                                               ; preds = %4, %39
  %.5 = phi i1 [ %.4, %39 ], [ false, %4 ]
  ret i1 %.5
}

declare zeroext i1 @compute_quantum_geometric_tensor(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { 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 #4 = { "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 }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12, !14}
!14 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass