; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/190 Division 1/Problem B/B.ll (Z3allv)

; 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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@m = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@used = external dso_local global [101 x i32], align 16
@a = external dso_local global %"class.std::vector", align 8
@d = external dso_local global %"class.std::vector", align 8
@c = external dso_local global %"class.std::vector", align 8

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

; 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 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 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4findi(i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3allv() #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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %9 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @a) #2
  %10 = trunc i64 %9 to i32
  store i32 %10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %11 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @d) #2
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %3, align 4, !tbaa !5
  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 %13

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

17:                                               ; preds = %13
  store i32 2, ptr %6, align 4
  br label %31

18:                                               ; preds = %13
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @d, i64 noundef %20) #2
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = call noundef i32 @_Z4findi(i32 noundef %23)
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %31

27:                                               ; preds = %18
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !9

31:                                               ; preds = %26, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %32 = load i32, ptr %6, align 4
  switch i32 %32, label %90 [
    i32 2, label %33
  ]

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

34:                                               ; preds = %60, %33
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 5, ptr %6, align 4
  br label %63

39:                                               ; preds = %34
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %41) #2
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = call noundef i32 @_Z4findi(i32 noundef %43)
  store i32 %44, ptr @x, align 4, !tbaa !5
  %45 = load i32, ptr @x, align 4, !tbaa !5
  %46 = icmp eq i32 %45, -1
  br i1 %46, label %47, label %48

47:                                               ; preds = %39
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %63

48:                                               ; preds = %39
  %49 = load i32, ptr @x, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @c, i64 noundef %50) #2
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %54) #2
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = sub nsw i32 %52, %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, %57
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %48
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !5
  br label %34, !llvm.loop !11

63:                                               ; preds = %47, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %64 = load i32, ptr %6, align 4
  switch i32 %64, label %90 [
    i32 5, label %65
  ]

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

66:                                               ; preds = %85, %65
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = load i32, ptr @m, align 4, !tbaa !5
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %88

71:                                               ; preds = %66
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [101 x i32], ptr @used, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %84, label %77

77:                                               ; preds = %71
  %78 = load i32, ptr %8, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @c, i64 noundef %79) #2
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = add nsw i32 %82, %81
  store i32 %83, ptr %4, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %77, %71
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %8, align 4, !tbaa !5
  br label %66, !llvm.loop !12

88:                                               ; preds = %70
  %89 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %89, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %90

90:                                               ; preds = %88, %63, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@m = external dso_local local_unnamed_addr global i32, align 4
@x = external dso_local local_unnamed_addr global i32, align 4
@used = external dso_local local_unnamed_addr global [101 x i32], align 16
@a = external dso_local global %"class.std::vector", align 8
@d = external dso_local global %"class.std::vector", align 8
@c = external dso_local global %"class.std::vector", align 8

; 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 nounwind uwtable
declare dso_local noundef i32 @_Z4findi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3allv() local_unnamed_addr #0 {
  %1 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @a) #1
  %2 = trunc i64 %1 to i32
  %3 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @d) #1
  %4 = trunc i64 %3 to i32
  %.not36 = icmp sgt i32 %4, 0
  br i1 %.not36, label %.lr.ph.preheader, label %.critedge.preheader

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

5:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge.preheader, label %.lr.ph, !llvm.loop !5

.critedge.preheader:                              ; preds = %5, %0
  %.not2938 = icmp sgt i32 %2, 0
  br i1 %.not2938, label %.lr.ph41.preheader, label %.critedge32.preheader

.lr.ph41.preheader:                               ; preds = %.critedge.preheader
  %wide.trip.count52 = and i64 %1, 2147483647
  br label %.lr.ph41

.lr.ph:                                           ; preds = %.lr.ph.preheader, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %5 ]
  %6 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @d, i64 noundef %indvars.iv) #1
  %7 = load i32, ptr %6, align 4, !tbaa !7
  %8 = add nsw i32 %7, 1
  %9 = tail call noundef i32 @_Z4findi(i32 noundef %8)
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %.loopexit, label %5

.critedge32.preheader:                            ; preds = %.critedge, %.critedge.preheader
  %.023.lcssa = phi i32 [ 0, %.critedge.preheader ], [ %23, %.critedge ]
  %11 = load i32, ptr @m, align 4, !tbaa !7
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph44, label %.loopexit

.lr.ph41:                                         ; preds = %.lr.ph41.preheader, %.critedge
  %indvars.iv49 = phi i64 [ 0, %.lr.ph41.preheader ], [ %indvars.iv.next50, %.critedge ]
  %.02339 = phi i32 [ 0, %.lr.ph41.preheader ], [ %23, %.critedge ]
  %13 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv49) #1
  %14 = load i32, ptr %13, align 4, !tbaa !7
  %15 = tail call noundef i32 @_Z4findi(i32 noundef %14)
  store i32 %15, ptr @x, align 4, !tbaa !7
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %.loopexit, label %.critedge

.critedge:                                        ; preds = %.lr.ph41
  %17 = sext i32 %15 to i64
  %18 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @c, i64 noundef %17) #1
  %19 = load i32, ptr %18, align 4, !tbaa !7
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv49) #1
  %21 = load i32, ptr %20, align 4, !tbaa !7
  %22 = add i32 %19, %.02339
  %23 = sub i32 %22, %21
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53.not, label %.critedge32.preheader, label %.lr.ph41, !llvm.loop !11

.lr.ph44:                                         ; preds = %.critedge32.preheader, %.critedge32
  %24 = phi i32 [ %31, %.critedge32 ], [ %11, %.critedge32.preheader ]
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %.critedge32 ], [ 0, %.critedge32.preheader ]
  %.12442 = phi i32 [ %.2, %.critedge32 ], [ %.023.lcssa, %.critedge32.preheader ]
  %25 = getelementptr inbounds [101 x i32], ptr @used, i64 0, i64 %indvars.iv54
  %26 = load i32, ptr %25, align 4, !tbaa !7
  %.not30 = icmp eq i32 %26, 0
  br i1 %.not30, label %27, label %.critedge32

27:                                               ; preds = %.lr.ph44
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @c, i64 noundef %indvars.iv54) #1
  %29 = load i32, ptr %28, align 4, !tbaa !7
  %30 = add nsw i32 %29, %.12442
  %.pre = load i32, ptr @m, align 4, !tbaa !7
  br label %.critedge32

.critedge32:                                      ; preds = %.lr.ph44, %27
  %31 = phi i32 [ %24, %.lr.ph44 ], [ %.pre, %27 ]
  %.2 = phi i32 [ %.12442, %.lr.ph44 ], [ %30, %27 ]
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next55, %32
  br i1 %33, label %.lr.ph44, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph41, %.critedge32, %.critedge32.preheader
  %.227 = phi i32 [ %.023.lcssa, %.critedge32.preheader ], [ %.2, %.critedge32 ], [ 0, %.lr.ph41 ], [ 0, %.lr.ph ]
  ret i32 %.227
}

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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


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