; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

; 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
declare double @pow(double noundef, double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @r8_round2(i32 noundef %0, double noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 2.000000e+00, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store double 0.000000e+00, ptr %12, align 8, !tbaa !9
  %14 = load double, ptr %5, align 8, !tbaa !9
  %15 = fcmp oeq double %14, 0.000000e+00
  br i1 %15, label %16, label %18

16:                                               ; preds = %2
  %17 = load double, ptr %12, align 8, !tbaa !9
  store double %17, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %85

18:                                               ; preds = %2
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp sle i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load double, ptr %12, align 8, !tbaa !9
  store double %22, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %85

23:                                               ; preds = %18
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = fcmp olt double 0.000000e+00, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  store i32 1, ptr %8, align 4, !tbaa !5
  %27 = load double, ptr %5, align 8, !tbaa !9
  store double %27, ptr %11, align 8, !tbaa !9
  br label %31

28:                                               ; preds = %23
  store i32 -1, ptr %8, align 4, !tbaa !5
  %29 = load double, ptr %5, align 8, !tbaa !9
  %30 = fneg double %29
  store double %30, ptr %11, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %28, %26
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %35, %31
  %33 = load double, ptr %11, align 8, !tbaa !9
  %34 = fcmp ole double 2.000000e+00, %33
  br i1 %34, label %35, label %40

35:                                               ; preds = %32
  %36 = load double, ptr %11, align 8, !tbaa !9
  %37 = fdiv double %36, 2.000000e+00
  store double %37, ptr %11, align 8, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !5
  br label %32, !llvm.loop !11

40:                                               ; preds = %32
  br label %41

41:                                               ; preds = %44, %40
  %42 = load double, ptr %11, align 8, !tbaa !9
  %43 = fcmp olt double %42, 1.000000e+00
  br i1 %43, label %44, label %49

44:                                               ; preds = %41
  %45 = load double, ptr %11, align 8, !tbaa !9
  %46 = fmul double %45, 2.000000e+00
  store double %46, ptr %11, align 8, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !5
  br label %41, !llvm.loop !13

49:                                               ; preds = %41
  store double 0.000000e+00, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %78, %49
  %51 = load double, ptr %10, align 8, !tbaa !9
  %52 = fmul double 2.000000e+00, %51
  store double %52, ptr %10, align 8, !tbaa !9
  %53 = load double, ptr %11, align 8, !tbaa !9
  %54 = fcmp ole double 1.000000e+00, %53
  br i1 %54, label %55, label %60

55:                                               ; preds = %50
  %56 = load double, ptr %10, align 8, !tbaa !9
  %57 = fadd double %56, 1.000000e+00
  store double %57, ptr %10, align 8, !tbaa !9
  %58 = load double, ptr %11, align 8, !tbaa !9
  %59 = fsub double %58, 1.000000e+00
  store double %59, ptr %11, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %55, %50
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !5
  %63 = load double, ptr %11, align 8, !tbaa !9
  %64 = fcmp oeq double %63, 0.000000e+00
  br i1 %64, label %69, label %65

65:                                               ; preds = %60
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = icmp sle i32 %66, %67
  br i1 %68, label %69, label %78

69:                                               ; preds = %65, %60
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = sitofp i32 %70 to double
  %72 = load double, ptr %10, align 8, !tbaa !9
  %73 = fmul double %71, %72
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = sitofp i32 %74 to double
  %76 = call double @pow(double noundef 2.000000e+00, double noundef %75) #3
  %77 = fmul double %73, %76
  store double %77, ptr %12, align 8, !tbaa !9
  br label %83

78:                                               ; preds = %65
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = sub nsw i32 %79, 1
  store i32 %80, ptr %7, align 4, !tbaa !5
  %81 = load double, ptr %11, align 8, !tbaa !9
  %82 = fmul double %81, 2.000000e+00
  store double %82, ptr %11, align 8, !tbaa !9
  br label %50

83:                                               ; preds = %69
  %84 = load double, ptr %12, align 8, !tbaa !9
  store double %84, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %85

85:                                               ; preds = %83, %21, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %86 = load double, ptr %3, align 8
  ret double %86
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: nofree nounwind uwtable
define dso_local double @r8_round2(i32 noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fcmp oeq double %1, 0.000000e+00
  %4 = icmp slt i32 %0, 1
  %or.cond38 = or i1 %4, %3
  br i1 %or.cond38, label %31, label %5

5:                                                ; preds = %2
  %6 = fcmp ogt double %1, 0.000000e+00
  %7 = fneg double %1
  %.0 = select i1 %6, double %1, double %7
  %8 = fcmp ult double %.0, 2.000000e+00
  br i1 %8, label %.preheader39, label %.lr.ph

.preheader39:                                     ; preds = %.lr.ph, %5
  %.031.lcssa = phi i32 [ 0, %5 ], [ %11, %.lr.ph ]
  %.1.lcssa = phi double [ %.0, %5 ], [ %10, %.lr.ph ]
  %9 = fcmp olt double %.1.lcssa, 1.000000e+00
  br i1 %9, label %.lr.ph45, label %.preheader

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.141 = phi double [ %10, %.lr.ph ], [ %.0, %5 ]
  %.03140 = phi i32 [ %11, %.lr.ph ], [ 0, %5 ]
  %10 = fmul double %.141, 5.000000e-01
  %11 = add nuw nsw i32 %.03140, 1
  %12 = fcmp ult double %10, 2.000000e+00
  br i1 %12, label %.preheader39, label %.lr.ph, !llvm.loop !5

.preheader:                                       ; preds = %.lr.ph45, %.preheader39
  %.132.lcssa = phi i32 [ %.031.lcssa, %.preheader39 ], [ %17, %.lr.ph45 ]
  %.2.lcssa = phi double [ %.1.lcssa, %.preheader39 ], [ %16, %.lr.ph45 ]
  %13 = fcmp ult double %.2.lcssa, 1.000000e+00
  %14 = fadd double %.2.lcssa, -1.000000e+00
  %.12848 = select i1 %13, double 0.000000e+00, double 1.000000e+00
  %.449 = select i1 %13, double %.2.lcssa, double %14
  %15 = fcmp une double %.449, 0.000000e+00
  %.not50 = icmp sgt i32 %0, 1
  %or.cond51 = and i1 %15, %.not50
  br i1 %or.cond51, label %.lr.ph55, label %._crit_edge

.lr.ph45:                                         ; preds = %.preheader39, %.lr.ph45
  %.244 = phi double [ %16, %.lr.ph45 ], [ %.1.lcssa, %.preheader39 ]
  %.13243 = phi i32 [ %17, %.lr.ph45 ], [ %.031.lcssa, %.preheader39 ]
  %16 = fmul double %.244, 2.000000e+00
  %17 = add nsw i32 %.13243, -1
  %18 = fcmp olt double %16, 1.000000e+00
  br i1 %18, label %.lr.ph45, label %.preheader, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph55, %.preheader
  %.233.lcssa = phi i32 [ %.132.lcssa, %.preheader ], [ %23, %.lr.ph55 ]
  %.128.lcssa = phi double [ %.12848, %.preheader ], [ %.128, %.lr.ph55 ]
  %19 = fneg double %.128.lcssa
  %20 = select i1 %6, double %.128.lcssa, double %19
  %ldexp = tail call double @ldexp(double 1.000000e+00, i32 %.233.lcssa) #2
  %21 = fmul double %20, %ldexp
  br label %31

.lr.ph55:                                         ; preds = %.preheader, %.lr.ph55
  %22 = phi i32 [ %29, %.lr.ph55 ], [ 1, %.preheader ]
  %.454 = phi double [ %.4, %.lr.ph55 ], [ %.449, %.preheader ]
  %.12853 = phi double [ %.128, %.lr.ph55 ], [ %.12848, %.preheader ]
  %.23352 = phi i32 [ %23, %.lr.ph55 ], [ %.132.lcssa, %.preheader ]
  %23 = add nsw i32 %.23352, -1
  %24 = fmul double %.454, 2.000000e+00
  %25 = fmul double %.12853, 2.000000e+00
  %26 = fcmp ult double %24, 1.000000e+00
  %27 = fadd double %25, 1.000000e+00
  %28 = fadd double %24, -1.000000e+00
  %.128 = select i1 %26, double %25, double %27
  %.4 = select i1 %26, double %24, double %28
  %29 = add nuw nsw i32 %22, 1
  %30 = fcmp une double %.4, 0.000000e+00
  %.not = icmp slt i32 %29, %0
  %or.cond = select i1 %30, i1 %.not, i1 false
  br i1 %or.cond, label %.lr.ph55, label %._crit_edge

31:                                               ; preds = %2, %._crit_edge
  %.029 = phi double [ %21, %._crit_edge ], [ 0.000000e+00, %2 ]
  ret double %.029
}

; Function Attrs: nofree willreturn
declare double @ldexp(double, i32) local_unnamed_addr #1

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


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass