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

; 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
@Left = external dso_local global [5010 x [5010 x double]], align 16
@down = external dso_local global [5010 x [5010 x double]], align 16

; 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: mustprogress nounwind uwtable
define dso_local noundef double @_Z5solvev() #1 {
  %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 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 %7

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

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

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

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

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

21:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = add nsw i32 %22, %23
  %25 = sub nsw i32 %24, 1
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = sub nsw i64 %29, %34
  %36 = sitofp i64 %35 to double
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %38
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [5010 x double], ptr %39, i64 0, i64 %41
  store double %36, ptr %42, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [5010 x [5010 x double]], ptr @Left, i64 0, i64 %44
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [5010 x double], ptr %45, i64 0, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [5010 x [5010 x double]], ptr @down, i64 0, i64 %51
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [5010 x double], ptr %52, i64 0, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = fadd double %49, %56
  store double %57, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sub nsw i32 %58, %59
  store i32 %60, ptr %6, align 4, !tbaa !5
  %61 = load double, ptr %5, align 8, !tbaa !11
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sitofp i32 %62 to double
  %64 = fdiv double %61, %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %66
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [5010 x double], ptr %67, i64 0, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = fadd double %71, %64
  store double %72, ptr %70, align 8, !tbaa !11
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [5010 x [5010 x double]], ptr @Left, i64 0, i64 %74
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [5010 x double], ptr %75, i64 0, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %81
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [5010 x double], ptr %82, i64 0, i64 %84
  %86 = load double, ptr %85, align 8, !tbaa !11
  %87 = fadd double %79, %86
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [5010 x [5010 x double]], ptr @Left, i64 0, i64 %89
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [5010 x double], ptr %90, i64 0, i64 %93
  store double %87, ptr %94, align 8, !tbaa !11
  %95 = load i32, ptr %3, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [5010 x [5010 x double]], ptr @down, i64 0, i64 %96
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [5010 x double], ptr %97, i64 0, i64 %99
  %101 = load double, ptr %100, align 8, !tbaa !11
  %102 = load i32, ptr %3, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %103
  %105 = load i32, ptr %4, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [5010 x double], ptr %104, i64 0, i64 %106
  %108 = load double, ptr %107, align 8, !tbaa !11
  %109 = fadd double %101, %108
  %110 = load i32, ptr %3, align 4, !tbaa !5
  %111 = sub nsw i32 %110, 1
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [5010 x [5010 x double]], ptr @down, i64 0, i64 %112
  %114 = load i32, ptr %4, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [5010 x double], ptr %113, i64 0, i64 %115
  store double %109, ptr %116, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, 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 %117

117:                                              ; preds = %21
  %118 = load i32, ptr %3, align 4, !tbaa !5
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !13

120:                                              ; preds = %20
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %1, align 4, !tbaa !5
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %1, align 4, !tbaa !5
  br label %7, !llvm.loop !15

124:                                              ; preds = %11
  %125 = load i32, ptr @n, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [5010 x double], ptr getelementptr inbounds ([5010 x [5010 x double]], ptr @dp, i64 0, i64 1), i64 0, i64 %126
  %128 = load double, ptr %127, align 8, !tbaa !11
  ret double %128
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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}


; 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
@Left = external dso_local local_unnamed_addr global [5010 x [5010 x double]], align 16
@down = 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 @_Z5solvev() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %.not37 = icmp slt i32 %1, 2
  br i1 %.not37, label %._crit_edge, label %.preheader.preheader

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

.preheader:                                       ; preds = %.preheader.preheader, %7
  %indvars.iv42 = phi i64 [ 2, %.preheader.preheader ], [ %indvars.iv.next43, %7 ]
  %indvars.iv = phi i32 [ 1, %.preheader.preheader ], [ %indvars.iv.next, %7 ]
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %3 = uitofp nneg i32 %indvars.iv to double
  br label %8

._crit_edge:                                      ; 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 = %8
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next43, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !11

8:                                                ; preds = %.preheader, %8
  %indvars.iv39 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next40, %8 ]
  %9 = phi i64 [ %indvars.iv42, %.preheader ], [ %32, %8 ]
  %.in = phi i64 [ %indvars.iv.next43, %.preheader ], [ %31, %8 ]
  %sext = shl i64 %9, 32
  %10 = ashr exact i64 %sext, 32
  %11 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = add nsw i64 %indvars.iv39, -1
  %14 = getelementptr inbounds [5010 x i64], ptr @sum, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = sub nsw i64 %12, %15
  %17 = sitofp i64 %16 to double
  %18 = getelementptr inbounds [5010 x [5010 x double]], ptr @dp, i64 0, i64 %indvars.iv39, i64 %10
  %19 = getelementptr inbounds [5010 x [5010 x double]], ptr @Left, i64 0, i64 %indvars.iv39, i64 %10
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds [5010 x [5010 x double]], ptr @down, i64 0, i64 %indvars.iv39, i64 %10
  %22 = load double, ptr %21, align 8, !tbaa !9
  %23 = fadd double %20, %22
  %24 = fdiv double %23, %3
  %25 = fadd double %24, %17
  store double %25, ptr %18, align 8, !tbaa !9
  %26 = fadd double %20, %25
  %27 = and i64 %.in, 4294967295
  %28 = getelementptr inbounds [5010 x [5010 x double]], ptr @Left, i64 0, i64 %indvars.iv39, i64 %27
  store double %26, ptr %28, align 8, !tbaa !9
  %29 = fadd double %22, %25
  %30 = getelementptr inbounds [5010 x [5010 x double]], ptr @down, i64 0, i64 %13, i64 %10
  store double %29, ptr %30, align 8, !tbaa !9
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %31 = add nuw nsw i64 %indvars.iv.next40, %indvars.iv42
  %32 = add nuw nsw i64 %indvars.iv39, %indvars.iv42
  %33 = trunc nuw i64 %32 to i32
  %.not35 = icmp slt i32 %1, %33
  br i1 %.not35, label %7, label %8, !llvm.loop !15
}

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}


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