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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @compute_parameter_shift_gradient(ptr noundef, i64 noundef, double 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
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) #1

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

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

22:                                               ; preds = %19
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %25, %22, %19, %5
  store i1 false, ptr %6, align 1
  br label %59

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = call zeroext i1 @compute_parameter_shift_gradient(ptr noundef %30, i64 noundef %31, double noundef 0x3FF921FB54442D18, ptr noundef %12, ptr noundef %14)
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i1 false, ptr %6, align 1
  store i32 1, ptr %16, align 4
  br label %58

34:                                               ; preds = %29
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = call zeroext i1 @compute_parameter_shift_gradient(ptr noundef %35, i64 noundef %36, double noundef 0x3FE921FB54442D18, ptr noundef %13, ptr noundef %15)
  br i1 %37, label %40, label %38

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

40:                                               ; preds = %34
  %41 = load i64, ptr %14, align 8, !tbaa !9
  %42 = load i64, ptr %15, align 8, !tbaa !9
  %43 = icmp ne i64 %41, %42
  br i1 %43, label %44, label %47

44:                                               ; preds = %40
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %45) #3
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %46) #3
  store i1 false, ptr %6, align 1
  store i32 1, ptr %16, align 4
  br label %58

47:                                               ; preds = %40
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %48, ptr %49, align 8, !tbaa !5
  %50 = load i64, ptr %15, align 8, !tbaa !9
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %50, ptr %51, align 8, !tbaa !9
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = load i64, ptr %14, align 8, !tbaa !9
  %55 = call double @estimate_gradient_error(ptr noundef %52, ptr noundef %53, i64 noundef %54)
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  store double %55, ptr %56, align 8, !tbaa !11
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %57) #3
  store i1 true, ptr %6, align 1
  store i32 1, ptr %16, align 4
  br label %58

58:                                               ; preds = %47, %44, %38, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %59

59:                                               ; preds = %58, %28
  %60 = load i1, ptr %6, align 1
  ret i1 %60
}

; Function Attrs: nounwind uwtable
declare hidden double @estimate_gradient_error(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 "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, !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, !12, i64 0}
!12 = !{!"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: nounwind uwtable
declare dso_local zeroext i1 @compute_parameter_shift_gradient(ptr noundef, i64 noundef, double 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 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) #1

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @compute_gradient_with_error(ptr noundef %0, i64 noundef %1, ptr noundef writeonly %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %11 = insertelement <4 x ptr> %10, ptr %2, i64 1
  %12 = insertelement <4 x ptr> %11, ptr %3, i64 2
  %13 = insertelement <4 x ptr> %12, ptr %4, i64 3
  %14 = icmp eq <4 x ptr> %13, zeroinitializer
  %15 = bitcast <4 x i1> %14 to i4
  %16 = icmp eq i4 %15, 0
  br i1 %16, label %17, label %31

17:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  %18 = call zeroext i1 @compute_parameter_shift_gradient(ptr noundef nonnull %0, i64 noundef %1, double noundef 0x3FF921FB54442D18, ptr noundef nonnull %6, ptr noundef nonnull %8)
  br i1 %18, label %19, label %30

19:                                               ; preds = %17
  %20 = call zeroext i1 @compute_parameter_shift_gradient(ptr noundef nonnull %0, i64 noundef %1, double noundef 0x3FE921FB54442D18, ptr noundef nonnull %7, ptr noundef nonnull %9)
  br i1 %20, label %21, label %.sink.split

21:                                               ; preds = %19
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = load i64, ptr %9, align 8, !tbaa !5
  %.not = icmp eq i64 %22, %23
  br i1 %.not, label %26, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %25) #3
  br label %.sink.split

26:                                               ; preds = %21
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %27, ptr %2, align 8, !tbaa !9
  store i64 %22, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = call double @estimate_gradient_error(ptr noundef %28, ptr noundef %27, i64 noundef %22)
  store double %29, ptr %3, align 8, !tbaa !11
  br label %.sink.split

.sink.split:                                      ; preds = %19, %24, %26
  %.sink.in = phi ptr [ %6, %26 ], [ %7, %24 ], [ %6, %19 ]
  %.0.ph = phi i1 [ true, %26 ], [ false, %24 ], [ false, %19 ]
  %.sink = load ptr, ptr %.sink.in, align 8, !tbaa !9
  call void @free(ptr noundef %.sink) #3
  br label %30

30:                                               ; preds = %.sink.split, %17
  %.0 = phi i1 [ false, %17 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  br label %31

31:                                               ; preds = %5, %30
  %.1 = phi i1 [ %.0, %30 ], [ false, %5 ]
  ret i1 %.1
}

; Function Attrs: nounwind uwtable
declare hidden double @estimate_gradient_error(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 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 = { 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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass