; LLVM IR from ggml-org/ggml :: src (ggml-opt)

; 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.ggml_opt_result = type <{ i64, %"class.std::vector.0", %"class.std::vector.5", i64, i64, i8, [7 x i8] }>
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl" = type { %"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" }
%"struct.std::_Vector_base<float, std::allocator<float>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: nounwind
declare double @sqrt(double noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @ggml_opt_result_accuracy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ggml_opt_result, ptr %7, i32 0, i32 3
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = icmp sge i64 %9, 0
  br i1 %10, label %11, label %21

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ggml_opt_result, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = sitofp i64 %14 to double
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ggml_opt_result, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !21
  %19 = sitofp i64 %18 to double
  %20 = fdiv double %15, %19
  br label %22

21:                                               ; preds = %3
  br label %22

22:                                               ; preds = %21, %11
  %23 = phi double [ %20, %11 ], [ 0x7FF8000000000000, %21 ]
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store double %23, ptr %24, align 8, !tbaa !22
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  br label %56

28:                                               ; preds = %22
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ggml_opt_result, ptr %29, i32 0, i32 3
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = icmp sge i64 %31, 0
  br i1 %32, label %33, label %52

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ggml_opt_result, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %35, align 8, !tbaa !21
  %37 = icmp sge i64 %36, 2
  br i1 %37, label %38, label %52

38:                                               ; preds = %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load double, ptr %39, align 8, !tbaa !22
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load double, ptr %41, align 8, !tbaa !22
  %43 = fsub double 1.000000e+00, %42
  %44 = fmul double %40, %43
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ggml_opt_result, ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = sub nsw i64 %47, 1
  %49 = sitofp i64 %48 to double
  %50 = fdiv double %44, %49
  %51 = call double @sqrt(double noundef %50) #2
  br label %53

52:                                               ; preds = %33, %28
  br label %53

53:                                               ; preds = %52, %38
  %54 = phi double [ %51, %38 ], [ 0x7FF8000000000000, %52 ]
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  store double %54, ptr %55, align 8, !tbaa !22
  br label %56

56:                                               ; preds = %53, %27
  ret void
}

attributes #0 = { 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 #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !11, i64 56}
!10 = !{!"_ZTS15ggml_opt_result", !11, i64 0, !12, i64 8, !16, i64 32, !11, i64 56, !11, i64 64, !20, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIfSaIfEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"_ZTSSt6vectorIiSaIiEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"bool", !7, i64 0}
!21 = !{!10, !11, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"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 nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local void @ggml_opt_result_accuracy(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, -1
  br i1 %6, label %7, label %.thread

7:                                                ; preds = %3
  %8 = uitofp nneg i64 %5 to double
  %9 = load i64, ptr %0, align 8, !tbaa !20
  %10 = sitofp i64 %9 to double
  %11 = fdiv double %8, %10
  store double %11, ptr %1, align 8, !tbaa !21
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %22, label %12

.thread:                                          ; preds = %3
  store double 0x7FF8000000000000, ptr %1, align 8, !tbaa !21
  %.not13 = icmp eq ptr %2, null
  br i1 %.not13, label %22, label %.thread14

12:                                               ; preds = %7
  %13 = icmp sgt i64 %9, 1
  br i1 %13, label %14, label %.thread14

14:                                               ; preds = %12
  %15 = fsub double 1.000000e+00, %11
  %16 = fmul double %11, %15
  %17 = add nsw i64 %9, -1
  %18 = uitofp nneg i64 %17 to double
  %19 = fdiv double %16, %18
  %20 = tail call double @sqrt(double noundef %19) #2
  br label %.thread14

.thread14:                                        ; preds = %.thread, %12, %14
  %21 = phi double [ %20, %14 ], [ 0x7FF8000000000000, %12 ], [ 0x7FF8000000000000, %.thread ]
  store double %21, ptr %2, align 8, !tbaa !21
  br label %22

22:                                               ; preds = %.thread, %7, %.thread14
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 nofree nounwind willreturn memory(write, argmem: readwrite) 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, !7, i64 56}
!6 = !{!"_ZTS15ggml_opt_result", !7, i64 0, !10, i64 8, !15, i64 32, !7, i64 56, !7, i64 64, !19, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIfSaIfEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIfSaIfEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIfSaIfEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSSt6vectorIiSaIiEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!19 = !{!"bool", !8, i64 0}
!20 = !{!6, !7, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"double", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass