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

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN13counting_listIPhEC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 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 #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z23msd_D_std_list_adaptivePPhm(ptr noundef %0, i64 noundef %1) #4 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %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 8, ptr %5) #5
  %8 = call noalias noundef nonnull ptr @_Znam(i64 noundef 2097160) #6
  store i64 65536, ptr %8, align 16
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = getelementptr inbounds %class.counting_list, ptr %9, i64 65536
  br label %11

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

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

16:                                               ; preds = %13
  store ptr %9, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZL14msd_D_adaptiveI13counting_listIPhEEvPS1_mmPT_(ptr noundef %17, i64 noundef %18, i64 noundef 0, ptr noundef %19)
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %34, label %22

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %20, i64 -8
  %24 = load i64, ptr %23, align 8
  %25 = getelementptr inbounds %class.counting_list, ptr %20, i64 %24
  %26 = icmp eq ptr %20, %25
  br i1 %26, label %31, label %27

27:                                               ; preds = %27, %22
  %28 = phi ptr [ %25, %22 ], [ %29, %27 ]
  %29 = getelementptr inbounds %class.counting_list, ptr %28, i64 -1
  call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %29) #5
  %30 = icmp eq ptr %29, %20
  br i1 %30, label %31, label %27

31:                                               ; preds = %27, %22
  %32 = mul i64 32, %24
  %33 = add i64 %32, 8
  call void @_ZdaPvm(ptr noundef %23, i64 noundef %33) #7
  br label %34

34:                                               ; preds = %31, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void

35:                                               ; preds = %11
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %6, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %7, align 4
  %39 = icmp eq ptr %9, %12
  br i1 %39, label %44, label %40

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

44:                                               ; preds = %40, %35
  call void @_ZdaPvm(ptr noundef %8, i64 noundef 2097160) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %6, align 8
  %47 = load i32, ptr %7, align 4
  %48 = insertvalue { ptr, i32 } poison, ptr %46, 0
  %49 = insertvalue { ptr, i32 } %48, i32 %47, 1
  resume { ptr, i32 } %49
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { nobuiltin 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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"

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

; 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
define dso_local void @_Z23msd_D_std_list_adaptivePPhm(ptr noundef %0, i64 noundef %1) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %3 = tail call noalias noundef nonnull dereferenceable(2097160) ptr @_Znam(i64 noundef 2097160) #4
  store i64 65536, ptr %3, align 16
  br label %4

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

6:                                                ; preds = %4
  %.ptr4.ptr = getelementptr inbounds i8, ptr %3, i64 8
  tail call void @_ZL14msd_D_adaptiveI13counting_listIPhEEvPS1_mmPT_(ptr noundef %0, i64 noundef %1, i64 noundef 0, ptr noundef nonnull %.ptr4.ptr)
  %7 = load i64, ptr %3, align 8
  %.idx5 = shl i64 %7, 5
  %.ptr4.add = or disjoint i64 %.idx5, 8
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %6, %.preheader
  %.idx7 = phi i64 [ %.add8, %.preheader ], [ %.ptr4.add, %6 ]
  %.add8 = add nsw i64 %.idx7, -32
  %.ptr10 = getelementptr inbounds i8, ptr %3, i64 %.add8
  tail call void @_ZNSt7__cxx1110_List_baseIPhSaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %.ptr10) #5
  %9 = icmp eq i64 %.add8, 8
  br i1 %9, label %.loopexit, label %.preheader

.loopexit:                                        ; preds = %.preheader, %6
  tail call void @_ZdaPvm(ptr noundef nonnull %3, i64 noundef %.ptr4.add) #6
  ret void
}

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

attributes #0 = { nobuiltin allocsize(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 = { nobuiltin 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 #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 = { 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 = { builtin allocsize(0) }
attributes #5 = { nounwind }
attributes #6 = { builtin 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass