; LLVM IR from upupming/algorithm :: kick-start/2020/RoundG/D-Merge_Cards.ll (Z11solve_cubicv)

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

@n = external dso_local global i32, align 4
@sum = external dso_local global [5010 x i64], align 16
@dp = external dso_local global [5010 x [5010 x double]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z11solve_cubicv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %91, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %94

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %87, %13
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %15, %16
  %18 = sub nsw i32 %17, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %14
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %90

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = add nsw i32 %23, %24
  %26 = sub nsw i32 %25, 1
  store i32 %26, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = sub nsw i64 %30, %35
  %37 = sitofp i64 %36 to double
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5010 x double], ptr %40, i64 0, i64 %42
  store double %37, ptr %43, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store double 0.000000e+00, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 0.000000e+00, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %44 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %44, ptr %7, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %72, %22
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %75

51:                                               ; preds = %45
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %53
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5010 x double], ptr %54, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %61
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5010 x double], ptr %62, i64 0, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !11
  %67 = fadd double %58, %66
  %68 = load double, ptr %5, align 8, !tbaa !11
  %69 = fadd double %68, %67
  store double %69, ptr %5, align 8, !tbaa !11
  %70 = load double, ptr %6, align 8, !tbaa !11
  %71 = fadd double %70, 1.000000e+00
  store double %71, ptr %6, align 8, !tbaa !11
  br label %72

72:                                               ; preds = %51
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %7, align 4, !tbaa !5
  br label %45, !llvm.loop !13

75:                                               ; preds = %50
  %76 = load double, ptr %5, align 8, !tbaa !11
  %77 = load double, ptr %6, align 8, !tbaa !11
  %78 = fdiv double %76, %77
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %80
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [5010 x double], ptr %81, i64 0, i64 %83
  %85 = load double, ptr %84, align 8, !tbaa !11
  %86 = fadd double %85, %78
  store double %86, ptr %84, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %87

87:                                               ; preds = %75
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !15

90:                                               ; preds = %21
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %1, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !16

94:                                               ; preds = %12
  %95 = load i32, ptr @n, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [5010 x double], ptr getelementptr inbounds ([5010 x [5010 x double]], ptr @dp, i64 0, i64 1), i64 0, i64 %96
  %98 = load double, ptr %97, align 8, !tbaa !11
  ret double %98
}

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

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

attributes #0 = { mustprogress 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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local local_unnamed_addr global [5010 x i64], align 16
@dp = external dso_local local_unnamed_addr global [5010 x [5010 x double]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef double @_Z11solve_cubicv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not39 = icmp slt i32 %1, 2
  br i1 %.not39, label %._crit_edge41, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %2 = add nuw i32 %1, 1
  %wide.trip.count53 = zext i32 %2 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %7
  %indvars.iv50 = phi i64 [ 2, %.preheader.preheader ], [ %indvars.iv.next51, %7 ]
  %3 = trunc nuw nsw i64 %indvars.iv50 to i32
  br label %8

._crit_edge41:                                    ; preds = %7, %0
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [5010 x double], ptr getelementptr inbounds (i8, ptr @dp, i64 40080), i64 0, i64 %4
  %6 = load double, ptr %5, align 8, !tbaa !9
  ret double %6

7:                                                ; preds = %._crit_edge
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count53
  br i1 %exitcond54.not, label %._crit_edge41, label %.preheader, !llvm.loop !11

8:                                                ; preds = %.preheader, %._crit_edge
  %indvars.iv47 = phi i32 [ %3, %.preheader ], [ %indvars.iv.next48, %._crit_edge ]
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %9 = sext i32 %indvars.iv47 to i64
  %10 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %9
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = add nsw i64 %indvars.iv, -1
  %13 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = sub nsw i64 %11, %14
  %16 = sitofp i64 %15 to double
  %17 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %indvars.iv, i64 %9
  store double %16, ptr %17, align 8, !tbaa !9
  %.not32.not33 = icmp slt i64 %indvars.iv, %9
  br i1 %.not32.not33, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %8
  %wide.trip.count = zext i32 %indvars.iv47 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %18 = fdiv double %28, %29
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %8
  %19 = phi double [ 0x7FF8000000000000, %8 ], [ %18, %._crit_edge.loopexit ]
  %20 = fadd double %19, %16
  store double %20, ptr %17, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = add nuw nsw i64 %indvars.iv50, %indvars.iv
  %22 = trunc nuw i64 %21 to i32
  %.not31 = icmp slt i32 %1, %22
  %indvars.iv.next48 = add i32 %indvars.iv47, 1
  br i1 %.not31, label %7, label %8, !llvm.loop !15

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv44 = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %indvars.iv.next45, %.lr.ph ]
  %.02435 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %29, %.lr.ph ]
  %.02534 = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %28, %.lr.ph ]
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %23 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %indvars.iv, i64 %indvars.iv44
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %indvars.iv.next45, i64 %9
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fadd double %24, %26
  %28 = fadd double %.02534, %27
  %29 = fadd double %.02435, 1.000000e+00
  %exitcond.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !16
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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" }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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