; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK65/Problem E/brute.ll (Z3dfsi)

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

@g = external dso_local global [100010 x %"class.std::vector"], align 16
@_ZL2ch = external hidden global [100010 x i32], align 16
@_ZL1l = external hidden global [100010 x i32], align 16
@_ZL3lca = external hidden global [100010 x [20 x i32]], align 16
@_ZL3vis = external hidden global [100010 x i32], align 16
@_ZL1p = external hidden global [100010 x i32], 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 uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) #1 {
  %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
  store i32 %0, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100010 x i32], ptr @_ZL2ch, i64 0, i64 %9
  store i32 1, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @_ZL3vis, i64 0, i64 %12
  store i32 1, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %90, %1
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %17
  %19 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18) #3
  %20 = sub i64 %19, 1
  %21 = trunc i64 %20 to i32
  %22 = icmp sle i32 %15, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %29) #3
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100010 x i32], ptr @_ZL3vis, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %24
  store i32 4, ptr %4, align 4
  br label %87

38:                                               ; preds = %24
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100010 x i32], ptr @_ZL1l, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i32], ptr @_ZL1l, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %49
  %51 = getelementptr inbounds [20 x i32], ptr %50, i64 0, i64 0
  store i32 %47, ptr %51, align 16, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %53
  store i32 %47, ptr %54, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %55 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %55, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %59, %38
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = icmp ne i32 %57, -1
  br i1 %58, label %59, label %76

59:                                               ; preds = %56
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %61
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [20 x i32], ptr %62, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %69
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [20 x i32], ptr %70, i64 0, i64 %72
  store i32 %67, ptr %73, align 4, !tbaa !5
  store i32 %67, ptr %6, align 4, !tbaa !5
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !5
  br label %56, !llvm.loop !9

76:                                               ; preds = %56
  %77 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %77)
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100010 x i32], ptr @_ZL2ch, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [100010 x i32], ptr @_ZL2ch, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = add nsw i32 %85, %81
  store i32 %86, ptr %84, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  store i32 0, ptr %4, align 4
  br label %87

87:                                               ; preds = %76, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %88 = load i32, ptr %4, align 4
  switch i32 %88, label %94 [
    i32 0, label %89
    i32 4, label %90
  ]

89:                                               ; preds = %87
  br label %90

90:                                               ; preds = %89, %87
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !11

93:                                               ; preds = %23
  ret void

94:                                               ; preds = %87
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 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) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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 }

@g = external dso_local global [100010 x %"class.std::vector"], align 16
@_ZL2ch = external hidden local_unnamed_addr global [100010 x i32], align 16
@_ZL1l = external hidden local_unnamed_addr global [100010 x i32], align 16
@_ZL3lca = external hidden local_unnamed_addr global [100010 x [20 x i32]], align 16
@_ZL3vis = external hidden local_unnamed_addr global [100010 x i32], align 16
@_ZL1p = external hidden local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100010 x i32], ptr @_ZL2ch, i64 0, i64 %2
  store i32 1, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds [100010 x i32], ptr @_ZL3vis, i64 0, i64 %2
  store i32 1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %2
  %6 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #1
  %7 = trunc i64 %6 to i32
  %8 = add i32 %7, -1
  %.not30 = icmp slt i32 %8, 0
  br i1 %.not30, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %1
  %9 = getelementptr inbounds [100010 x i32], ptr @_ZL1l, i64 0, i64 %2
  %.not2627 = icmp eq i32 %0, -1
  br i1 %.not2627, label %.lr.ph33.split.us, label %.lr.ph33.split

.lr.ph33.split.us:                                ; preds = %.lr.ph33, %25
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %25 ], [ 0, %.lr.ph33 ]
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv40) #1
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @_ZL3vis, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not25.us = icmp eq i32 %14, 0
  br i1 %.not25.us, label %15, label %25

15:                                               ; preds = %.lr.ph33.split.us
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  %18 = getelementptr inbounds [100010 x i32], ptr @_ZL1l, i64 0, i64 %12
  store i32 %17, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %12
  store i32 -1, ptr %19, align 16, !tbaa !5
  %20 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %12
  store i32 -1, ptr %20, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %11)
  %21 = getelementptr inbounds [100010 x i32], ptr @_ZL2ch, i64 0, i64 %12
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, %22
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %15, %.lr.ph33.split.us
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %26 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #1
  %27 = shl i64 %26, 32
  %sext43 = add i64 %27, -4294967296
  %28 = ashr exact i64 %sext43, 32
  %.not.us.not = icmp slt i64 %indvars.iv40, %28
  br i1 %.not.us.not, label %.lr.ph33.split.us, label %._crit_edge34, !llvm.loop !9

._crit_edge34:                                    ; preds = %49, %25, %1
  ret void

.lr.ph33.split:                                   ; preds = %.lr.ph33, %49
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %49 ], [ 0, %.lr.ph33 ]
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv37) #1
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100010 x i32], ptr @_ZL3vis, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %.not25 = icmp eq i32 %33, 0
  br i1 %.not25, label %.lr.ph, label %49

.lr.ph:                                           ; preds = %.lr.ph33.split
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = getelementptr inbounds [100010 x i32], ptr @_ZL1l, i64 0, i64 %31
  store i32 %35, ptr %36, align 4, !tbaa !5
  %37 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %31
  store i32 %0, ptr %37, align 16, !tbaa !5
  %38 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %31
  store i32 %0, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %.lr.ph, %39
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %39 ]
  %.02328 = phi i32 [ %0, %.lr.ph ], [ %43, %39 ]
  %40 = sext i32 %.02328 to i64
  %41 = add nsw i64 %indvars.iv, -1
  %42 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %40, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = getelementptr inbounds [100010 x [20 x i32]], ptr @_ZL3lca, i64 0, i64 %31, i64 %indvars.iv
  store i32 %43, ptr %44, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not26 = icmp eq i32 %43, -1
  br i1 %.not26, label %._crit_edge, label %39, !llvm.loop !11

._crit_edge:                                      ; preds = %39
  tail call void @_Z3dfsi(i32 noundef %30)
  %45 = getelementptr inbounds [100010 x i32], ptr @_ZL2ch, i64 0, i64 %31
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %.lr.ph33.split, %._crit_edge
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %50 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #1
  %51 = shl i64 %50, 32
  %sext = add i64 %51, -4294967296
  %52 = ashr exact i64 %sext, 32
  %.not.not = icmp slt i64 %indvars.iv37, %52
  br i1 %.not.not, label %.lr.ph33.split, label %._crit_edge34, !llvm.loop !9
}

; 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

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


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