; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Week of Code/Week 24/Problem E/E.ll (Z5resetv)

; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1aB5cxx11 = external dso_local global [51 x %"class.std::__cxx11::basic_string"], align 16
@_Z1bB5cxx11 = external dso_local global [51 x %"class.std::__cxx11::basic_string"], align 16
@dp1 = external dso_local global [1001 x [1001 x [2 x i32]]], align 16
@dp2 = external dso_local global [1001 x [1001 x [2 x i32]]], align 16
@block1 = external dso_local global [1001 x i32], align 16
@block2 = external dso_local global [1001 x i32], align 16
@n = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5resetv() #0 {
  %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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = 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 %9

9:                                                ; preds = %51, %0
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1001
  br i1 %11, label %13, label %12

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

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

14:                                               ; preds = %47, %13
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 1001
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1001 x [1001 x [2 x i32]]], ptr @dp1, i64 0, i64 %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1001 x [2 x i32]], ptr %21, i64 0, i64 %23
  %25 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 1
  store i32 0, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1001 x [1001 x [2 x i32]]], ptr @dp1, i64 0, i64 %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1001 x [2 x i32]], ptr %28, i64 0, i64 %30
  %32 = getelementptr inbounds [2 x i32], ptr %31, i64 0, i64 0
  store i32 0, ptr %32, align 8, !tbaa !5
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1001 x [1001 x [2 x i32]]], ptr @dp2, i64 0, i64 %34
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1001 x [2 x i32]], ptr %35, i64 0, i64 %37
  %39 = getelementptr inbounds [2 x i32], ptr %38, i64 0, i64 1
  store i32 0, ptr %39, align 4, !tbaa !5
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1001 x [1001 x [2 x i32]]], ptr @dp2, i64 0, i64 %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1001 x [2 x i32]], ptr %42, i64 0, i64 %44
  %46 = getelementptr inbounds [2 x i32], ptr %45, i64 0, i64 0
  store i32 0, ptr %46, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %18
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !9

50:                                               ; preds = %17
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %1, align 4, !tbaa !5
  br label %9, !llvm.loop !11

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

55:                                               ; preds = %80, %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %83

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

61:                                               ; preds = %76, %60
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [51 x %"class.std::__cxx11::basic_string"], ptr @_Z1aB5cxx11, i64 0, i64 %65
  %67 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %66) #2
  %68 = icmp ult i64 %63, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %61
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %79

70:                                               ; preds = %61
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds [1001 x i32], ptr @block1, i64 0, i64 %74
  store i32 %71, ptr %75, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %70
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %6, align 4, !tbaa !5
  br label %61, !llvm.loop !12

79:                                               ; preds = %69
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !5
  br label %55, !llvm.loop !13

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

84:                                               ; preds = %109, %83
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = icmp slt i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  store i32 14, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %112

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

90:                                               ; preds = %105, %89
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [51 x %"class.std::__cxx11::basic_string"], ptr @_Z1bB5cxx11, i64 0, i64 %94
  %96 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %95) #2
  %97 = icmp ult i64 %92, %96
  br i1 %97, label %99, label %98

98:                                               ; preds = %90
  store i32 17, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %108

99:                                               ; preds = %90
  %100 = load i32, ptr %7, align 4, !tbaa !5
  %101 = load i32, ptr %4, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %4, align 4, !tbaa !5
  %103 = sext i32 %101 to i64
  %104 = getelementptr inbounds [1001 x i32], ptr @block2, i64 0, i64 %103
  store i32 %100, ptr %104, align 4, !tbaa !5
  br label %105

105:                                              ; preds = %99
  %106 = load i32, ptr %8, align 4, !tbaa !5
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %8, align 4, !tbaa !5
  br label %90, !llvm.loop !14

108:                                              ; preds = %98
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr %7, align 4, !tbaa !5
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %7, align 4, !tbaa !5
  br label %84, !llvm.loop !15

112:                                              ; preds = %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  ret void
}

; 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

; Function Attrs: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32)) #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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


; 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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1aB5cxx11 = external dso_local global [51 x %"class.std::__cxx11::basic_string"], align 16
@_Z1bB5cxx11 = external dso_local global [51 x %"class.std::__cxx11::basic_string"], align 16
@dp1 = external dso_local local_unnamed_addr global [1001 x [1001 x [2 x i32]]], align 16
@dp2 = external dso_local local_unnamed_addr global [1001 x [1001 x [2 x i32]]], align 16
@block1 = external dso_local local_unnamed_addr global [1001 x i32], align 16
@block2 = external dso_local local_unnamed_addr global [1001 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5resetv() local_unnamed_addr #0 {
.preheader34:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8016008) @dp1, i8 0, i64 8016008, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8016008) @dp2, i8 0, i64 8016008, i1 false), !tbaa !5
  %0 = load i32, ptr @n, align 4, !tbaa !5
  %1 = icmp sgt i32 %0, 0
  br i1 %1, label %.preheader33, label %._crit_edge49

.preheader33:                                     ; preds = %.preheader34, %._crit_edge
  %indvars.iv60 = phi i64 [ %indvars.iv.next61, %._crit_edge ], [ 0, %.preheader34 ]
  %.02940 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %.preheader34 ]
  %2 = getelementptr inbounds [51 x %"class.std::__cxx11::basic_string"], ptr @_Z1aB5cxx11, i64 0, i64 %indvars.iv60
  %3 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #2
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader33
  %4 = sext i32 %.02940 to i64
  %5 = trunc nuw nsw i64 %indvars.iv60 to i32
  br label %.lr.ph

.preheader32:                                     ; preds = %._crit_edge
  %6 = icmp sgt i32 %8, 0
  br i1 %6, label %.preheader, label %._crit_edge49

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %7 = trunc nsw i64 %indvars.iv.next56 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader33
  %.1.lcssa = phi i32 [ %.02940, %.preheader33 ], [ %7, %._crit_edge.loopexit ]
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvars.iv.next61, %9
  br i1 %10, label %.preheader33, label %.preheader32, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv55 = phi i64 [ %4, %.lr.ph.preheader ], [ %indvars.iv.next56, %.lr.ph ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %indvars.iv.next56 = add nsw i64 %indvars.iv55, 1
  %11 = getelementptr inbounds [1001 x i32], ptr @block1, i64 0, i64 %indvars.iv55
  store i32 %5, ptr %11, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %2) #2
  %13 = icmp ugt i64 %12, %indvars.iv.next
  br i1 %13, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

.preheader:                                       ; preds = %.preheader32, %._crit_edge45
  %indvars.iv70 = phi i64 [ %indvars.iv.next71, %._crit_edge45 ], [ 0, %.preheader32 ]
  %.247 = phi i32 [ %.3.lcssa, %._crit_edge45 ], [ 0, %.preheader32 ]
  %14 = getelementptr inbounds [51 x %"class.std::__cxx11::basic_string"], ptr @_Z1bB5cxx11, i64 0, i64 %indvars.iv70
  %15 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %14) #2
  %.not50 = icmp eq i64 %15, 0
  br i1 %.not50, label %._crit_edge45, label %.lr.ph44.preheader

.lr.ph44.preheader:                               ; preds = %.preheader
  %16 = sext i32 %.247 to i64
  %17 = trunc nuw nsw i64 %indvars.iv70 to i32
  br label %.lr.ph44

._crit_edge49:                                    ; preds = %._crit_edge45, %.preheader34, %.preheader32
  ret void

._crit_edge45.loopexit:                           ; preds = %.lr.ph44
  %18 = trunc nsw i64 %indvars.iv.next66 to i32
  br label %._crit_edge45

._crit_edge45:                                    ; preds = %._crit_edge45.loopexit, %.preheader
  %.3.lcssa = phi i32 [ %.247, %.preheader ], [ %18, %._crit_edge45.loopexit ]
  %indvars.iv.next71 = add nuw nsw i64 %indvars.iv70, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next71, %20
  br i1 %21, label %.preheader, label %._crit_edge49, !llvm.loop !12

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %.lr.ph44
  %indvars.iv65 = phi i64 [ %16, %.lr.ph44.preheader ], [ %indvars.iv.next66, %.lr.ph44 ]
  %indvars.iv63 = phi i64 [ 0, %.lr.ph44.preheader ], [ %indvars.iv.next64, %.lr.ph44 ]
  %indvars.iv.next66 = add nsw i64 %indvars.iv65, 1
  %22 = getelementptr inbounds [1001 x i32], ptr @block2, i64 0, i64 %indvars.iv65
  store i32 %17, ptr %22, align 4, !tbaa !5
  %indvars.iv.next64 = add nuw nsw i64 %indvars.iv63, 1
  %23 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) %14) #2
  %24 = icmp ugt i64 %23, %indvars.iv.next64
  br i1 %24, label %.lr.ph44, label %._crit_edge45.loopexit, !llvm.loop !13
}

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

; 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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