; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/CPCRC1C/A.ll (Z3getSt6vectorIiSaIiEEb)

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

@sum = external dso_local global [20 x [2 x i64]], align 16
@cnt = external dso_local global [20 x [2 x i64]], 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 i64 @_Z3getSt6vectorIiSaIiEEb(ptr noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %15 = zext i1 %1 to i8
  store i8 %15, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %16 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %5, align 4, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 16 @sum, i8 0, i64 320, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @cnt, i8 0, i64 320, i1 false)
  store i64 1, ptr getelementptr inbounds ([2 x i64], ptr @cnt, i64 0, i64 1), align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %111, %2
  %19 = load i32, ptr %6, align 4, !tbaa !11
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %107, %23
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = icmp slt i32 %25, 2
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %110

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20 x [2 x i64]], ptr @cnt, i64 0, i64 %30
  %32 = load i32, ptr %8, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2 x i64], ptr %31, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !13
  store i64 %35, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %36 = load i32, ptr %6, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %37
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2 x i64], ptr %38, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !13
  store i64 %42, ptr %10, align 8, !tbaa !13
  %43 = load i64, ptr %9, align 8, !tbaa !13
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %28
  store i32 7, ptr %7, align 4
  br label %104

46:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %47 = load i32, ptr %8, align 4, !tbaa !11
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %46
  %50 = load i32, ptr %6, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %51) #3
  %53 = load i32, ptr %52, align 4, !tbaa !11
  br label %55

54:                                               ; preds = %46
  br label %55

55:                                               ; preds = %54, %49
  %56 = phi i32 [ %53, %49 ], [ 9, %54 ]
  store i32 %56, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %100, %55
  %58 = load i32, ptr %12, align 4, !tbaa !11
  %59 = load i32, ptr %11, align 4, !tbaa !11
  %60 = icmp sle i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %103

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %63 = load i32, ptr %8, align 4, !tbaa !11
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %72

65:                                               ; preds = %62
  %66 = load i32, ptr %12, align 4, !tbaa !11
  %67 = load i32, ptr %6, align 4, !tbaa !11
  %68 = sext i32 %67 to i64
  %69 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %68) #3
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = icmp eq i32 %66, %70
  br label %72

72:                                               ; preds = %65, %62
  %73 = phi i1 [ false, %62 ], [ %71, %65 ]
  %74 = zext i1 %73 to i32
  store i32 %74, ptr %13, align 4, !tbaa !11
  %75 = load i64, ptr %10, align 8, !tbaa !13
  %76 = load i64, ptr %9, align 8, !tbaa !13
  %77 = load i32, ptr %12, align 4, !tbaa !11
  %78 = sext i32 %77 to i64
  %79 = mul nsw i64 %76, %78
  %80 = add nsw i64 %75, %79
  %81 = load i32, ptr %6, align 4, !tbaa !11
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %83
  %85 = load i32, ptr %13, align 4, !tbaa !11
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [2 x i64], ptr %84, i64 0, i64 %86
  %88 = load i64, ptr %87, align 8, !tbaa !13
  %89 = add nsw i64 %88, %80
  store i64 %89, ptr %87, align 8, !tbaa !13
  %90 = load i64, ptr %9, align 8, !tbaa !13
  %91 = load i32, ptr %6, align 4, !tbaa !11
  %92 = add nsw i32 %91, 1
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [20 x [2 x i64]], ptr @cnt, i64 0, i64 %93
  %95 = load i32, ptr %13, align 4, !tbaa !11
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [2 x i64], ptr %94, i64 0, i64 %96
  %98 = load i64, ptr %97, align 8, !tbaa !13
  %99 = add nsw i64 %98, %90
  store i64 %99, ptr %97, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %100

100:                                              ; preds = %72
  %101 = load i32, ptr %12, align 4, !tbaa !11
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %12, align 4, !tbaa !11
  br label %57, !llvm.loop !15

103:                                              ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  store i32 0, ptr %7, align 4
  br label %104

104:                                              ; preds = %103, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %105 = load i32, ptr %7, align 4
  switch i32 %105, label %133 [
    i32 0, label %106
    i32 7, label %107
  ]

106:                                              ; preds = %104
  br label %107

107:                                              ; preds = %106, %104
  %108 = load i32, ptr %8, align 4, !tbaa !11
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %8, align 4, !tbaa !11
  br label %24, !llvm.loop !17

110:                                              ; preds = %27
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %6, align 4, !tbaa !11
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %6, align 4, !tbaa !11
  br label %18, !llvm.loop !18

114:                                              ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %115 = load i32, ptr %5, align 4, !tbaa !11
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %116
  %118 = getelementptr inbounds [2 x i64], ptr %117, i64 0, i64 0
  %119 = load i64, ptr %118, align 16, !tbaa !13
  %120 = load i8, ptr %4, align 1, !tbaa !9, !range !19, !noundef !20
  %121 = trunc i8 %120 to i1
  br i1 %121, label %122, label %128

122:                                              ; preds = %114
  %123 = load i32, ptr %5, align 4, !tbaa !11
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %124
  %126 = getelementptr inbounds [2 x i64], ptr %125, i64 0, i64 1
  %127 = load i64, ptr %126, align 8, !tbaa !13
  br label %129

128:                                              ; preds = %114
  br label %129

129:                                              ; preds = %128, %122
  %130 = phi i64 [ %127, %122 ], [ 0, %128 ]
  %131 = add nsw i64 %119, %130
  store i64 %131, ptr %14, align 8, !tbaa !13
  %132 = load i64, ptr %14, align 8, !tbaa !13
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i64 %132

133:                                              ; preds = %104
  unreachable
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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) #1 align 2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = !{i8 0, i8 2}
!20 = !{}


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

@sum = external dso_local local_unnamed_addr global [20 x [2 x i64]], align 16
@cnt = external dso_local local_unnamed_addr global [20 x [2 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z3getSt6vectorIiSaIiEEb(ptr noundef nonnull %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2
  %4 = trunc i64 %3 to i32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(320) @sum, i8 0, i64 320, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(320) @cnt, i8 0, i64 320, i1 false)
  store i64 1, ptr getelementptr inbounds (i8, ptr @cnt, i64 8), align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %2
  %wide.trip.count = and i64 %3, 2147483647
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit.1
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %.loopexit.1 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %6 = getelementptr inbounds [20 x [2 x i64]], ptr @cnt, i64 0, i64 %indvars.iv, i64 0
  %7 = load i64, ptr %6, align 16, !tbaa !5
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %.loopexit, label %.lr.ph.split.us

._crit_edge:                                      ; preds = %.loopexit.1, %2
  %sext = shl i64 %3, 32
  %8 = ashr exact i64 %sext, 32
  %9 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %8
  %10 = load i64, ptr %9, align 16, !tbaa !5
  br i1 %1, label %44, label %47

.lr.ph.split.us:                                  ; preds = %.preheader
  %11 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %indvars.iv, i64 0
  %12 = load i64, ptr %11, align 16, !tbaa !5
  %13 = getelementptr inbounds [20 x [2 x i64]], ptr @cnt, i64 0, i64 %indvars.iv.next, i64 0
  %14 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %indvars.iv.next, i64 0
  %.promoted = load i64, ptr %14, align 16, !tbaa !5
  %.promoted38 = load i64, ptr %13, align 16, !tbaa !5
  %15 = add i64 %12, %7
  %16 = mul i64 %15, 9
  %17 = mul i64 %7, 36
  %18 = mul i64 %7, 10
  %19 = add i64 %12, %.promoted
  %20 = add i64 %19, %16
  %21 = add i64 %20, %17
  %22 = add i64 %.promoted38, %18
  store i64 %21, ptr %14, align 16, !tbaa !5
  store i64 %22, ptr %13, align 16, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.split.us, %.preheader
  %23 = getelementptr inbounds [20 x [2 x i64]], ptr @cnt, i64 0, i64 %indvars.iv, i64 1
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %indvars.iv, i64 1
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %.not.1 = icmp eq i64 %24, 0
  br i1 %.not.1, label %.loopexit.1, label %27

27:                                               ; preds = %.loopexit
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #2
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %.not3536.1 = icmp slt i32 %29, 0
  br i1 %.not3536.1, label %.loopexit.1, label %.lr.ph.split.preheader.1

.lr.ph.split.preheader.1:                         ; preds = %27
  %30 = add nuw i32 %29, 1
  %wide.trip.count.1 = zext i32 %30 to i64
  br label %.lr.ph.split.1

.lr.ph.split.1:                                   ; preds = %.lr.ph.split.1, %.lr.ph.split.preheader.1
  %indvars.iv.1 = phi i64 [ 0, %.lr.ph.split.preheader.1 ], [ %indvars.iv.next.1, %.lr.ph.split.1 ]
  %31 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #2
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = icmp eq i64 %indvars.iv.1, %33
  %35 = mul nsw i64 %24, %indvars.iv.1
  %36 = add nsw i64 %35, %26
  %37 = zext i1 %34 to i64
  %38 = getelementptr inbounds [20 x [2 x i64]], ptr @sum, i64 0, i64 %indvars.iv.next, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = add nsw i64 %36, %39
  store i64 %40, ptr %38, align 8, !tbaa !5
  %41 = getelementptr inbounds [20 x [2 x i64]], ptr @cnt, i64 0, i64 %indvars.iv.next, i64 %37
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = add nsw i64 %42, %24
  store i64 %43, ptr %41, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %exitcond.1.not = icmp eq i64 %indvars.iv.next.1, %wide.trip.count.1
  br i1 %exitcond.1.not, label %.loopexit.1, label %.lr.ph.split.1, !llvm.loop !11

.loopexit.1:                                      ; preds = %.lr.ph.split.1, %27, %.loopexit
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !13

44:                                               ; preds = %._crit_edge
  %45 = getelementptr inbounds i8, ptr %9, i64 8
  %46 = load i64, ptr %45, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %._crit_edge, %44
  %48 = phi i64 [ %46, %44 ], [ 0, %._crit_edge ]
  %49 = add nsw i64 %48, %10
  ret i64 %49
}

; 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 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 nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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