; LLVM IR from upupming/algorithm :: kick-start/2020/2020G-D.ll (Z6solve2v)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@n = external dso_local global i32, align 4
@sum = external dso_local global %"class.std::vector", align 8
@dp = external dso_local global [5050 x [5050 x double]], align 16
@dphs = external dso_local global [5050 x double], align 16
@dpvs = external dso_local global [5050 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
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

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

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %21

11:                                               ; preds = %6
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [5050 x double], ptr @dpvs, i64 0, i64 %13
  store double 0.000000e+00, ptr %14, align 8, !tbaa !9
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5050 x double], ptr @dphs, i64 0, i64 %16
  store double 0.000000e+00, ptr %17, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !11

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

22:                                               ; preds = %110, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %106, %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %28
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %109

35:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  store i32 %38, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5050 x double], ptr @dphs, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [5050 x double], ptr @dpvs, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = fadd double %42, %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %49
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [5050 x double], ptr %50, i64 0, i64 %52
  store double %47, ptr %53, align 8, !tbaa !9
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %55
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [5050 x double], ptr %56, i64 0, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = sitofp i32 %61 to double
  %63 = fdiv double %60, %62
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @sum, i64 noundef %66) #2
  %68 = load i64, ptr %67, align 8, !tbaa !13
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @sum, i64 noundef %70) #2
  %72 = load i64, ptr %71, align 8, !tbaa !13
  %73 = sub nsw i64 %68, %72
  %74 = sitofp i64 %73 to double
  %75 = fadd double %63, %74
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %77
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [5050 x double], ptr %78, i64 0, i64 %80
  store double %75, ptr %81, align 8, !tbaa !9
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %83
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [5050 x double], ptr %84, i64 0, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !9
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [5050 x double], ptr @dphs, i64 0, i64 %90
  %92 = load double, ptr %91, align 8, !tbaa !9
  %93 = fadd double %92, %88
  store double %93, ptr %91, align 8, !tbaa !9
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %95
  %97 = load i32, ptr %5, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [5050 x double], ptr %96, i64 0, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !9
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [5050 x double], ptr @dpvs, i64 0, i64 %102
  %104 = load double, ptr %103, align 8, !tbaa !9
  %105 = fadd double %104, %100
  store double %105, ptr %103, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %106

106:                                              ; preds = %35
  %107 = load i32, ptr %4, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %4, align 4, !tbaa !5
  br label %28, !llvm.loop !15

109:                                              ; preds = %34
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %2, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %2, align 4, !tbaa !5
  br label %22, !llvm.loop !16

113:                                              ; preds = %26
  %114 = load i32, ptr @n, align 4, !tbaa !5
  %115 = sub nsw i32 %114, 1
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [5050 x double], ptr @dp, i64 0, i64 %116
  %118 = load double, ptr %117, align 8, !tbaa !9
  ret double %118
}

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 = !{!"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}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@n = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local global %"class.std::vector", align 8
@dp = external dso_local local_unnamed_addr global [5050 x [5050 x double]], align 16
@dphs = external dso_local local_unnamed_addr global [5050 x double], align 16
@dpvs = external dso_local local_unnamed_addr global [5050 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z6solve2v() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.preheader31, label %._crit_edge36

.preheader31:                                     ; preds = %0
  %3 = zext nneg i32 %1 to i64
  %4 = shl nuw nsw i64 %3, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @dpvs, i8 0, i64 %4, i1 false), !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @dphs, i8 0, i64 %4, i1 false), !tbaa !9
  %.not = icmp eq i32 %1, 1
  br i1 %.not, label %._crit_edge36, label %.preheader

.preheader:                                       ; preds = %.preheader31, %._crit_edge
  %5 = phi i32 [ %14, %._crit_edge ], [ %1, %.preheader31 ]
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %._crit_edge ], [ 1, %.preheader31 ]
  %6 = sext i32 %5 to i64
  %7 = icmp slt i64 %indvars.iv40, %6
  br i1 %7, label %.lr.ph34, label %._crit_edge

.lr.ph34:                                         ; preds = %.preheader
  %8 = trunc nuw nsw i64 %indvars.iv40 to i32
  %9 = uitofp nneg i32 %8 to double
  br label %16

._crit_edge36:                                    ; preds = %._crit_edge, %0, %.preheader31
  %.lcssa = phi i32 [ 1, %.preheader31 ], [ %1, %0 ], [ %14, %._crit_edge ]
  %10 = add nsw i32 %.lcssa, -1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [5050 x double], ptr @dp, i64 0, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !9
  ret double %13

._crit_edge.loopexit:                             ; preds = %16
  %.pre = sext i32 %37 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.pre-phi = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %6, %.preheader ]
  %14 = phi i32 [ %37, %._crit_edge.loopexit ], [ %5, %.preheader ]
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %15 = icmp slt i64 %indvars.iv.next41, %.pre-phi
  br i1 %15, label %.preheader, label %._crit_edge36, !llvm.loop !11

16:                                               ; preds = %.lr.ph34, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph34 ], [ %indvars.iv.next, %16 ]
  %17 = add nuw nsw i64 %indvars.iv, %indvars.iv40
  %18 = getelementptr inbounds [5050 x double], ptr @dphs, i64 0, i64 %indvars.iv
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds [5050 x double], ptr @dpvs, i64 0, i64 %17
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fadd double %19, %21
  %23 = getelementptr inbounds [5050 x [5050 x double]], ptr @dp, i64 0, i64 %indvars.iv, i64 %17
  store double %22, ptr %23, align 8, !tbaa !9
  %24 = fdiv double %22, %9
  %25 = add nuw nsw i64 %17, 1
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @sum, i64 noundef %25) #2
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @sum, i64 noundef %indvars.iv) #2
  %29 = load i64, ptr %28, align 8, !tbaa !13
  %30 = sub nsw i64 %27, %29
  %31 = sitofp i64 %30 to double
  %32 = fadd double %24, %31
  store double %32, ptr %23, align 8, !tbaa !9
  %33 = load double, ptr %18, align 8, !tbaa !9
  %34 = fadd double %33, %32
  store double %34, ptr %18, align 8, !tbaa !9
  %35 = load double, ptr %20, align 8, !tbaa !9
  %36 = fadd double %32, %35
  store double %36, ptr %20, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sub nsw i32 %37, %8
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next, %39
  br i1 %40, label %16, label %._crit_edge.loopexit, !llvm.loop !15
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }
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 = !{!"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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass