; LLVM IR from freakout42/macrocalc :: mc/src (mcfinc)

; 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: nounwind uwtable
define dso_local double @ddb(double noundef %0, double noundef %1, double noundef %2, double noundef %3) #0 {
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  store double %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !5
  store double %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %15 = load double, ptr %9, align 8, !tbaa !5
  %16 = fadd double %15, 5.000000e-01
  %17 = fptosi double %16 to i32
  store i32 %17, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store double 0.000000e+00, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %18 = load double, ptr %6, align 8, !tbaa !5
  store double %18, ptr %13, align 8, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 1
  br i1 %20, label %27, label %21

21:                                               ; preds = %4
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = load double, ptr %8, align 8, !tbaa !5
  %24 = fadd double %23, 5.000000e-01
  %25 = fptosi double %24 to i32
  %26 = icmp sgt i32 %22, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %21, %4
  %28 = call ptr @__errno_location() #4
  store i32 34, ptr %28, align 4, !tbaa !9
  store double 0x7FF0000000000000, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %69

29:                                               ; preds = %21
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %42, %29
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %45

34:                                               ; preds = %30
  %35 = load double, ptr %13, align 8, !tbaa !5
  %36 = fmul double %35, 2.000000e+00
  %37 = load double, ptr %8, align 8, !tbaa !5
  %38 = fdiv double %36, %37
  store double %38, ptr %12, align 8, !tbaa !5
  %39 = load double, ptr %12, align 8, !tbaa !5
  %40 = load double, ptr %13, align 8, !tbaa !5
  %41 = fsub double %40, %39
  store double %41, ptr %13, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %34
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %10, align 4, !tbaa !9
  br label %30, !llvm.loop !11

45:                                               ; preds = %30
  %46 = load double, ptr %12, align 8, !tbaa !5
  %47 = load double, ptr %13, align 8, !tbaa !5
  %48 = fadd double %47, %46
  store double %48, ptr %13, align 8, !tbaa !5
  %49 = load double, ptr %13, align 8, !tbaa !5
  %50 = load double, ptr %7, align 8, !tbaa !5
  %51 = fcmp ogt double %49, %50
  br i1 %51, label %52, label %66

52:                                               ; preds = %45
  %53 = load double, ptr %12, align 8, !tbaa !5
  %54 = load double, ptr %13, align 8, !tbaa !5
  %55 = load double, ptr %7, align 8, !tbaa !5
  %56 = fsub double %54, %55
  %57 = fcmp olt double %53, %56
  br i1 %57, label %58, label %60

58:                                               ; preds = %52
  %59 = load double, ptr %12, align 8, !tbaa !5
  br label %64

60:                                               ; preds = %52
  %61 = load double, ptr %13, align 8, !tbaa !5
  %62 = load double, ptr %7, align 8, !tbaa !5
  %63 = fsub double %61, %62
  br label %64

64:                                               ; preds = %60, %58
  %65 = phi double [ %59, %58 ], [ %63, %60 ]
  br label %67

66:                                               ; preds = %45
  br label %67

67:                                               ; preds = %66, %64
  %68 = phi double [ %65, %64 ], [ 0.000000e+00, %66 ]
  store double %68, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %69

69:                                               ; preds = %67, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  %70 = load double, ptr %5, align 8
  ret double %70
}

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

; 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 = { nounwind willreturn memory(none) "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 }
attributes #4 = { nounwind 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: nofree nosync nounwind memory(write, inaccessiblemem: none) uwtable
define dso_local double @ddb(double noundef %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #0 {
  %5 = fadd double %3, 5.000000e-01
  %6 = fptosi double %5 to i32
  %7 = icmp slt i32 %6, 1
  br i1 %7, label %13, label %8

8:                                                ; preds = %4
  %9 = fadd double %2, 5.000000e-01
  %10 = fptosi double %9 to i32
  %11 = icmp sgt i32 %6, %10
  br i1 %11, label %13, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %8
  %xtraiter = and i32 %6, 3
  %12 = icmp ult i32 %6, 4
  br i1 %12, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %6, 2147483644
  br label %.lr.ph

13:                                               ; preds = %8, %4
  %14 = tail call ptr @__errno_location() #2
  store i32 34, ptr %14, align 4, !tbaa !5
  br label %36

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.030 = phi double [ %0, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %15 = fmul double %.030, 2.000000e+00
  %16 = fdiv double %15, %2
  %17 = fsub double %.030, %16
  %18 = fmul double %17, 2.000000e+00
  %19 = fdiv double %18, %2
  %20 = fsub double %17, %19
  %21 = fmul double %20, 2.000000e+00
  %22 = fdiv double %21, %2
  %23 = fsub double %20, %22
  %24 = fmul double %23, 2.000000e+00
  %25 = fdiv double %24, %2
  %26 = fsub double %23, %25
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa35.ph = phi double [ poison, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %.030.unr = phi double [ %0, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.030.epil = phi double [ %29, %.lr.ph.epil ], [ %.030.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %27 = fmul double %.030.epil, 2.000000e+00
  %28 = fdiv double %27, %2
  %29 = fsub double %.030.epil, %28
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %.lcssa35 = phi double [ %.lcssa35.ph, %._crit_edge.unr-lcssa ], [ %28, %.lr.ph.epil ]
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %29, %.lr.ph.epil ]
  %30 = fadd double %.lcssa35, %.lcssa
  %31 = fcmp ogt double %30, %1
  br i1 %31, label %32, label %36

32:                                               ; preds = %._crit_edge
  %33 = fsub double %30, %1
  %34 = fcmp olt double %.lcssa35, %33
  %35 = select i1 %34, double %.lcssa35, double %33
  br label %36

36:                                               ; preds = %32, %._crit_edge, %13
  %.023 = phi double [ 0x7FF0000000000000, %13 ], [ %35, %32 ], [ 0.000000e+00, %._crit_edge ]
  ret double %.023
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

attributes #0 = { nofree nosync nounwind memory(write, inaccessiblemem: none) 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 nofree nosync nounwind willreturn memory(none) "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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}


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