; LLVM IR from abeaumont/competitive-programming :: cses/1624.ll (Z1fi)

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

@b = external dso_local global %"class.std::vector", align 8
@_Z1aB5cxx11 = external dso_local global [8 x %"class.std::__cxx11::basic_string"], align 16
@c = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z1fi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 8
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = load i32, ptr @c, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @c, align 4, !tbaa !5
  br label %82

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

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

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

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [8 x %"class.std::__cxx11::basic_string"], ptr @_Z1aB5cxx11, i64 0, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %20, i64 noundef %22)
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = icmp eq i32 %25, 42
  br i1 %26, label %27, label %28

27:                                               ; preds = %17
  br label %79

28:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 1, ptr %5, align 1, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %65, %28
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 5, ptr %4, align 4
  br label %68

34:                                               ; preds = %29
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %36) #3
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %63, label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %43) #3
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sub nsw i32 %47, %48
  %50 = add nsw i32 %46, %49
  %51 = icmp eq i32 %45, %50
  br i1 %51, label %63, label %52

52:                                               ; preds = %41
  %53 = load i32, ptr %6, 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) @b, i64 noundef %54) #3
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sub nsw i32 %58, %59
  %61 = sub nsw i32 %57, %60
  %62 = icmp eq i32 %56, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %52, %41, %34
  store i8 0, ptr %5, align 1, !tbaa !10
  store i32 5, ptr %4, align 4
  br label %68

64:                                               ; preds = %52
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %6, align 4, !tbaa !5
  br label %29, !llvm.loop !12

68:                                               ; preds = %63, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %69

69:                                               ; preds = %68
  %70 = load i8, ptr %5, align 1, !tbaa !10, !range !14, !noundef !15
  %71 = trunc i8 %70 to i1
  br i1 %71, label %73, label %72

72:                                               ; preds = %69
  store i32 4, ptr %4, align 4
  br label %76

73:                                               ; preds = %69
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @b, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  call void @_Z1fi(i32 noundef %75)
  call void @_ZNSt6vectorIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) @b) #3
  store i32 0, ptr %4, align 4
  br label %76

76:                                               ; preds = %73, %72
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  %77 = load i32, ptr %4, align 4
  switch i32 %77, label %83 [
    i32 0, label %78
    i32 4, label %79
  ]

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78, %76, %27
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !16

82:                                               ; preds = %16, %9
  ret void

83:                                               ; preds = %76
  unreachable
}

; 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 nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

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

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 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !13}


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

@b = external dso_local global %"class.std::vector", align 8
@_Z1aB5cxx11 = external dso_local global [8 x %"class.std::__cxx11::basic_string"], align 16
@c = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z1fi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = icmp eq i32 %0, 8
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = load i32, ptr @c, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @c, align 4, !tbaa !5
  br label %44

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [8 x %"class.std::__cxx11::basic_string"], ptr @_Z1aB5cxx11, i64 0, i64 %8
  store i32 0, ptr %2, align 4, !tbaa !5
  %.not17 = icmp sgt i32 %0, 0
  %10 = add nsw i32 %0, 1
  br i1 %.not17, label %.split.us.preheader, label %.split

.split.us.preheader:                              ; preds = %7
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.split.us

.split.us:                                        ; preds = %.split.us.preheader, %.loopexit.us
  %storemerge19.us = phi i32 [ %34, %.loopexit.us ], [ 0, %.split.us.preheader ]
  %11 = sext i32 %storemerge19.us to i64
  %12 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %9, i64 noundef %11)
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp eq i8 %13, 42
  br i1 %14, label %.loopexit.usthread-pre-split, label %.preheader.us

15:                                               ; preds = %27
  %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_crit_edge.us, label %.preheader.us, !llvm.loop !10

.preheader.us:                                    ; preds = %.split.us, %15
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 0, %.split.us ]
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %indvars.iv) #3
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %.loopexit.us, label %20

20:                                               ; preds = %.preheader.us
  %indvars23 = trunc i64 %indvars.iv to i32
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %indvars.iv) #3
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sub nsw i32 %0, %indvars23
  %25 = add nsw i32 %23, %24
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %.loopexit.us, label %27

27:                                               ; preds = %20
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %indvars.iv) #3
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sub nsw i32 %30, %24
  %32 = icmp eq i32 %29, %31
  br i1 %32, label %.loopexit.us, label %15

.loopexit.usthread-pre-split:                     ; preds = %.split.us, %..critedge_crit_edge.us
  %.pr = load i32, ptr %2, align 4, !tbaa !5
  br label %.loopexit.us

.loopexit.us:                                     ; preds = %.preheader.us, %20, %27, %.loopexit.usthread-pre-split
  %33 = phi i32 [ %.pr, %.loopexit.usthread-pre-split ], [ %30, %27 ], [ %23, %20 ], [ %18, %.preheader.us ]
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !5
  %35 = icmp slt i32 %33, 7
  br i1 %35, label %.split.us, label %.split21.us, !llvm.loop !12

..critedge_crit_edge.us:                          ; preds = %15
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @b, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @_Z1fi(i32 noundef %10)
  call void @_ZNSt6vectorIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) @b) #3
  br label %.loopexit.usthread-pre-split

.split21.us:                                      ; preds = %40, %.loopexit.us
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %44

.split:                                           ; preds = %7, %40
  %storemerge19 = phi i32 [ %42, %40 ], [ 0, %7 ]
  %36 = sext i32 %storemerge19 to i64
  %37 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %9, i64 noundef %36)
  %38 = load i8, ptr %37, align 1, !tbaa !9
  %39 = icmp eq i8 %38, 42
  br i1 %39, label %40, label %.preheader

.preheader:                                       ; preds = %.split
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @b, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @_Z1fi(i32 noundef %10)
  call void @_ZNSt6vectorIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) @b) #3
  br label %40

40:                                               ; preds = %.preheader, %.split
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %2, align 4, !tbaa !5
  %43 = icmp slt i32 %41, 7
  br i1 %43, label %.split, label %.split21.us, !llvm.loop !12

44:                                               ; preds = %.split21.us, %4
  ret void
}

; Function Attrs: mustprogress 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 nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #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) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

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 = { mustprogress 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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass