; LLVM IR from rantala/string-sorting :: src/msd_dyn_vector.ll (Z14msd_D_std_listPPhm)

; 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.counting_list = type { %"class.std::__cxx11::list", i64 }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<unsigned char *, std::allocator<unsigned char *>>::_List_impl" }
%"struct.std::__cxx11::_List_base<unsigned char *, std::allocator<unsigned char *>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

; 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 @_Z14msd_D_std_listPPhm(ptr noundef %0, i64 noundef %1) #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca [256 x %class.counting_list], align 16
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8192, ptr %5) #3
  %8 = getelementptr inbounds [256 x %class.counting_list], ptr %5, i32 0, i32 0
  %9 = getelementptr inbounds %class.counting_list, ptr %8, i64 256
  br label %10

10:                                               ; preds = %12, %2
  %11 = phi ptr [ %8, %2 ], [ %13, %12 ]
  invoke void @_ZN13counting_listIPhEC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %11)
          to label %12 unwind label %27

12:                                               ; preds = %10
  %13 = getelementptr inbounds %class.counting_list, ptr %11, i64 1
  %14 = icmp eq ptr %13, %9
  br i1 %14, label %15, label %10

15:                                               ; preds = %12
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds [256 x %class.counting_list], ptr %5, i64 0, i64 0
  invoke void @_ZL5msd_DI13counting_listIPhEmEvPS1_mmPT_(ptr noundef %16, i64 noundef %17, i64 noundef 0, ptr noundef %18)
          to label %19 unwind label %37

19:                                               ; preds = %15
  %20 = getelementptr inbounds [256 x %class.counting_list], ptr %5, i32 0, i32 0
  %21 = getelementptr inbounds %class.counting_list, ptr %20, i64 256
  br label %22

22:                                               ; preds = %22, %19
  %23 = phi ptr [ %21, %19 ], [ %24, %22 ]
  %24 = getelementptr inbounds %class.counting_list, ptr %23, i64 -1
  call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %24) #3
  %25 = icmp eq ptr %24, %20
  br i1 %25, label %26, label %22

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8192, ptr %5) #3
  ret void

27:                                               ; preds = %10
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %6, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %7, align 4
  %31 = icmp eq ptr %8, %11
  br i1 %31, label %36, label %32

32:                                               ; preds = %32, %27
  %33 = phi ptr [ %11, %27 ], [ %34, %32 ]
  %34 = getelementptr inbounds %class.counting_list, ptr %33, i64 -1
  call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %34) #3
  %35 = icmp eq ptr %34, %8
  br i1 %35, label %36, label %32

36:                                               ; preds = %32, %27
  br label %48

37:                                               ; preds = %15
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %6, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %7, align 4
  %41 = getelementptr inbounds [256 x %class.counting_list], ptr %5, i32 0, i32 0
  %42 = getelementptr inbounds %class.counting_list, ptr %41, i64 256
  br label %43

43:                                               ; preds = %43, %37
  %44 = phi ptr [ %42, %37 ], [ %45, %43 ]
  %45 = getelementptr inbounds %class.counting_list, ptr %44, i64 -1
  call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %45) #3
  %46 = icmp eq ptr %45, %41
  br i1 %46, label %47, label %43

47:                                               ; preds = %43
  br label %48

48:                                               ; preds = %47, %36
  call void @llvm.lifetime.end.p0(i64 8192, ptr %5) #3
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %6, align 8
  %51 = load i32, ptr %7, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

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

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL5msd_DI13counting_listIPhEmEvPS1_mmPT_(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


; 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.counting_list = type { %"class.std::__cxx11::list", i64 }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<unsigned char *, std::allocator<unsigned char *>>::_List_impl" }
%"struct.std::__cxx11::_List_base<unsigned char *, std::allocator<unsigned char *>>::_List_impl" = type { %"struct.std::__detail::_List_node_header" }
%"struct.std::__detail::_List_node_header" = type { %"struct.std::__detail::_List_node_base", i64 }
%"struct.std::__detail::_List_node_base" = type { ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress 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 @_Z14msd_D_std_listPPhm(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca [256 x %class.counting_list], align 16
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %3) #3
  br label %4

4:                                                ; preds = %4, %2
  %.idx = phi i64 [ 0, %2 ], [ %.add, %4 ]
  %.ptr = getelementptr inbounds i8, ptr %3, i64 %.idx
  call void @_ZN13counting_listIPhEC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %.ptr)
  %.add = add nuw nsw i64 %.idx, 32
  %5 = icmp eq i64 %.add, 8192
  br i1 %5, label %6, label %4

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %3, i64 8192
  invoke void @_ZL5msd_DI13counting_listIPhEmEvPS1_mmPT_(ptr noundef %0, i64 noundef %1, i64 noundef 0, ptr noundef nonnull %3)
          to label %.preheader unwind label %12

.preheader:                                       ; preds = %6, %.preheader
  %8 = phi ptr [ %9, %.preheader ], [ %7, %6 ]
  %9 = getelementptr inbounds i8, ptr %8, i64 -32
  call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %9) #3
  %10 = icmp eq ptr %9, %3
  br i1 %10, label %11, label %.preheader

11:                                               ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %3) #3
  ret void

12:                                               ; preds = %6
  %13 = landingpad { ptr, i32 }
          cleanup
  br label %14

14:                                               ; preds = %14, %12
  %15 = phi ptr [ %7, %12 ], [ %16, %14 ]
  %16 = getelementptr inbounds i8, ptr %15, i64 -32
  call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %16) #3
  %17 = icmp eq ptr %16, %3
  br i1 %17, label %18, label %14

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %3) #3
  resume { ptr, i32 } %13
}

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

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL5msd_DI13counting_listIPhEmEvPS1_mmPT_(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass