; LLVM IR from xirc/cp-algorithm :: atcoder/abc155/D/main.ll (Z5solvev)

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

@K = external dso_local global i64, align 8
@A = external dso_local global %"class.std::vector", align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__._Z5solvev = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5countl(i64 noundef) #0

; 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 dso_local ptr @_ZNSt6vectorIlSaIlEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #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 nounwind uwtable
declare dso_local ptr @_ZNSt6vectorIlSaIlEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvev() #0 {
  %1 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %2 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = call ptr @_ZNSt6vectorIlSaIlEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @A) #6
  %7 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %1, i32 0, i32 0
  store ptr %6, ptr %7, align 8
  %8 = call ptr @_ZNSt6vectorIlSaIlEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @A) #6
  %9 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %2, i32 0, i32 0
  store ptr %8, ptr %9, align 8
  %10 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %1, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8
  %12 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %2, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8
  call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPlSt6vectorIlSaIlEEEEEvT_S7_(ptr %11, ptr %13)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 1000000000000000001, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 -1000000000000000001, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = call noundef i64 @_Z5countl(i64 noundef %14)
  %16 = load i64, ptr @K, align 8, !tbaa !5
  %17 = icmp sge i64 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %0
  br label %21

19:                                               ; preds = %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.2, i32 noundef 39, ptr noundef @__PRETTY_FUNCTION__._Z5solvev) #7
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = call noundef i64 @_Z5countl(i64 noundef %22)
  %24 = load i64, ptr @K, align 8, !tbaa !5
  %25 = icmp slt i64 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  br label %29

27:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 40, ptr noundef @__PRETTY_FUNCTION__._Z5solvev) #7
  unreachable

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28, %26
  br label %30

30:                                               ; preds = %49, %29
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = sub nsw i64 %31, %32
  %34 = call noundef i64 @_ZSt3absl(i64 noundef %33)
  %35 = icmp sgt i64 %34, 1
  br i1 %35, label %36, label %50

36:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = add nsw i64 %37, %38
  %40 = ashr i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = call noundef i64 @_Z5countl(i64 noundef %41)
  %43 = load i64, ptr @K, align 8, !tbaa !5
  %44 = icmp sge i64 %42, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %36
  %46 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %46, ptr %3, align 8, !tbaa !5
  br label %49

47:                                               ; preds = %36
  %48 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %48, ptr %4, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %30, !llvm.loop !9

50:                                               ; preds = %30
  %51 = load i64, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret i64 %51
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPlSt6vectorIlSaIlEEEEEvT_S7_(ptr, ptr) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absl(i64 noundef) #5

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 = { inlinehint 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 #4 = { noreturn nounwind "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 #5 = { inlinehint 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@K = external dso_local local_unnamed_addr global i64, align 8
@A = external dso_local global %"class.std::vector", align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__._Z5solvev = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5countl(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solvev() local_unnamed_addr #0 {
  %1 = tail call ptr @_ZNSt6vectorIlSaIlEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @A) #5
  %2 = tail call ptr @_ZNSt6vectorIlSaIlEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @A) #5
  tail call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPlSt6vectorIlSaIlEEEEEvT_S7_(ptr %1, ptr %2)
  %3 = tail call noundef i64 @_Z5countl(i64 noundef 1000000000000000001)
  %4 = load i64, ptr @K, align 8, !tbaa !5
  %.not = icmp slt i64 %3, %4
  br i1 %.not, label %5, label %6

5:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, i32 noundef 39, ptr noundef nonnull @__PRETTY_FUNCTION__._Z5solvev) #6
  unreachable

6:                                                ; preds = %0
  %7 = tail call noundef i64 @_Z5countl(i64 noundef -1000000000000000001)
  %8 = load i64, ptr @K, align 8, !tbaa !5
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %.preheader, label %12

.preheader:                                       ; preds = %6
  %10 = tail call noundef i64 @_ZSt3absl(i64 noundef 2000000000000000002)
  %11 = icmp sgt i64 %10, 1
  br i1 %11, label %.lr.ph, label %._crit_edge

12:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 40, ptr noundef nonnull @__PRETTY_FUNCTION__._Z5solvev) #6
  unreachable

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.015 = phi i64 [ %.0., %.lr.ph ], [ 1000000000000000001, %.preheader ]
  %.01114 = phi i64 [ %..011, %.lr.ph ], [ -1000000000000000001, %.preheader ]
  %13 = add nsw i64 %.015, %.01114
  %14 = ashr i64 %13, 1
  %15 = tail call noundef i64 @_Z5countl(i64 noundef %14)
  %16 = load i64, ptr @K, align 8, !tbaa !5
  %.not13 = icmp slt i64 %15, %16
  %..011 = select i1 %.not13, i64 %14, i64 %.01114
  %.0. = select i1 %.not13, i64 %.015, i64 %14
  %17 = sub nsw i64 %.0., %..011
  %18 = tail call noundef i64 @_ZSt3absl(i64 noundef %17)
  %19 = icmp sgt i64 %18, 1
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi i64 [ 1000000000000000001, %.preheader ], [ %.0., %.lr.ph ]
  ret i64 %.0.lcssa
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPlSt6vectorIlSaIlEEEEEvT_S7_(ptr, ptr) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absl(i64 noundef) local_unnamed_addr #4

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 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 = { inlinehint 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 #3 = { noreturn nounwind "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 #4 = { inlinehint 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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