; LLVM IR from microsoft/LightAIMD :: src (f64_util)

; 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 [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @char_to_digit(i8 noundef signext) #0

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pos_of_dot(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_exponent(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @f64_sign(double noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @round_f64_to_string(double noundef %0, i64 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca double, align 8
  store double %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !11
  store i32 %3, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr @.str, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %24 = load ptr, ptr %10, align 8, !tbaa !11
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef null, i64 noundef 0, ptr noundef %24, i64 noundef %25) #5
  store i32 %26, ptr %11, align 4, !tbaa !13
  %27 = load i32, ptr %11, align 4, !tbaa !13
  %28 = add nsw i32 %27, 1
  %29 = zext i32 %28 to i64
  %30 = call ptr @llvm.stacksave.p0()
  store ptr %30, ptr %12, align 8
  %31 = alloca i8, i64 %29, align 16
  store i64 %29, ptr %13, align 8
  %32 = load ptr, ptr %10, align 8, !tbaa !11
  %33 = load i64, ptr %7, align 8, !tbaa !9
  %34 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %31, i64 noundef %29, ptr noundef %32, i64 noundef %33) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store ptr %31, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %35 = load ptr, ptr %14, align 8, !tbaa !11
  %36 = load double, ptr %6, align 8, !tbaa !5
  %37 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef null, i64 noundef 0, ptr noundef %35, double noundef %36) #5
  store i32 %37, ptr %15, align 4, !tbaa !13
  %38 = load ptr, ptr %8, align 8, !tbaa !11
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %42

40:                                               ; preds = %4
  %41 = load i32, ptr %15, align 4, !tbaa !13
  store i32 %41, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %105

42:                                               ; preds = %4
  %43 = load ptr, ptr %8, align 8, !tbaa !11
  %44 = load i32, ptr %9, align 4, !tbaa !13
  %45 = sext i32 %44 to i64
  %46 = load ptr, ptr %14, align 8, !tbaa !11
  %47 = load double, ptr %6, align 8, !tbaa !5
  %48 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %43, i64 noundef %45, ptr noundef %46, double noundef %47) #5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = icmp eq i64 %49, 16
  br i1 %50, label %51, label %54

51:                                               ; preds = %42
  %52 = load i32, ptr %9, align 4, !tbaa !13
  %53 = sub nsw i32 %52, 1
  store i32 %53, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %105

54:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store ptr @.str.1, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %55 = load ptr, ptr %17, align 8, !tbaa !11
  %56 = load double, ptr %6, align 8, !tbaa !5
  %57 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef null, i64 noundef 0, ptr noundef %55, double noundef %56) #5
  store i32 %57, ptr %18, align 4, !tbaa !13
  %58 = load i32, ptr %18, align 4, !tbaa !13
  %59 = add nsw i32 %58, 1
  %60 = zext i32 %59 to i64
  %61 = alloca i8, i64 %60, align 16
  store i64 %60, ptr %19, align 8
  %62 = load ptr, ptr %17, align 8, !tbaa !11
  %63 = load double, ptr %6, align 8, !tbaa !5
  %64 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %61, i64 noundef %60, ptr noundef %62, double noundef %63) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #5
  %65 = load i32, ptr %18, align 4, !tbaa !13
  %66 = call i32 @pos_of_dot(ptr noundef %61, i32 noundef %65)
  store i32 %66, ptr %20, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  %67 = load i32, ptr %20, align 4, !tbaa !13
  %68 = sext i32 %67 to i64
  %69 = load i64, ptr %7, align 8, !tbaa !9
  %70 = add nsw i64 %68, %69
  %71 = trunc i64 %70 to i32
  store i32 %71, ptr %21, align 4, !tbaa !13
  %72 = load i32, ptr %21, align 4, !tbaa !13
  %73 = add nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %61, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !15
  %77 = call i32 @char_to_digit(i8 noundef signext %76)
  %78 = icmp sgt i32 %77, 4
  br i1 %78, label %79, label %101

79:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  %80 = load i32, ptr %21, align 4, !tbaa !13
  %81 = load i32, ptr %18, align 4, !tbaa !13
  %82 = call i32 @get_exponent(ptr noundef %61, i32 noundef %81)
  %83 = add nsw i32 %80, %82
  store i32 %83, ptr %22, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %84 = load double, ptr %6, align 8, !tbaa !5
  %85 = load double, ptr %6, align 8, !tbaa !5
  %86 = call i32 @f64_sign(double noundef %85)
  %87 = sitofp i32 %86 to double
  %88 = load i32, ptr %22, align 4, !tbaa !13
  %89 = sub nsw i32 0, %88
  %90 = sitofp i32 %89 to double
  %91 = call double @pow(double noundef 1.000000e+01, double noundef %90) #5
  %92 = call double @llvm.fmuladd.f64(double %87, double %91, double %84)
  store double %92, ptr %23, align 8, !tbaa !5
  %93 = load ptr, ptr %8, align 8, !tbaa !11
  %94 = load i32, ptr %9, align 4, !tbaa !13
  %95 = sext i32 %94 to i64
  %96 = load ptr, ptr %14, align 8, !tbaa !11
  %97 = load double, ptr %23, align 8, !tbaa !5
  %98 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %93, i64 noundef %95, ptr noundef %96, double noundef %97) #5
  %99 = load i32, ptr %9, align 4, !tbaa !13
  %100 = sub nsw i32 %99, 1
  store i32 %100, ptr %5, align 4
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  br label %104

101:                                              ; preds = %54
  %102 = load i32, ptr %9, align 4, !tbaa !13
  %103 = sub nsw i32 %102, 1
  store i32 %103, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %104

104:                                              ; preds = %101, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %105

105:                                              ; preds = %104, %51, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %106 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %106)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %107 = load i32, ptr %5, align 4
  ret i32 %107
}

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !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"

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @char_to_digit(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @pos_of_dot(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_exponent(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @f64_sign(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @round_f64_to_string(double noundef %0, i64 noundef %1, ptr noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef null, i64 noundef 0, ptr noundef nonnull @.str, i64 noundef %1) #4
  %6 = add nsw i32 %5, 1
  %7 = zext i32 %6 to i64
  %8 = alloca i8, i64 %7, align 16
  %9 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %8, i64 noundef %7, ptr noundef nonnull @.str, i64 noundef %1) #4
  %10 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef null, i64 noundef 0, ptr noundef nonnull %8, double noundef %0) #4
  %11 = icmp eq ptr %2, null
  br i1 %11, label %44, label %12

12:                                               ; preds = %4
  %13 = sext i32 %3 to i64
  %14 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %2, i64 noundef %13, ptr noundef nonnull %8, double noundef %0) #4
  %15 = icmp eq i64 %1, 16
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = add nsw i32 %3, -1
  br label %44

18:                                               ; preds = %12
  %19 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef null, i64 noundef 0, ptr noundef nonnull @.str.1, double noundef %0) #4
  %20 = add nsw i32 %19, 1
  %21 = zext i32 %20 to i64
  %22 = alloca i8, i64 %21, align 16
  %23 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %22, i64 noundef %21, ptr noundef nonnull @.str.1, double noundef %0) #4
  %24 = call i32 @pos_of_dot(ptr noundef nonnull %22, i32 noundef %19)
  %25 = trunc i64 %1 to i32
  %26 = add i32 %24, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr i8, ptr %22, i64 %27
  %29 = getelementptr i8, ptr %28, i64 1
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = call i32 @char_to_digit(i8 noundef signext %30)
  %32 = icmp sgt i32 %31, 4
  br i1 %32, label %33, label %43

33:                                               ; preds = %18
  %34 = call i32 @get_exponent(ptr noundef nonnull %22, i32 noundef %19)
  %35 = add nsw i32 %26, %34
  %36 = call i32 @f64_sign(double noundef %0)
  %37 = sitofp i32 %36 to double
  %38 = sub nsw i32 0, %35
  %39 = sitofp i32 %38 to double
  %40 = call double @pow(double noundef 1.000000e+01, double noundef %39) #4
  %41 = call double @llvm.fmuladd.f64(double %37, double %40, double %0)
  %42 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull %2, i64 noundef %13, ptr noundef nonnull %8, double noundef %41) #4
  br label %43

43:                                               ; preds = %18, %33
  %.0 = add nsw i32 %3, -1
  br label %44

44:                                               ; preds = %4, %43, %16
  %.1 = phi i32 [ %17, %16 ], [ %.0, %43 ], [ %10, %4 ]
  ret i32 %.1
}

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #2

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

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 = { nofree 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass