; LLVM IR from cselab/aphros :: src/util/suspender.ll (ZN9Suspender3Sem7LoopEndEv)

; 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.Suspender::Sem" = type { ptr, %"class.std::__cxx11::basic_string" }
%"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] }
%class.Suspender = type { %"class.std::__cxx11::list", %"struct.std::_List_iterator", i8, i64 }
%"class.std::__cxx11::list" = type { %"class.std::__cxx11::_List_base" }
%"class.std::__cxx11::_List_base" = type { %"struct.std::__cxx11::_List_base<Suspender::State, std::allocator<Suspender::State>>::_List_impl" }
%"struct.std::__cxx11::_List_base<Suspender::State, std::allocator<Suspender::State>>::_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 }
%"struct.std::_List_iterator" = type { ptr }
%"struct.Suspender::State" = type { i32, i32, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", i32, i32, i32, %"class.std::unique_ptr" }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.5" }
%"struct.std::_Head_base.5" = type { ptr }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9Suspender3Sem7LoopEndEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = getelementptr inbounds %"class.Suspender::Sem", ptr %4, i32 0, i32 0
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %class.Suspender, ptr %6, i32 0, i32 1
  %8 = call noundef nonnull align 8 dereferenceable(96) ptr @_ZNKSt14_List_iteratorIN9Suspender5StateEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %7) #2
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %"struct.Suspender::State", ptr %9, i32 0, i32 6
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.Suspender::State", ptr %12, i32 0, i32 5
  %14 = load i32, ptr %13, align 4, !tbaa !23
  %15 = icmp slt i32 %11, %14
  br i1 %15, label %16, label %30

16:                                               ; preds = %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.Suspender::State", ptr %17, i32 0, i32 5
  %19 = load i32, ptr %18, align 4, !tbaa !23
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.Suspender::State", ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !24
  %23 = icmp sle i32 %19, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %16
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.Suspender::State", ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !25
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.Suspender::State", ptr %28, i32 0, i32 6
  store i32 %27, ptr %29, align 8, !tbaa !14
  br label %30

30:                                               ; preds = %24, %16, %1
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.Suspender::State", ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !25
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.Suspender::State", ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !24
  %37 = add nsw i32 %36, 1
  %38 = icmp eq i32 %33, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %30
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.Suspender::State", ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 4, !tbaa !23
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.Suspender::State", ptr %43, i32 0, i32 1
  store i32 %42, ptr %44, align 4, !tbaa !24
  br label %45

45:                                               ; preds = %39, %30
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.Suspender::State", ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !25
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %47, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!10 = !{!"_ZTSN9Suspender3SemE", !6, i64 0, !11, i64 8}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !7, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !16, i64 80}
!15 = !{!"_ZTSN9Suspender5StateE", !16, i64 0, !16, i64 4, !11, i64 8, !11, i64 40, !16, i64 72, !16, i64 76, !16, i64 80, !17, i64 88}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTSSt10unique_ptrI10BaseHolderSt14default_deleteIS0_EE", !18, i64 0}
!18 = !{!"_ZTSSt15__uniq_ptr_dataI10BaseHolderSt14default_deleteIS0_ELb1ELb1EE", !19, i64 0}
!19 = !{!"_ZTSSt15__uniq_ptr_implI10BaseHolderSt14default_deleteIS0_EE", !20, i64 0}
!20 = !{!"_ZTSSt5tupleIJP10BaseHolderSt14default_deleteIS0_EEE", !21, i64 0}
!21 = !{!"_ZTSSt11_Tuple_implILm0EJP10BaseHolderSt14default_deleteIS0_EEE", !22, i64 0}
!22 = !{!"_ZTSSt10_Head_baseILm0EP10BaseHolderLb0EE", !6, i64 0}
!23 = !{!15, !16, i64 76}
!24 = !{!15, !16, i64 4}
!25 = !{!15, !16, 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(96) ptr @_ZNKSt14_List_iteratorIN9Suspender5StateEEdeEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9Suspender3Sem7LoopEndEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 24
  %4 = tail call noundef nonnull align 8 dereferenceable(96) ptr @_ZNKSt14_List_iteratorIN9Suspender5StateEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #1
  %5 = getelementptr inbounds i8, ptr %4, i64 80
  %6 = load i32, ptr %5, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %4, i64 76
  %8 = load i32, ptr %7, align 4, !tbaa !22
  %9 = icmp sge i32 %6, %8
  %10 = getelementptr inbounds i8, ptr %4, i64 4
  %11 = load i32, ptr %10, align 4
  %.not = icmp sgt i32 %8, %11
  %or.cond = select i1 %9, i1 true, i1 %.not
  %.pre = load i32, ptr %4, align 8, !tbaa !23
  br i1 %or.cond, label %13, label %12

12:                                               ; preds = %1
  store i32 %.pre, ptr %5, align 8, !tbaa !13
  br label %13

13:                                               ; preds = %12, %1
  %14 = add nsw i32 %11, 1
  %15 = icmp eq i32 %.pre, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store i32 %8, ptr %10, align 4, !tbaa !24
  br label %17

17:                                               ; preds = %16, %13
  %18 = add nsw i32 %.pre, 1
  store i32 %18, ptr %4, align 8, !tbaa !23
  ret void
}

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, !7, i64 0}
!6 = !{!"_ZTSN9Suspender3SemE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !11, i64 0, !12, i64 8, !8, i64 16}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !7, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !15, i64 80}
!14 = !{!"_ZTSN9Suspender5StateE", !15, i64 0, !15, i64 4, !10, i64 8, !10, i64 40, !15, i64 72, !15, i64 76, !15, i64 80, !16, i64 88}
!15 = !{!"int", !8, i64 0}
!16 = !{!"_ZTSSt10unique_ptrI10BaseHolderSt14default_deleteIS0_EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_dataI10BaseHolderSt14default_deleteIS0_ELb1ELb1EE", !18, i64 0}
!18 = !{!"_ZTSSt15__uniq_ptr_implI10BaseHolderSt14default_deleteIS0_EE", !19, i64 0}
!19 = !{!"_ZTSSt5tupleIJP10BaseHolderSt14default_deleteIS0_EEE", !20, i64 0}
!20 = !{!"_ZTSSt11_Tuple_implILm0EJP10BaseHolderSt14default_deleteIS0_EEE", !21, i64 0}
!21 = !{!"_ZTSSt10_Head_baseILm0EP10BaseHolderLb0EE", !7, i64 0}
!22 = !{!14, !15, i64 76}
!23 = !{!14, !15, i64 0}
!24 = !{!14, !15, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass