; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/sqrt (libsqrt)

; 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 float @fabs_float(float noundef) #0

; Function Attrs: nounwind uwtable
define dso_local float @sqrtfcn(float noundef %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store float %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %9 = load float, ptr %2, align 4, !tbaa !5
  %10 = fdiv float %9, 1.000000e+01
  store float %10, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 1.000000e-05, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  %11 = load float, ptr %2, align 4, !tbaa !5
  %12 = fcmp oeq float %11, 0.000000e+00
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store float 0.000000e+00, ptr %3, align 4, !tbaa !5
  br label %56

14:                                               ; preds = %1
  store i32 1, ptr %7, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %52, %14
  %16 = load i32, ptr %7, align 4, !tbaa !11
  %17 = icmp slt i32 %16, 20
  br i1 %17, label %18, label %55

18:                                               ; preds = %15
  %19 = load i32, ptr %8, align 4, !tbaa !11
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %50, label %21

21:                                               ; preds = %18
  %22 = load float, ptr %2, align 4, !tbaa !5
  %23 = load float, ptr %3, align 4, !tbaa !5
  %24 = load float, ptr %3, align 4, !tbaa !5
  %25 = fneg float %23
  %26 = call float @llvm.fmuladd.f32(float %25, float %24, float %22)
  %27 = fpext float %26 to double
  %28 = load float, ptr %3, align 4, !tbaa !5
  %29 = fpext float %28 to double
  %30 = fmul double 2.000000e+00, %29
  %31 = fdiv double %27, %30
  %32 = fptrunc double %31 to float
  store float %32, ptr %4, align 4, !tbaa !5
  %33 = load float, ptr %3, align 4, !tbaa !5
  %34 = load float, ptr %4, align 4, !tbaa !5
  %35 = fadd float %33, %34
  store float %35, ptr %3, align 4, !tbaa !5
  %36 = load float, ptr %2, align 4, !tbaa !5
  %37 = load float, ptr %3, align 4, !tbaa !5
  %38 = load float, ptr %3, align 4, !tbaa !5
  %39 = fneg float %37
  %40 = call float @llvm.fmuladd.f32(float %39, float %38, float %36)
  %41 = fpext float %40 to double
  store double %41, ptr %5, align 8, !tbaa !9
  %42 = load double, ptr %5, align 8, !tbaa !9
  %43 = fptrunc double %42 to float
  %44 = call float @fabs_float(float noundef %43)
  %45 = fpext float %44 to double
  %46 = load double, ptr %6, align 8, !tbaa !9
  %47 = fcmp ole double %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %21
  store i32 1, ptr %8, align 4, !tbaa !11
  br label %49

49:                                               ; preds = %48, %21
  br label %51

50:                                               ; preds = %18
  br label %51

51:                                               ; preds = %50, %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %7, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !11
  br label %15, !llvm.loop !13

55:                                               ; preds = %15
  br label %56

56:                                               ; preds = %55, %13
  %57 = load float, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret float %57
}

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

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

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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 float @fabs_float(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @sqrtfcn(float noundef %0) local_unnamed_addr #0 {
  %2 = fcmp oeq float %0, 0.000000e+00
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = fdiv float %0, 1.000000e+01
  br label %5

5:                                                ; preds = %3, %21
  %.022 = phi i32 [ 0, %3 ], [ %.1, %21 ]
  %.01621 = phi i32 [ 1, %3 ], [ %22, %21 ]
  %.01720 = phi float [ %4, %3 ], [ %.118, %21 ]
  %.not = icmp eq i32 %.022, 0
  br i1 %.not, label %6, label %21

6:                                                ; preds = %5
  %7 = fneg float %.01720
  %8 = tail call float @llvm.fmuladd.f32(float %7, float %.01720, float %0)
  %9 = fpext float %8 to double
  %10 = fpext float %.01720 to double
  %11 = fmul double %10, 2.000000e+00
  %12 = fdiv double %9, %11
  %13 = fptrunc double %12 to float
  %14 = fadd float %.01720, %13
  %15 = fneg float %14
  %16 = tail call float @llvm.fmuladd.f32(float %15, float %14, float %0)
  %17 = tail call float @fabs_float(float noundef %16)
  %18 = fpext float %17 to double
  %19 = fcmp ugt double %18, 1.000000e-05
  br i1 %19, label %21, label %20

20:                                               ; preds = %6
  br label %21

21:                                               ; preds = %20, %6, %5
  %.118 = phi float [ %.01720, %5 ], [ %14, %20 ], [ %14, %6 ]
  %.1 = phi i32 [ 1, %5 ], [ 1, %20 ], [ 0, %6 ]
  %22 = add nuw nsw i32 %.01621, 1
  %exitcond.not = icmp eq i32 %22, 20
  br i1 %exitcond.not, label %.loopexit, label %5, !llvm.loop !5

.loopexit:                                        ; preds = %21, %1
  %.2 = phi float [ 0.000000e+00, %1 ], [ %.118, %21 ]
  ret float %.2
}

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

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 speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass