; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/util.ll (ZN3qOS4util13stringToFloatEPKc)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3qOS4util13stringToFloatEPKc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  store i8 0, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call noundef ptr @_ZL18discardWhitespacesPKcm(ptr noundef %8, i64 noundef 512) #4
  store ptr %9, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call noundef ptr @_ZL12checkStrSignPKcPi(ptr noundef %10, ptr noundef %6) #4
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !13
  %13 = sitofp i32 %12 to double
  store double %13, ptr %4, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %43, %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !15
  store i8 %16, ptr %7, align 1, !tbaa !15
  %17 = zext i8 %16 to i32
  %18 = icmp ne i32 0, %17
  br i1 %18, label %19, label %46

19:                                               ; preds = %14
  %20 = load i8, ptr %7, align 1, !tbaa !15
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 46, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  store i8 1, ptr %5, align 1, !tbaa !11
  br label %43

24:                                               ; preds = %19
  %25 = load i8, ptr %7, align 1, !tbaa !15
  %26 = sext i8 %25 to i32
  %27 = call i32 @isdigit(i32 noundef %26) #5
  %28 = icmp ne i32 0, %27
  br i1 %28, label %29, label %41

29:                                               ; preds = %24
  %30 = load i8, ptr %5, align 1, !tbaa !11, !range !16, !noundef !17
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load double, ptr %4, align 8, !tbaa !9
  %34 = fmul double %33, 1.000000e-01
  store double %34, ptr %4, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %32, %29
  %36 = load double, ptr %3, align 8, !tbaa !9
  %37 = load i8, ptr %7, align 1, !tbaa !15
  %38 = sitofp i8 %37 to double
  %39 = call double @llvm.fmuladd.f64(double %36, double 1.000000e+01, double %38)
  %40 = fsub double %39, 4.800000e+01
  store double %40, ptr %3, align 8, !tbaa !9
  br label %42

41:                                               ; preds = %24
  br label %46

42:                                               ; preds = %35
  br label %43

43:                                               ; preds = %42, %23
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i32 1
  store ptr %45, ptr %2, align 8, !tbaa !5
  br label %14, !llvm.loop !18

46:                                               ; preds = %41, %14
  %47 = load double, ptr %3, align 8, !tbaa !9
  %48 = load double, ptr %4, align 8, !tbaa !9
  %49 = fmul double %47, %48
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %49
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL18discardWhitespacesPKcm(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL12checkStrSignPKcPi(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isdigit(i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 willreturn memory(read) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3qOS4util13stringToFloatEPKc(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  %3 = tail call noundef ptr @_ZL18discardWhitespacesPKcm(ptr noundef %0, i64 noundef 512) #3
  %4 = call noundef ptr @_ZL12checkStrSignPKcPi(ptr noundef %3, ptr noundef nonnull %2) #3
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = sitofp i32 %5 to double
  br label %7

7:                                                ; preds = %16, %1
  %.014 = phi double [ 0.000000e+00, %1 ], [ %.115, %16 ]
  %.012 = phi double [ %6, %1 ], [ %.2, %16 ]
  %.011 = phi i1 [ false, %1 ], [ %.1, %16 ]
  %.0 = phi ptr [ %4, %1 ], [ %17, %16 ]
  %8 = load i8, ptr %.0, align 1, !tbaa !9
  switch i8 %8, label %9 [
    i8 0, label %18
    i8 46, label %16
  ]

9:                                                ; preds = %7
  %10 = sext i8 %8 to i32
  %isdigittmp = add nsw i32 %10, -48
  %isdigit = icmp ult i32 %isdigittmp, 10
  br i1 %isdigit, label %11, label %18

11:                                               ; preds = %9
  %12 = fmul double %.012, 1.000000e-01
  %.113 = select i1 %.011, double %12, double %.012
  %13 = sitofp i8 %8 to double
  %14 = call double @llvm.fmuladd.f64(double %.014, double 1.000000e+01, double %13)
  %15 = fadd double %14, -4.800000e+01
  br label %16

16:                                               ; preds = %7, %11
  %.115 = phi double [ %15, %11 ], [ %.014, %7 ]
  %.2 = phi double [ %.113, %11 ], [ %.012, %7 ]
  %.1 = phi i1 [ %.011, %11 ], [ true, %7 ]
  %17 = getelementptr inbounds i8, ptr %.0, i64 1
  br label %7, !llvm.loop !10

18:                                               ; preds = %7, %9
  %19 = fmul double %.014, %.012
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret double %19
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL18discardWhitespacesPKcm(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL12checkStrSignPKcPi(ptr noundef, ptr noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass