; LLVM IR from VastoLorde95/Competitive-Programming :: Codejam/2016/Round 2/Problem B/B.ll (Z3getRSt6vectorIiSaIiEE)

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

@p = external dso_local global [201 x double], align 16
@dp = external dso_local global [201 x [201 x x86_fp80]], align 16
@k = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef x86_fp80 @_Z3getRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @dp, i8 0, i64 646416, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #4
  %9 = trunc i64 %8 to i32
  store i32 %9, ptr %3, align 4, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef 0) #4
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = fpext double %15 to x86_fp80
  store x86_fp80 %16, ptr getelementptr inbounds ([201 x x86_fp80], ptr @dp, i64 0, i64 1), align 16, !tbaa !13
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef 0) #4
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = fsub double 1.000000e+00, %22
  %24 = fpext double %23 to x86_fp80
  store x86_fp80 %24, ptr @dp, align 16, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %116, %1
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %119

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %112, %30
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  %35 = icmp sle i32 %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %115

37:                                               ; preds = %31
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %40, label %85

40:                                               ; preds = %37
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [201 x x86_fp80], ptr %44, i64 0, i64 %47
  %49 = load x86_fp80, ptr %48, align 16, !tbaa !13
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %50, i64 noundef %52) #4
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fpext double %57 to x86_fp80
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %61
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [201 x x86_fp80], ptr %62, i64 0, i64 %64
  %66 = load x86_fp80, ptr %65, align 16, !tbaa !13
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %67, i64 noundef %69) #4
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = fsub double 1.000000e+00, %74
  %76 = fpext double %75 to x86_fp80
  %77 = fmul x86_fp80 %66, %76
  %78 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %49, x86_fp80 %58, x86_fp80 %77)
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %80
  %82 = load i32, ptr %6, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [201 x x86_fp80], ptr %81, i64 0, i64 %83
  store x86_fp80 %78, ptr %84, align 16, !tbaa !13
  br label %111

85:                                               ; preds = %37
  %86 = load i32, ptr %4, align 4, !tbaa !9
  %87 = sub nsw i32 %86, 1
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %88
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [201 x x86_fp80], ptr %89, i64 0, i64 %91
  %93 = load x86_fp80, ptr %92, align 16, !tbaa !13
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = load i32, ptr %4, align 4, !tbaa !9
  %96 = sext i32 %95 to i64
  %97 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %94, i64 noundef %96) #4
  %98 = load i32, ptr %97, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %99
  %101 = load double, ptr %100, align 8, !tbaa !11
  %102 = fsub double 1.000000e+00, %101
  %103 = fpext double %102 to x86_fp80
  %104 = fmul x86_fp80 %93, %103
  %105 = load i32, ptr %4, align 4, !tbaa !9
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %106
  %108 = load i32, ptr %6, align 4, !tbaa !9
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [201 x x86_fp80], ptr %107, i64 0, i64 %109
  store x86_fp80 %104, ptr %110, align 16, !tbaa !13
  br label %111

111:                                              ; preds = %85, %40
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %6, align 4, !tbaa !9
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %6, align 4, !tbaa !9
  br label %31, !llvm.loop !15

115:                                              ; preds = %36
  br label %116

116:                                              ; preds = %115
  %117 = load i32, ptr %4, align 4, !tbaa !9
  %118 = add nsw i32 %117, 1
  store i32 %118, ptr %4, align 4, !tbaa !9
  br label %25, !llvm.loop !17

119:                                              ; preds = %29
  %120 = load i32, ptr %3, align 4, !tbaa !9
  %121 = sub nsw i32 %120, 1
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %122
  %124 = load i32, ptr @k, align 4, !tbaa !9
  %125 = sdiv i32 %124, 2
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [201 x x86_fp80], ptr %123, i64 0, i64 %126
  %128 = load x86_fp80, ptr %127, align 16, !tbaa !13
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret x86_fp80 %128
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare x86_fp80 @llvm.fmuladd.f80(x86_fp80, x86_fp80, x86_fp80) #3

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@p = external dso_local local_unnamed_addr global [201 x double], align 16
@dp = external dso_local local_unnamed_addr global [201 x [201 x x86_fp80]], align 16
@k = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef x86_fp80 @_Z3getRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(646416) @dp, i8 0, i64 646416, i1 false)
  %2 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %3 = trunc i64 %2 to i32
  %4 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %6
  %8 = load double, ptr %7, align 8, !tbaa !9
  %9 = fpext double %8 to x86_fp80
  store x86_fp80 %9, ptr getelementptr inbounds (i8, ptr @dp, i64 16), align 16, !tbaa !11
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #3
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %12
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = fsub double 1.000000e+00, %14
  %16 = fpext double %15 to x86_fp80
  store x86_fp80 %16, ptr @dp, align 16, !tbaa !11
  %17 = icmp sgt i32 %3, 1
  br i1 %17, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %1
  %wide.trip.count43 = and i64 %2, 2147483647
  br label %.peel.next

.loopexit:                                        ; preds = %37
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond44.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count43
  br i1 %exitcond44.not, label %._crit_edge, label %.peel.next, !llvm.loop !13

.peel.next:                                       ; preds = %.loopexit, %.preheader.preheader
  %indvars.iv38 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next39, %.loopexit ]
  %indvars.iv36 = phi i64 [ 3, %.preheader.preheader ], [ %indvars.iv.next37, %.loopexit ]
  %18 = add nsw i64 %indvars.iv38, -1
  %19 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %18, i64 0
  %20 = load x86_fp80, ptr %19, align 16, !tbaa !11
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv38) #3
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fsub double 1.000000e+00, %25
  %27 = fpext double %26 to x86_fp80
  %28 = fmul x86_fp80 %20, %27
  %29 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %indvars.iv38, i64 0
  store x86_fp80 %28, ptr %29, align 16
  br label %37

._crit_edge:                                      ; preds = %.loopexit, %1
  %30 = shl i64 %2, 32
  %sext = add i64 %30, -4294967296
  %31 = ashr exact i64 %sext, 32
  %32 = load i32, ptr @k, align 4, !tbaa !5
  %33 = sdiv i32 %32, 2
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %31, i64 %34
  %36 = load x86_fp80, ptr %35, align 16, !tbaa !11
  ret x86_fp80 %36

37:                                               ; preds = %.peel.next, %37
  %indvars.iv = phi i64 [ 1, %.peel.next ], [ %indvars.iv.next, %37 ]
  %38 = add nsw i64 %indvars.iv, -1
  %39 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %18, i64 %38
  %40 = load x86_fp80, ptr %39, align 16, !tbaa !11
  %41 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv38) #3
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %18, i64 %indvars.iv
  %47 = load x86_fp80, ptr %46, align 16, !tbaa !11
  %48 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv38) #3
  %49 = fpext double %45 to x86_fp80
  %50 = load i32, ptr %48, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [201 x double], ptr @p, i64 0, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = fsub double 1.000000e+00, %53
  %55 = fpext double %54 to x86_fp80
  %56 = fmul x86_fp80 %47, %55
  %57 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %40, x86_fp80 %49, x86_fp80 %56)
  %58 = getelementptr inbounds [201 x [201 x x86_fp80]], ptr @dp, i64 0, i64 %indvars.iv38, i64 %indvars.iv
  store x86_fp80 %57, ptr %58, align 16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %indvars.iv36
  br i1 %exitcond, label %.loopexit, label %37, !llvm.loop !15
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare x86_fp80 @llvm.fmuladd.f80(x86_fp80, x86_fp80, x86_fp80) #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14, !16}
!16 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass