; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/246 Divison 2/Problem D/D.ll (Z7build_zv)

; 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] }

@z = external dso_local global [1000001 x i32], align 16
@n = external dso_local global i32, align 4
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7build_zv() #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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %6 = call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11) #3
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  store i32 %8, ptr @z, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %9

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

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %112

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

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %19, ptr %3, align 4, !tbaa !5
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %40, %18
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %38

24:                                               ; preds = %20
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sub nsw i32 %25, %26
  %28 = sext i32 %27 to i64
  %29 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %28)
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %33)
  %35 = load i8, ptr %34, align 1, !tbaa !9
  %36 = sext i8 %35 to i32
  %37 = icmp eq i32 %31, %36
  br label %38

38:                                               ; preds = %24, %20
  %39 = phi i1 [ false, %20 ], [ %37, %24 ]
  br i1 %39, label %40, label %43

40:                                               ; preds = %38
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !10

43:                                               ; preds = %38
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sub nsw i32 %44, %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %108

52:                                               ; preds = %14
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sub nsw i32 %53, %54
  store i32 %55, ptr %4, align 4, !tbaa !5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = sub nsw i32 %60, %61
  %63 = add nsw i32 %62, 1
  %64 = icmp slt i32 %59, %63
  br i1 %64, label %65, label %73

65:                                               ; preds = %52
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  br label %107

73:                                               ; preds = %52
  %74 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %74, ptr %2, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %95, %73
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = load i32, ptr @n, align 4, !tbaa !5
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %93

79:                                               ; preds = %75
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = sub nsw i32 %80, %81
  %83 = sext i32 %82 to i64
  %84 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %83)
  %85 = load i8, ptr %84, align 1, !tbaa !9
  %86 = sext i8 %85 to i32
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %88)
  %90 = load i8, ptr %89, align 1, !tbaa !9
  %91 = sext i8 %90 to i32
  %92 = icmp eq i32 %86, %91
  br label %93

93:                                               ; preds = %79, %75
  %94 = phi i1 [ false, %75 ], [ %92, %79 ]
  br i1 %94, label %95, label %98

95:                                               ; preds = %93
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %3, align 4, !tbaa !5
  br label %75, !llvm.loop !12

98:                                               ; preds = %93
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = load i32, ptr %2, align 4, !tbaa !5
  %101 = sub nsw i32 %99, %100
  %102 = load i32, ptr %5, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %103
  store i32 %101, ptr %104, align 4, !tbaa !5
  %105 = load i32, ptr %3, align 4, !tbaa !5
  %106 = add nsw i32 %105, -1
  store i32 %106, ptr %3, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %98, %65
  br label %108

108:                                              ; preds = %107, %43
  br label %109

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

112:                                              ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  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: mustprogress nounwind uwtable
declare noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

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

attributes #0 = { mustprogress 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 = { 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 #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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


; 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] }

@z = external dso_local local_unnamed_addr global [1000001 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7build_zv() local_unnamed_addr #0 {
  %1 = tail call noundef i64 @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11) #1
  %2 = trunc i64 %1 to i32
  store i32 %2, ptr @z, align 16, !tbaa !5
  %3 = icmp sgt i32 %2, 1
  br i1 %3, label %.lr.ph51.preheader, label %._crit_edge

.lr.ph51.preheader:                               ; preds = %0
  %wide.trip.count = and i64 %1, 2147483647
  br label %.lr.ph51

._crit_edge:                                      ; preds = %44, %0
  ret void

.lr.ph51:                                         ; preds = %.lr.ph51.preheader, %44
  %indvars.iv53 = phi i64 [ 1, %.lr.ph51.preheader ], [ %indvars.iv.next54, %44 ]
  %.03549 = phi i32 [ 0, %.lr.ph51.preheader ], [ %.1, %44 ]
  %.03648 = phi i32 [ 0, %.lr.ph51.preheader ], [ %.3, %44 ]
  %indvars60 = trunc i64 %indvars.iv53 to i32
  %4 = sext i32 %.03648 to i64
  %5 = icmp sgt i64 %indvars.iv53, %4
  br i1 %5, label %.preheader, label %22

.preheader:                                       ; preds = %.lr.ph51
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = icmp slt i64 %indvars.iv53, %7
  br i1 %8, label %.lr.ph44, label %.critedge

.lr.ph44:                                         ; preds = %.preheader, %15
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %15 ], [ %indvars.iv53, %.preheader ]
  %9 = sub nuw nsw i64 %indvars.iv55, %indvars.iv53
  %10 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %9)
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %indvars.iv55)
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp eq i8 %11, %13
  br i1 %14, label %15, label %.critedge.loopexit

15:                                               ; preds = %.lr.ph44
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next56, %17
  br i1 %18, label %.lr.ph44, label %.critedge.loopexit, !llvm.loop !10

.critedge.loopexit:                               ; preds = %15, %.lr.ph44
  %.137.lcssa.ph.in = phi i64 [ %indvars.iv55, %.lr.ph44 ], [ %indvars.iv.next56, %15 ]
  %.137.lcssa.ph = trunc i64 %.137.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader
  %.137.lcssa = phi i32 [ %indvars60, %.preheader ], [ %.137.lcssa.ph, %.critedge.loopexit ]
  %19 = sub nsw i32 %.137.lcssa, %indvars60
  %20 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %indvars.iv53
  store i32 %19, ptr %20, align 4, !tbaa !5
  %21 = add nsw i32 %.137.lcssa, -1
  br label %44

22:                                               ; preds = %.lr.ph51
  %23 = sext i32 %.03549 to i64
  %24 = sub nsw i64 %indvars.iv53, %23
  %25 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sub nsw i32 %.03648, %indvars60
  %.not = icmp sgt i32 %26, %27
  br i1 %.not, label %.preheader39, label %30

.preheader39:                                     ; preds = %22
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = icmp slt i32 %.03648, %28
  br i1 %29, label %.lr.ph, label %.critedge2

30:                                               ; preds = %22
  %31 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %indvars.iv53
  store i32 %26, ptr %31, align 4, !tbaa !5
  br label %44

.lr.ph:                                           ; preds = %.preheader39, %38
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ %4, %.preheader39 ]
  %32 = sub nsw i64 %indvars.iv, %indvars.iv53
  %33 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %32)
  %34 = load i8, ptr %33, align 1, !tbaa !9
  %35 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %indvars.iv)
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = icmp eq i8 %34, %36
  br i1 %37, label %38, label %.critedge2.loopexit

38:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next, %40
  br i1 %41, label %.lr.ph, label %.critedge2.loopexit, !llvm.loop !12

.critedge2.loopexit:                              ; preds = %38, %.lr.ph
  %.2.lcssa.ph.in = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next, %38 ]
  %.2.lcssa.ph = trunc i64 %.2.lcssa.ph.in to i32
  %.pre = sub nsw i32 %.2.lcssa.ph, %indvars60
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.preheader39
  %.pre-phi = phi i32 [ %.pre, %.critedge2.loopexit ], [ %27, %.preheader39 ]
  %.2.lcssa = phi i32 [ %.2.lcssa.ph, %.critedge2.loopexit ], [ %.03648, %.preheader39 ]
  %42 = getelementptr inbounds [1000001 x i32], ptr @z, i64 0, i64 %indvars.iv53
  store i32 %.pre-phi, ptr %42, align 4, !tbaa !5
  %43 = add nsw i32 %.2.lcssa, -1
  br label %44

44:                                               ; preds = %.critedge, %.critedge2, %30
  %.3 = phi i32 [ %21, %.critedge ], [ %.03648, %30 ], [ %43, %.critedge2 ]
  %.1 = phi i32 [ %indvars60, %.critedge ], [ %.03549, %30 ], [ %indvars60, %.critedge2 ]
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next54, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph51, !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: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), 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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}


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