; LLVM IR from gulrak/filesystem :: test/impl_test.ll (ZN3ghc10filesystem28recursive_directory_iterator3popERSt10error_code)

; 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.ghc::filesystem::recursive_directory_iterator" = type { %"class.std::shared_ptr.22" }
%"class.std::shared_ptr.22" = type { %"class.std::__shared_ptr.23" }
%"class.std::__shared_ptr.23" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.ghc::filesystem::directory_iterator" = type { %"class.std::shared_ptr" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"struct.ghc::filesystem::recursive_directory_iterator::recursive_directory_iterator_impl" = type { i16, i8, %"class.std::stack" }
%"class.std::stack" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<ghc::filesystem::directory_iterator, std::allocator<ghc::filesystem::directory_iterator>>::_Deque_impl" }
%"struct.std::_Deque_base<ghc::filesystem::directory_iterator, std::allocator<ghc::filesystem::directory_iterator>>::_Deque_impl" = type { %"struct.std::_Deque_base<ghc::filesystem::directory_iterator, std::allocator<ghc::filesystem::directory_iterator>>::_Deque_impl_data" }
%"struct.std::_Deque_base<ghc::filesystem::directory_iterator, std::allocator<ghc::filesystem::directory_iterator>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, 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(16) ptr @_ZN3ghc10filesystem18directory_iterator9incrementERSt10error_code(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3ghc10filesystem18directory_iteratoreqERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3ghc10filesystem28recursive_directory_iterator5depthEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3topEv(ptr noundef nonnull align 8 dereferenceable(80)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN3ghc10filesystem28recursive_directory_iteratoraSEOS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3ghc10filesystem28recursive_directory_iterator3popERSt10error_code(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"class.ghc::filesystem::recursive_directory_iterator", align 8
  %6 = alloca %"class.ghc::filesystem::directory_iterator", align 8
  %7 = alloca i1, align 1
  %8 = alloca i1, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  %10 = call noundef i32 @_ZNK3ghc10filesystem28recursive_directory_iterator5depthEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  call void @_ZN3ghc10filesystem28recursive_directory_iteratorC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3ghc10filesystem28recursive_directory_iteratoraSEOS1_(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  call void @_ZN3ghc10filesystem28recursive_directory_iteratorD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  br label %43

14:                                               ; preds = %2
  br label %15

15:                                               ; preds = %41, %14
  %16 = getelementptr inbounds %"class.ghc::filesystem::recursive_directory_iterator", ptr %9, i32 0, i32 0
  %17 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3ghc10filesystem28recursive_directory_iterator33recursive_directory_iterator_implELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %16) #3
  %18 = getelementptr inbounds %"struct.ghc::filesystem::recursive_directory_iterator::recursive_directory_iterator_impl", ptr %17, i32 0, i32 2
  call void @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) %18)
  %19 = getelementptr inbounds %"class.ghc::filesystem::recursive_directory_iterator", ptr %9, i32 0, i32 0
  %20 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3ghc10filesystem28recursive_directory_iterator33recursive_directory_iterator_implELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %19) #3
  %21 = getelementptr inbounds %"struct.ghc::filesystem::recursive_directory_iterator::recursive_directory_iterator_impl", ptr %20, i32 0, i32 2
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3topEv(ptr noundef nonnull align 8 dereferenceable(80) %21)
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3ghc10filesystem18directory_iterator9incrementERSt10error_code(ptr noundef nonnull align 8 dereferenceable(16) %22, ptr noundef nonnull align 8 dereferenceable(16) %23) #3
  br label %25

25:                                               ; preds = %15
  %26 = call noundef i32 @_ZNK3ghc10filesystem28recursive_directory_iterator5depthEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  %27 = icmp ne i32 %26, 0
  store i1 false, ptr %7, align 1
  store i1 false, ptr %8, align 1
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = getelementptr inbounds %"class.ghc::filesystem::recursive_directory_iterator", ptr %9, i32 0, i32 0
  %30 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3ghc10filesystem28recursive_directory_iterator33recursive_directory_iterator_implELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %29) #3
  %31 = getelementptr inbounds %"struct.ghc::filesystem::recursive_directory_iterator::recursive_directory_iterator_impl", ptr %30, i32 0, i32 2
  %32 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3topEv(ptr noundef nonnull align 8 dereferenceable(80) %31)
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  store i1 true, ptr %7, align 1
  call void @_ZN3ghc10filesystem18directory_iteratorC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  store i1 true, ptr %8, align 1
  %33 = call noundef zeroext i1 @_ZNK3ghc10filesystem18directory_iteratoreqERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %32, ptr noundef nonnull align 8 dereferenceable(16) %6)
  br label %34

34:                                               ; preds = %28, %25
  %35 = phi i1 [ false, %25 ], [ %33, %28 ]
  %36 = load i1, ptr %8, align 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  call void @_ZN3ghc10filesystem18directory_iteratorD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  br label %38

38:                                               ; preds = %37, %34
  %39 = load i1, ptr %7, align 1
  br i1 %39, label %40, label %41

40:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  br label %41

41:                                               ; preds = %40, %38
  br i1 %35, label %15, label %42, !llvm.loop !9

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42, %12
  ret void
}

declare void @_ZN3ghc10filesystem18directory_iteratorC1Ev(ptr)

declare void @_ZN3ghc10filesystem18directory_iteratorD1Ev(ptr)

declare void @_ZN3ghc10filesystem28recursive_directory_iteratorC1Ev(ptr)

declare void @_ZN3ghc10filesystem28recursive_directory_iteratorD1Ev(ptr)

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 = { 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 = { 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 = 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.ghc::filesystem::recursive_directory_iterator" = type { %"class.std::shared_ptr.22" }
%"class.std::shared_ptr.22" = type { %"class.std::__shared_ptr.23" }
%"class.std::__shared_ptr.23" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.ghc::filesystem::directory_iterator" = type { %"class.std::shared_ptr" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3ghc10filesystem18directory_iteratoreqERKS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK3ghc10filesystem28recursive_directory_iterator5depthEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3ghc10filesystem28recursive_directory_iterator3popERSt10error_code(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %"class.ghc::filesystem::recursive_directory_iterator", align 8
  %4 = alloca %"class.ghc::filesystem::directory_iterator", align 8
  %5 = tail call noundef i32 @_ZNK3ghc10filesystem28recursive_directory_iterator5depthEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %.preheader

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @_ZN3ghc10filesystem28recursive_directory_iteratorC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3ghc10filesystem28recursive_directory_iteratoraSEOS1_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @_ZN3ghc10filesystem28recursive_directory_iteratorD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  br label %.critedge.thread

.preheader:                                       ; preds = %2, %.critedge
  %9 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3ghc10filesystem28recursive_directory_iterator33recursive_directory_iterator_implELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %0) #3
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  call void @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) %10)
  %11 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3ghc10filesystem28recursive_directory_iterator33recursive_directory_iterator_implELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %0) #3
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3topEv(ptr noundef nonnull align 8 dereferenceable(80) %12)
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN3ghc10filesystem18directory_iterator9incrementERSt10error_code(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef nonnull align 8 dereferenceable(16) %1) #3
  %15 = call noundef i32 @_ZNK3ghc10filesystem28recursive_directory_iterator5depthEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %.not.not = icmp eq i32 %15, 0
  br i1 %.not.not, label %.critedge.thread, label %.critedge

.critedge:                                        ; preds = %.preheader
  %16 = call noundef ptr @_ZNKSt19__shared_ptr_accessIN3ghc10filesystem28recursive_directory_iterator33recursive_directory_iterator_implELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %0) #3
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5stackIN3ghc10filesystem18directory_iteratorESt5dequeIS2_SaIS2_EEE3topEv(ptr noundef nonnull align 8 dereferenceable(80) %17)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @_ZN3ghc10filesystem18directory_iteratorC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  %19 = call noundef zeroext i1 @_ZNK3ghc10filesystem18directory_iteratoreqERKS1_(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(16) %4)
  call void @_ZN3ghc10filesystem18directory_iteratorD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  br i1 %19, label %.preheader, label %.critedge.thread, !llvm.loop !5

.critedge.thread:                                 ; preds = %.preheader, %.critedge, %7
  ret void
}

declare void @_ZN3ghc10filesystem18directory_iteratorC1Ev(ptr) local_unnamed_addr

declare void @_ZN3ghc10filesystem18directory_iteratorD1Ev(ptr) local_unnamed_addr

declare void @_ZN3ghc10filesystem28recursive_directory_iteratorC1Ev(ptr) local_unnamed_addr

declare void @_ZN3ghc10filesystem28recursive_directory_iteratorD1Ev(ptr) local_unnamed_addr

attributes #0 = { mustprogress 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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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