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

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; 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
declare dso_local noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS4util13floatToStringEdPch(double noundef %0, ptr noundef %1, i8 noundef zeroext %2) #1 personality ptr @__gxx_personality_v0 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %106

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 8 %4, i64 4, i1 false)
  %14 = load i32, ptr %7, align 4, !tbaa !12
  %15 = and i32 %14, 2147483647
  store i32 %15, ptr %7, align 4, !tbaa !12
  %16 = load i32, ptr %7, align 4, !tbaa !12
  %17 = icmp eq i32 0, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef %19, ptr noundef @.str, i64 noundef 4) #5
  br label %105

21:                                               ; preds = %13
  %22 = load i32, ptr %7, align 4, !tbaa !12
  %23 = icmp ult i32 %22, 2139095040
  br i1 %23, label %24, label %87

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !14
  %25 = load i8, ptr %6, align 1, !tbaa !11
  %26 = invoke noundef zeroext i8 @_ZN3qOS9clipUpperIhEET_S1_S1_(i8 noundef zeroext %25, i8 noundef zeroext 10)
          to label %27 unwind label %108

27:                                               ; preds = %24
  store i8 %26, ptr %6, align 1, !tbaa !11
  %28 = load double, ptr %4, align 8, !tbaa !5
  %29 = fcmp olt double %28, 0.000000e+00
  br i1 %29, label %30, label %37

30:                                               ; preds = %27
  %31 = load double, ptr %4, align 8, !tbaa !5
  %32 = fneg double %31
  store double %32, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = load i64, ptr %9, align 8, !tbaa !14
  %35 = add i64 %34, 1
  store i64 %35, ptr %9, align 8, !tbaa !14
  %36 = getelementptr inbounds i8, ptr %33, i64 %34
  store i8 45, ptr %36, align 1, !tbaa !11
  br label %37

37:                                               ; preds = %30, %27
  %38 = load double, ptr %4, align 8, !tbaa !5
  %39 = fptoui double %38 to i32
  store i32 %39, ptr %8, align 4, !tbaa !12
  %40 = load i32, ptr %8, align 4, !tbaa !12
  %41 = uitofp i32 %40 to double
  %42 = load double, ptr %4, align 8, !tbaa !5
  %43 = fsub double %42, %41
  store double %43, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !12
  %45 = zext i32 %44 to i64
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = load i64, ptr %9, align 8, !tbaa !14
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = call noundef i64 @_ZL9xBaseUtoAmPch(i64 noundef %45, ptr noundef %48, i8 noundef zeroext 10) #5
  %50 = load i64, ptr %9, align 8, !tbaa !14
  %51 = add i64 %50, %49
  store i64 %51, ptr %9, align 8, !tbaa !14
  %52 = load i8, ptr %6, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = icmp ugt i32 %53, 0
  br i1 %54, label %55, label %83

55:                                               ; preds = %37
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = load i64, ptr %9, align 8, !tbaa !14
  %58 = add i64 %57, 1
  store i64 %58, ptr %9, align 8, !tbaa !14
  %59 = getelementptr inbounds i8, ptr %56, i64 %57
  store i8 46, ptr %59, align 1, !tbaa !11
  br label %60

60:                                               ; preds = %65, %55
  %61 = load i8, ptr %6, align 1, !tbaa !11
  %62 = add i8 %61, -1
  store i8 %62, ptr %6, align 1, !tbaa !11
  %63 = zext i8 %61 to i32
  %64 = icmp ne i32 0, %63
  br i1 %64, label %65, label %82

65:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #5
  %66 = load double, ptr %4, align 8, !tbaa !5
  %67 = fmul double %66, 1.000000e+01
  store double %67, ptr %4, align 8, !tbaa !5
  %68 = load double, ptr %4, align 8, !tbaa !5
  %69 = fptosi double %68 to i8
  store i8 %69, ptr %10, align 1, !tbaa !11
  %70 = load i8, ptr %10, align 1, !tbaa !11
  %71 = zext i8 %70 to i32
  %72 = add nsw i32 %71, 48
  %73 = trunc i32 %72 to i8
  %74 = load ptr, ptr %5, align 8, !tbaa !9
  %75 = load i64, ptr %9, align 8, !tbaa !14
  %76 = add i64 %75, 1
  store i64 %76, ptr %9, align 8, !tbaa !14
  %77 = getelementptr inbounds i8, ptr %74, i64 %75
  store i8 %73, ptr %77, align 1, !tbaa !11
  %78 = load i8, ptr %10, align 1, !tbaa !11
  %79 = sitofp i8 %78 to double
  %80 = load double, ptr %4, align 8, !tbaa !5
  %81 = fsub double %80, %79
  store double %81, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  br label %60, !llvm.loop !16

82:                                               ; preds = %60
  br label %83

83:                                               ; preds = %82, %37
  %84 = load ptr, ptr %5, align 8, !tbaa !9
  %85 = load i64, ptr %9, align 8, !tbaa !14
  %86 = getelementptr inbounds i8, ptr %84, i64 %85
  store i8 0, ptr %86, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %104

87:                                               ; preds = %21
  %88 = load i32, ptr %7, align 4, !tbaa !12
  %89 = icmp eq i32 2139095040, %88
  br i1 %89, label %90, label %100

90:                                               ; preds = %87
  %91 = load double, ptr %4, align 8, !tbaa !5
  %92 = fcmp ogt double %91, 0.000000e+00
  %93 = zext i1 %92 to i64
  %94 = select i1 %92, i8 43, i8 45
  %95 = load ptr, ptr %5, align 8, !tbaa !9
  %96 = getelementptr inbounds i8, ptr %95, i64 0
  store i8 %94, ptr %96, align 1, !tbaa !11
  %97 = load ptr, ptr %5, align 8, !tbaa !9
  %98 = getelementptr inbounds i8, ptr %97, i64 1
  %99 = call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef %98, ptr noundef @.str.1, i64 noundef 4) #5
  br label %103

100:                                              ; preds = %87
  %101 = load ptr, ptr %5, align 8, !tbaa !9
  %102 = call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef %101, ptr noundef @.str.2, i64 noundef 4) #5
  br label %103

103:                                              ; preds = %100, %90
  br label %104

104:                                              ; preds = %103, %83
  br label %105

105:                                              ; preds = %104, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %106

106:                                              ; preds = %105, %3
  %107 = load ptr, ptr %5, align 8, !tbaa !9
  ret ptr %107

108:                                              ; preds = %24
  %109 = landingpad { ptr, i32 }
          catch ptr null
  %110 = extractvalue { ptr, i32 } %109, 0
  call void @__clang_call_terminate(ptr %110) #6
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN3qOS9clipUpperIhEET_S1_S1_(i8 noundef zeroext, i8 noundef zeroext) #4

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noinline noreturn nounwind uwtable "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 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN3qOS4util13floatToStringEdPch(double noundef %0, ptr noundef returned %1, i8 noundef zeroext %2) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %58, label %4

4:                                                ; preds = %3
  %5 = bitcast double %0 to i64
  %.0.extract.trunc = trunc i64 %5 to i32
  %6 = and i32 %.0.extract.trunc, 2147483647
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = tail call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef nonnull %1, ptr noundef nonnull @.str, i64 noundef 4) #2
  br label %58

10:                                               ; preds = %4
  %11 = icmp ult i32 %6, 2139095040
  br i1 %11, label %12, label %49

12:                                               ; preds = %10
  %13 = tail call noundef zeroext i8 @_ZN3qOS9clipUpperIhEET_S1_S1_(i8 noundef zeroext %2, i8 noundef zeroext 10)
  %14 = fcmp olt double %0, 0.000000e+00
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  %16 = fneg double %0
  store i8 45, ptr %1, align 1, !tbaa !5
  br label %17

17:                                               ; preds = %15, %12
  %.036 = phi i64 [ 1, %15 ], [ 0, %12 ]
  %.0 = phi double [ %16, %15 ], [ %0, %12 ]
  %18 = fptoui double %.0 to i32
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %1, i64 %.036
  %21 = tail call noundef i64 @_ZL9xBaseUtoAmPch(i64 noundef %19, ptr noundef nonnull %20, i8 noundef zeroext 10) #2
  %22 = add i64 %21, %.036
  %.not43 = icmp eq i8 %13, 0
  br i1 %.not43, label %.loopexit, label %23

23:                                               ; preds = %17
  %24 = uitofp i32 %18 to double
  %25 = fsub double %.0, %24
  %26 = getelementptr inbounds i8, ptr %1, i64 %22
  store i8 46, ptr %26, align 1, !tbaa !5
  %.13745 = add i64 %22, 1
  %xtraiter = and i8 %13, 1
  %lcmp.mod.not = icmp eq i8 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %23
  %27 = add nsw i8 %13, -1
  %28 = fmul double %25, 1.000000e+01
  %29 = fptosi double %28 to i8
  %30 = add i8 %29, 48
  %31 = getelementptr inbounds i8, ptr %1, i64 %.13745
  store i8 %30, ptr %31, align 1, !tbaa !5
  %32 = sitofp i8 %29 to double
  %33 = fsub double %28, %32
  %.137.prol = add i64 %22, 2
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %23
  %.137.lcssa.unr = phi i64 [ poison, %23 ], [ %.137.prol, %.prol.loopexit.unr-lcssa ]
  %.13748.unr = phi i64 [ %.13745, %23 ], [ %.137.prol, %.prol.loopexit.unr-lcssa ]
  %.147.unr = phi double [ %25, %23 ], [ %33, %.prol.loopexit.unr-lcssa ]
  %.03846.unr = phi i8 [ %13, %23 ], [ %27, %.prol.loopexit.unr-lcssa ]
  %34 = icmp eq i8 %13, 1
  br i1 %34, label %.loopexit, label %.new

.new:                                             ; preds = %.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %1, i64 1
  br label %35

35:                                               ; preds = %35, %.new
  %.13748 = phi i64 [ %.13748.unr, %.new ], [ %.137.1, %35 ]
  %.147 = phi double [ %.147.unr, %.new ], [ %47, %35 ]
  %.03846 = phi i8 [ %.03846.unr, %.new ], [ %42, %35 ]
  %36 = fmul double %.147, 1.000000e+01
  %37 = fptosi double %36 to i8
  %38 = add i8 %37, 48
  %39 = getelementptr inbounds i8, ptr %1, i64 %.13748
  store i8 %38, ptr %39, align 1, !tbaa !5
  %40 = sitofp i8 %37 to double
  %41 = fsub double %36, %40
  %42 = add i8 %.03846, -2
  %43 = fmul double %41, 1.000000e+01
  %44 = fptosi double %43 to i8
  %45 = add i8 %44, 48
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.13748
  store i8 %45, ptr %gep, align 1, !tbaa !5
  %46 = sitofp i8 %44 to double
  %47 = fsub double %43, %46
  %.137.1 = add i64 %.13748, 2
  %.not44.1 = icmp eq i8 %42, 0
  br i1 %.not44.1, label %.loopexit, label %35, !llvm.loop !8

.loopexit:                                        ; preds = %.prol.loopexit, %35, %17
  %.2 = phi i64 [ %22, %17 ], [ %.137.lcssa.unr, %.prol.loopexit ], [ %.137.1, %35 ]
  %48 = getelementptr inbounds i8, ptr %1, i64 %.2
  store i8 0, ptr %48, align 1, !tbaa !5
  br label %58

49:                                               ; preds = %10
  %50 = icmp eq i32 %6, 2139095040
  br i1 %50, label %51, label %56

51:                                               ; preds = %49
  %52 = fcmp ogt double %0, 0.000000e+00
  %53 = select i1 %52, i8 43, i8 45
  store i8 %53, ptr %1, align 1, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %1, i64 1
  %55 = tail call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef nonnull %54, ptr noundef nonnull @.str.1, i64 noundef 4) #2
  br label %58

56:                                               ; preds = %49
  %57 = tail call noundef i64 @_ZN3qOS4util6strcpyEPcPKcm(ptr noundef nonnull %1, ptr noundef nonnull @.str.2, i64 noundef 4) #2
  br label %58

58:                                               ; preds = %8, %51, %56, %.loopexit, %3
  ret ptr %1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i8 @_ZN3qOS9clipUpperIhEET_S1_S1_(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZL9xBaseUtoAmPch(i64 noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

attributes #0 = { 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 #1 = { inlinehint 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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