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

; 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: nounwind uwtable
declare dso_local i32 @round_f64_to_string(double noundef, i64 noundef, ptr noundef, i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @compare_f64_values(double noundef %0, double noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 16, ptr %6, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %50, %2
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp sge i64 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %7, align 4
  br label %53

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %18 = load double, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = call i32 @round_f64_to_string(double noundef %18, i64 noundef %19, ptr noundef null, i32 noundef 0)
  store i32 %20, ptr %8, align 4, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = add nsw i32 %21, 1
  %23 = zext i32 %22 to i64
  %24 = call ptr @llvm.stacksave.p0()
  store ptr %24, ptr %9, align 8
  %25 = alloca i8, i64 %23, align 16
  store i64 %23, ptr %10, align 8
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = trunc i64 %23 to i32
  %29 = call i32 @round_f64_to_string(double noundef %26, i64 noundef %27, ptr noundef %25, i32 noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %30 = load double, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = call i32 @round_f64_to_string(double noundef %30, i64 noundef %31, ptr noundef null, i32 noundef 0)
  store i32 %32, ptr %11, align 4, !tbaa !11
  %33 = load i32, ptr %11, align 4, !tbaa !11
  %34 = add nsw i32 %33, 1
  %35 = zext i32 %34 to i64
  %36 = alloca i8, i64 %35, align 16
  store i64 %35, ptr %12, align 8
  %37 = load double, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = trunc i64 %35 to i32
  %40 = call i32 @round_f64_to_string(double noundef %37, i64 noundef %38, ptr noundef %36, i32 noundef %39)
  %41 = call i32 @strcmp(ptr noundef %25, ptr noundef %36) #5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %45, label %43

43:                                               ; preds = %17
  %44 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %44, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %46

45:                                               ; preds = %17
  store i32 0, ptr %7, align 4
  br label %46

46:                                               ; preds = %45, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %47 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %47)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %48 = load i32, ptr %7, align 4
  switch i32 %48, label %53 [
    i32 0, label %49
  ]

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = add nsw i64 %51, -1
  store i64 %52, ptr %6, align 8, !tbaa !9
  br label %13, !llvm.loop !13

53:                                               ; preds = %46, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %54 = load i32, ptr %7, align 4
  switch i32 %54, label %58 [
    i32 2, label %55
    i32 1, label %56
  ]

55:                                               ; preds = %53
  store i64 -1, ptr %3, align 8
  br label %56

56:                                               ; preds = %55, %53
  %57 = load i64, ptr %3, align 8
  ret i64 %57

58:                                               ; preds = %53
  unreachable
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 nosync nounwind willreturn }
attributes #3 = { 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 #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 = !{!"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 = !{!"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 i32 @round_f64_to_string(double noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @compare_f64_values(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %2, %16
  %.01619 = phi i64 [ 16, %2 ], [ %17, %16 ]
  %4 = call i32 @round_f64_to_string(double noundef %0, i64 noundef %.01619, ptr noundef null, i32 noundef 0)
  %5 = add nsw i32 %4, 1
  %6 = zext i32 %5 to i64
  %7 = call ptr @llvm.stacksave.p0()
  %8 = alloca i8, i64 %6, align 16
  %9 = call i32 @round_f64_to_string(double noundef %0, i64 noundef %.01619, ptr noundef nonnull %8, i32 noundef %5)
  %10 = call i32 @round_f64_to_string(double noundef %1, i64 noundef %.01619, ptr noundef null, i32 noundef 0)
  %11 = add nsw i32 %10, 1
  %12 = zext i32 %11 to i64
  %13 = alloca i8, i64 %12, align 16
  %14 = call i32 @round_f64_to_string(double noundef %1, i64 noundef %.01619, ptr noundef nonnull %13, i32 noundef %11)
  %15 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %8, ptr noundef nonnull dereferenceable(1) %13) #3
  %.not.not = icmp eq i32 %15, 0
  call void @llvm.stackrestore.p0(ptr %7)
  br i1 %.not.not, label %19, label %16

16:                                               ; preds = %3
  %17 = add nsw i64 %.01619, -1
  %18 = icmp eq i64 %.01619, 0
  br i1 %18, label %19, label %3, !llvm.loop !5

19:                                               ; preds = %16, %3
  %spec.select = phi i64 [ %.01619, %3 ], [ -1, %16 ]
  ret i64 %spec.select
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

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 willreturn }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass