; LLVM IR from aap/librw :: src/plg.ll (ZN2rw10PluginList5closeEv)

; 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"

%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }
%"struct.rw::Plugin" = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"struct.rw::LLLink", %"struct.rw::LLLink" }
%"struct.rw::PluginList" = type { i32, i32, %"struct.rw::LinkList" }

@_ZN2rwL10allPluginsE = external hidden global %"struct.rw::LinkList", align 8
@_ZN2rw6Engine8memfuncsE = external global %"struct.rw::MemoryFunctions", align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [55 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw10PluginList5closeEv = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw10PluginList5closeEv() #0 align 2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %5 = load ptr, ptr @_ZN2rwL10allPluginsE, align 8, !tbaa !9
  store ptr %5, ptr %4, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %37, %0
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %"struct.rw::LLLink", ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) @_ZN2rwL10allPluginsE)
  %12 = icmp ne ptr %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %39

14:                                               ; preds = %6
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 -104
  store ptr %16, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.rw::Plugin", ptr %17, i32 0, i32 11
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %1, align 8, !tbaa !5
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.rw::Plugin", ptr %20, i32 0, i32 12
  call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %21)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.rw::Plugin", ptr %22, i32 0, i32 13
  call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %23)
  %24 = load ptr, ptr getelementptr inbounds (%"struct.rw::MemoryFunctions", ptr @_ZN2rw6Engine8memfuncsE, i32 0, i32 2), align 8, !tbaa !16
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  call void %24(ptr noundef %25)
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::PluginList", ptr %26, i32 0, i32 2
  %28 = call noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %36

30:                                               ; preds = %14
  %31 = load ptr, ptr %1, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.rw::PluginList", ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !18
  %34 = load ptr, ptr %1, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.rw::PluginList", ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 8, !tbaa !20
  br label %36

36:                                               ; preds = %30, %14
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %38, ptr %4, align 8, !tbaa !5
  br label %6, !llvm.loop !21

39:                                               ; preds = %13
  %40 = call noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) @_ZN2rwL10allPluginsE)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  br label %45

43:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 45, ptr noundef @__PRETTY_FUNCTION__._ZN2rw10PluginList5closeEv) #5
  unreachable

44:                                               ; No predecessors!
  br label %45

45:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; 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 noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) #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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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 = { 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 = { nounwind }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN2rw8LinkListE", !11, i64 0}
!11 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!12 = !{!11, !6, i64 0}
!13 = !{!14, !6, i64 80}
!14 = !{!"_ZTSN2rw6PluginE", !15, i64 0, !15, i64 4, !15, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !11, i64 104}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 16}
!17 = !{!"_ZTSN2rw15MemoryFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!19, !15, i64 4}
!19 = !{!"_ZTSN2rw10PluginListE", !15, i64 0, !15, i64 4, !10, i64 8}
!20 = !{!19, !15, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::MemoryFunctions" = type { ptr, ptr, ptr, ptr, ptr }

@_ZN2rwL10allPluginsE = external hidden global %"struct.rw::LinkList", align 8
@_ZN2rw6Engine8memfuncsE = external local_unnamed_addr global %"struct.rw::MemoryFunctions", align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [55 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw10PluginList5closeEv = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw10PluginList5closeEv() local_unnamed_addr #0 align 2 {
  %1 = load ptr, ptr @_ZN2rwL10allPluginsE, align 8, !tbaa !5
  %2 = load ptr, ptr %1, align 8, !tbaa !11
  %3 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) @_ZN2rwL10allPluginsE)
  %.not13 = icmp eq ptr %1, %3
  br i1 %.not13, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %16, %0
  %4 = tail call noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) @_ZN2rwL10allPluginsE)
  %.not11 = icmp eq i32 %4, 0
  br i1 %.not11, label %19, label %20

.lr.ph:                                           ; preds = %0, %16
  %5 = phi ptr [ %17, %16 ], [ %2, %0 ]
  %.014 = phi ptr [ %5, %16 ], [ %1, %0 ]
  %6 = getelementptr inbounds i8, ptr %.014, i64 -104
  %7 = getelementptr inbounds i8, ptr %.014, i64 -24
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %.014, i64 -16
  tail call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  tail call void @_ZN2rw6LLLink6removeEv(ptr noundef nonnull align 8 dereferenceable(16) %.014)
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @_ZN2rw6Engine8memfuncsE, i64 16), align 8, !tbaa !15
  tail call void %10(ptr noundef nonnull %6)
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  %12 = tail call noundef i32 @_ZN2rw8LinkList7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  %.not12 = icmp eq i32 %12, 0
  br i1 %.not12, label %16, label %13

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %8, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !17
  store i32 %15, ptr %8, align 8, !tbaa !19
  br label %16

16:                                               ; preds = %.lr.ph, %13
  %17 = load ptr, ptr %5, align 8, !tbaa !11
  %18 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) @_ZN2rwL10allPluginsE)
  %.not = icmp eq ptr %5, %18
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20

19:                                               ; preds = %._crit_edge
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 45, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw10PluginList5closeEv) #3
  unreachable

20:                                               ; preds = %._crit_edge
  ret void
}

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

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

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

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

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 = { 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 #3 = { 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, !8, i64 0}
!6 = !{!"_ZTSN2rw8LinkListE", !7, i64 0}
!7 = !{!"_ZTSN2rw6LLLinkE", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!7, !8, i64 0}
!12 = !{!13, !8, i64 80}
!13 = !{!"_ZTSN2rw6PluginE", !14, i64 0, !14, i64 4, !14, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !7, i64 88, !7, i64 104}
!14 = !{!"int", !9, i64 0}
!15 = !{!16, !8, i64 16}
!16 = !{!"_ZTSN2rw15MemoryFunctionsE", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32}
!17 = !{!18, !14, i64 4}
!18 = !{!"_ZTSN2rw10PluginListE", !14, i64 0, !14, i64 4, !6, i64 8}
!19 = !{!18, !14, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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