; LLVM IR from daanx/mimalloc-bench :: bench/cfrac (pfloat)

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

%struct.precisionType = type { i16, i16, i16, i8, [1 x i16] }

; Function Attrs: nounwind uwtable
define dso_local ptr @dtop(double noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %7 = call ptr (i32, ...) @palloc(i32 noundef 129)
  store ptr %7, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %1
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %11, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %53

12:                                               ; preds = %1
  %13 = load double, ptr %3, align 8, !tbaa !5
  %14 = fcmp olt double %13, 0.000000e+00
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = fneg double %16
  store double %17, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.precisionType, ptr %18, i32 0, i32 3
  store i8 1, ptr %19, align 2, !tbaa !11
  br label %23

20:                                               ; preds = %12
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.precisionType, ptr %21, i32 0, i32 3
  store i8 0, ptr %22, align 2, !tbaa !11
  br label %23

23:                                               ; preds = %20, %15
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.precisionType, ptr %24, i32 0, i32 4
  %26 = getelementptr inbounds [1 x i16], ptr %25, i64 0, i64 0
  store ptr %26, ptr %4, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %36, %23
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = call double @fmod(double noundef %28, double noundef 6.553600e+04) #6
  %30 = fptoui double %29 to i16
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds i16, ptr %31, i32 1
  store ptr %32, ptr %4, align 8, !tbaa !9
  store i16 %30, ptr %31, align 2, !tbaa !14
  %33 = load double, ptr %3, align 8, !tbaa !5
  %34 = fdiv double %33, 6.553600e+04
  %35 = call double @llvm.floor.f64(double %34)
  store double %35, ptr %3, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %27
  %37 = load double, ptr %3, align 8, !tbaa !5
  %38 = fcmp une double %37, 0.000000e+00
  br i1 %38, label %27, label %39, !llvm.loop !15

39:                                               ; preds = %36
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.precisionType, ptr %41, i32 0, i32 4
  %43 = getelementptr inbounds [1 x i16], ptr %42, i64 0, i64 0
  %44 = ptrtoint ptr %40 to i64
  %45 = ptrtoint ptr %43 to i64
  %46 = sub i64 %44, %45
  %47 = sdiv exact i64 %46, 2
  %48 = trunc i64 %47 to i16
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.precisionType, ptr %49, i32 0, i32 2
  store i16 %48, ptr %50, align 2, !tbaa !17
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = call ptr @presult(ptr noundef %51)
  store ptr %52, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %53

53:                                               ; preds = %39, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %54 = load ptr, ptr %2, align 8
  ret ptr %54
}

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

declare ptr @palloc(...) #2

; Function Attrs: nounwind
declare double @fmod(double noundef, double noundef) #3

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @presult(ptr noundef) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { inlinehint 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 #6 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 6}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !7, i64 6, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !13, i64 4}


; 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
define dso_local ptr @dtop(double noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr (i32, ...) @palloc(i32 noundef 129) #5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %24, label %4

4:                                                ; preds = %1
  %5 = fcmp olt double %0, 0.000000e+00
  %6 = fneg double %0
  %.sink = zext i1 %5 to i8
  %.017 = select i1 %5, double %6, double %0
  %7 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %.sink, ptr %7, align 2
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  br label %9

9:                                                ; preds = %9, %4
  %.1 = phi double [ %.017, %4 ], [ %14, %9 ]
  %.016 = phi ptr [ %8, %4 ], [ %12, %9 ]
  %10 = tail call double @fmod(double noundef %.1, double noundef 6.553600e+04) #5
  %11 = fptoui double %10 to i16
  %12 = getelementptr inbounds i8, ptr %.016, i64 2
  store i16 %11, ptr %.016, align 2, !tbaa !5
  %13 = fmul double %.1, 0x3EF0000000000000
  %14 = tail call double @llvm.floor.f64(double %13)
  %15 = fcmp une double %14, 0.000000e+00
  br i1 %15, label %9, label %16, !llvm.loop !9

16:                                               ; preds = %9
  %17 = ptrtoint ptr %12 to i64
  %18 = ptrtoint ptr %8 to i64
  %19 = sub i64 %17, %18
  %20 = lshr exact i64 %19, 1
  %21 = trunc i64 %20 to i16
  %22 = getelementptr inbounds i8, ptr %2, i64 4
  store i16 %21, ptr %22, align 2, !tbaa !11
  %23 = tail call ptr @presult(ptr noundef nonnull %2)
  br label %24

24:                                               ; preds = %1, %16
  %.0 = phi ptr [ %23, %16 ], [ null, %1 ]
  ret ptr %.0
}

declare ptr @palloc(...) local_unnamed_addr #1

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @presult(ptr noundef) local_unnamed_addr #4

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 = { "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 = { inlinehint 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 }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 4}
!12 = !{!"", !6, i64 0, !6, i64 2, !6, i64 4, !7, i64 6, !7, i64 8}


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