; LLVM IR from kmilo17pet/qlibs :: qfp16 (qFP16_FPToA)

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

@__const.qFP16_FPToA.iScales = external hidden unnamed_addr constant [6 x i32], align 16

; 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 @qFP16_Mul(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @qFP16_FPToA(i32 noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca [6 x i32], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %13, ptr %7, align 8, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp eq i32 -2147483648, %14
  br i1 %15, label %16, label %35

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  store i8 111, ptr %18, align 1, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 1
  store i8 118, ptr %20, align 1, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 2
  store i8 101, ptr %22, align 1, !tbaa !11
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %23, i64 3
  store i8 114, ptr %24, align 1, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %25, i64 4
  store i8 102, ptr %26, align 1, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 5
  store i8 108, ptr %28, align 1, !tbaa !11
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %29, i64 6
  store i8 111, ptr %30, align 1, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i64 7
  store i8 119, ptr %32, align 1, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  store i8 0, ptr %34, align 1, !tbaa !11
  br label %95

35:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %8, ptr align 16 @__const.qFP16_FPToA.iScales, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = icmp sge i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = load i32, ptr %4, align 4, !tbaa !5
  br label %43

40:                                               ; preds = %35
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sub nsw i32 0, %41
  br label %43

43:                                               ; preds = %40, %38
  %44 = phi i32 [ %39, %38 ], [ %42, %40 ]
  store i32 %44, ptr %9, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %43
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %5, align 8, !tbaa !9
  store i8 45, ptr %48, align 1, !tbaa !11
  br label %50

50:                                               ; preds = %47, %43
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = lshr i32 %51, 16
  store i32 %52, ptr %12, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = and i32 %53, 65535
  store i32 %54, ptr %10, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = icmp sgt i32 %55, 5
  br i1 %56, label %57, label %58

57:                                               ; preds = %50
  store i32 5, ptr %6, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %57, %50
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = icmp slt i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %61, %58
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [6 x i32], ptr %8, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  store i32 %66, ptr %11, align 4, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = load i32, ptr %11, align 4, !tbaa !5
  %69 = call i32 @qFP16_Mul(i32 noundef %67, i32 noundef %68)
  store i32 %69, ptr %10, align 4, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !5
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = icmp uge i32 %70, %71
  br i1 %72, label %73, label %79

73:                                               ; preds = %62
  %74 = load i32, ptr %12, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %12, align 4, !tbaa !5
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = sub i32 %77, %76
  store i32 %78, ptr %10, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %73, %62
  %80 = load ptr, ptr %5, align 8, !tbaa !9
  %81 = load i32, ptr %12, align 4, !tbaa !5
  %82 = call ptr @qFP16_itoa(ptr noundef %80, i32 noundef 10000, i32 noundef %81, i8 noundef zeroext 1)
  store ptr %82, ptr %5, align 8, !tbaa !9
  %83 = load i32, ptr %11, align 4, !tbaa !5
  %84 = icmp ne i32 1, %83
  br i1 %84, label %85, label %93

85:                                               ; preds = %79
  %86 = load ptr, ptr %5, align 8, !tbaa !9
  %87 = getelementptr inbounds i8, ptr %86, i32 1
  store ptr %87, ptr %5, align 8, !tbaa !9
  store i8 46, ptr %86, align 1, !tbaa !11
  %88 = load ptr, ptr %5, align 8, !tbaa !9
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = udiv i32 %89, 10
  %91 = load i32, ptr %10, align 4, !tbaa !5
  %92 = call ptr @qFP16_itoa(ptr noundef %88, i32 noundef %90, i32 noundef %91, i8 noundef zeroext 0)
  store ptr %92, ptr %5, align 8, !tbaa !9
  br label %93

93:                                               ; preds = %85, %79
  %94 = load ptr, ptr %5, align 8, !tbaa !9
  store i8 0, ptr %94, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  br label %95

95:                                               ; preds = %93, %16
  %96 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %96
}

; 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

; Function Attrs: nounwind uwtable
declare hidden ptr @qFP16_itoa(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext) #1

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 nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!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"

@__const.qFP16_FPToA.iScales = external hidden unnamed_addr constant [6 x i32], align 16

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @qFP16_FPToA(i32 noundef %0, ptr noundef returned %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %0, -2147483648
  br i1 %4, label %5, label %7

5:                                                ; preds = %3
  store <8 x i8> <i8 111, i8 118, i8 101, i8 114, i8 102, i8 108, i8 111, i8 119>, ptr %1, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  br label %26

7:                                                ; preds = %3
  %8 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
  %9 = icmp slt i32 %0, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 45, ptr %1, align 1, !tbaa !5
  br label %12

12:                                               ; preds = %10, %7
  %.037 = phi ptr [ %11, %10 ], [ %1, %7 ]
  %13 = lshr i32 %8, 16
  %14 = and i32 %8, 65535
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %2, i32 5)
  %spec.store.select1 = tail call i32 @llvm.smax.i32(i32 %spec.store.select, i32 0)
  %15 = zext nneg i32 %spec.store.select1 to i64
  %16 = getelementptr inbounds [6 x i32], ptr @__const.qFP16_FPToA.iScales, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !8
  %18 = tail call i32 @qFP16_Mul(i32 noundef %14, i32 noundef %17)
  %.not = icmp uge i32 %18, %17
  %19 = zext i1 %.not to i32
  %.0 = add nuw nsw i32 %13, %19
  %20 = tail call ptr @qFP16_itoa(ptr noundef %.037, i32 noundef 10000, i32 noundef %.0, i8 noundef zeroext 1)
  %.not44 = icmp eq i32 %17, 1
  br i1 %.not44, label %26, label %21

21:                                               ; preds = %12
  %22 = select i1 %.not, i32 %17, i32 0
  %.038 = sub i32 %18, %22
  %23 = getelementptr inbounds i8, ptr %20, i64 1
  store i8 46, ptr %20, align 1, !tbaa !5
  %24 = udiv i32 %17, 10
  %25 = tail call ptr @qFP16_itoa(ptr noundef nonnull %23, i32 noundef %24, i32 noundef %.038, i8 noundef zeroext 0)
  br label %26

26:                                               ; preds = %12, %21, %5
  %.1.sink = phi ptr [ %6, %5 ], [ %25, %21 ], [ %20, %12 ]
  store i8 0, ptr %.1.sink, align 1, !tbaa !5
  ret ptr %1
}

; Function Attrs: nounwind uwtable
declare hidden ptr @qFP16_itoa(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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