; 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: 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
define dso_local double @ptod(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call ptr @pparmq(ptr noundef %5)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.precisionType, ptr %7, i32 0, i32 4
  %9 = getelementptr inbounds [1 x i16], ptr %8, i64 0, i64 0
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.precisionType, ptr %10, i32 0, i32 2
  %12 = load i16, ptr %11, align 2, !tbaa !9
  %13 = zext i16 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i16, ptr %9, i64 %14
  store ptr %15, ptr %3, align 8, !tbaa !5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !12
  br label %16

16:                                               ; preds = %23, %1
  %17 = load double, ptr %4, align 8, !tbaa !12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i16, ptr %18, i32 -1
  store ptr %19, ptr %3, align 8, !tbaa !5
  %20 = load i16, ptr %19, align 2, !tbaa !14
  %21 = uitofp i16 %20 to double
  %22 = call double @llvm.fmuladd.f64(double %17, double 6.553600e+04, double %21)
  store double %22, ptr %4, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.precisionType, ptr %25, i32 0, i32 4
  %27 = getelementptr inbounds [1 x i16], ptr %26, i64 0, i64 0
  %28 = icmp ugt ptr %24, %27
  br i1 %28, label %16, label %29, !llvm.loop !15

29:                                               ; preds = %23
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.precisionType, ptr %30, i32 0, i32 3
  %32 = load i8, ptr %31, align 2, !tbaa !17
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = load double, ptr %4, align 8, !tbaa !12
  %36 = fneg double %35
  store double %36, ptr %4, align 8, !tbaa !12
  br label %37

37:                                               ; preds = %34, %29
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @pdestroy(ptr noundef %38)
  %39 = load double, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %39
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @pparmq(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdestroy(ptr noundef) #2

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 = { 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 #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !7, i64 6, !7, i64 8}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !7, i64 6}


; 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 double @ptod(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @pparmq(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = zext i16 %4 to i64
  %.idx = shl nuw nsw i64 %5, 1
  %.add = add nuw nsw i64 %.idx, 8
  br label %6

6:                                                ; preds = %6, %1
  %.011.idx = phi i64 [ %.add, %1 ], [ %.011.add, %6 ]
  %.0 = phi double [ 0.000000e+00, %1 ], [ %9, %6 ]
  %.011.add = add nsw i64 %.011.idx, -2
  %.ptr = getelementptr inbounds i8, ptr %0, i64 %.011.add
  %7 = load i16, ptr %.ptr, align 2, !tbaa !10
  %8 = uitofp i16 %7 to double
  %9 = tail call double @llvm.fmuladd.f64(double %.0, double 6.553600e+04, double %8)
  %10 = icmp ugt i64 %.011.idx, 10
  br i1 %10, label %6, label %11, !llvm.loop !11

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 6
  %13 = load i8, ptr %12, align 2, !tbaa !13
  %.not = icmp eq i8 %13, 0
  %14 = fneg double %9
  %.1 = select i1 %.not, double %9, double %14
  tail call void @pdestroy(ptr noundef nonnull %0)
  ret double %.1
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @pdestroy(ptr noundef) local_unnamed_addr #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 = { 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 #2 = { mustprogress 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, !7, i64 4}
!6 = !{!"", !7, i64 0, !7, i64 2, !7, i64 4, !8, i64 6, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !8, i64 6}


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