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

; 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::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Plugin" = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"struct.rw::LLLink", %"struct.rw::LLLink" }

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

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

; 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 @_ZN2rw10PluginList12assertRightsEPvjj(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %14 = getelementptr inbounds %"struct.rw::PluginList", ptr %13, i32 0, i32 2
  %15 = getelementptr inbounds %"struct.rw::LinkList", ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds %"struct.rw::LLLink", ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %10, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %57, %4
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::LLLink", ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  store ptr %21, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.rw::PluginList", ptr %13, i32 0, i32 2
  %24 = call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %23)
  %25 = icmp ne ptr %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %18
  store i32 2, ptr %11, align 4
  br label %59

27:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 -88
  store ptr %29, ptr %12, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.rw::Plugin", ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !16
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %53

35:                                               ; preds = %27
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.rw::Plugin", ptr %36, i32 0, i32 9
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %52

40:                                               ; preds = %35
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.rw::Plugin", ptr %41, i32 0, i32 9
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.rw::Plugin", ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !19
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.rw::Plugin", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !20
  %51 = load i32, ptr %8, align 4, !tbaa !9
  call void %43(ptr noundef %44, i32 noundef %47, i32 noundef %50, i32 noundef %51)
  br label %52

52:                                               ; preds = %40, %35
  store i32 1, ptr %11, align 4
  br label %54

53:                                               ; preds = %27
  store i32 0, ptr %11, align 4
  br label %54

54:                                               ; preds = %53, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %55 = load i32, ptr %11, align 4
  switch i32 %55, label %59 [
    i32 0, label %56
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %58, ptr %10, align 8, !tbaa !5
  br label %18, !llvm.loop !21

59:                                               ; preds = %54, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %60 = load i32, ptr %11, align 4
  switch i32 %60, label %62 [
    i32 2, label %61
    i32 1, label %61
  ]

61:                                               ; preds = %59, %59
  ret void

62:                                               ; preds = %59
  unreachable
}

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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN2rw10PluginListE", !10, i64 0, !10, i64 4, !13, i64 8}
!13 = !{!"_ZTSN2rw8LinkListE", !14, i64 0}
!14 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !10, i64 8}
!17 = !{!"_ZTSN2rw6PluginE", !10, i64 0, !10, i64 4, !10, 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, !14, i64 88, !14, i64 104}
!18 = !{!17, !6, i64 64}
!19 = !{!17, !10, i64 0}
!20 = !{!17, !10, i64 4}
!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"

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw10PluginList12assertRightsEPvjj(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %9, %4
  %.013 = phi ptr [ %6, %4 ], [ %7, %9 ]
  %7 = load ptr, ptr %.013, align 8, !tbaa !13
  %8 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %.not = icmp eq ptr %.013, %8
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %.critedge
  %10 = getelementptr inbounds i8, ptr %.013, i64 -80
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %.not16 = icmp eq i32 %11, %2
  br i1 %.not16, label %12, label %.critedge, !llvm.loop !16

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %.013, i64 -24
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %.not15 = icmp eq ptr %14, null
  br i1 %.not15, label %.loopexit, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %.013, i64 -88
  %17 = load i32, ptr %16, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %.013, i64 -84
  %19 = load i32, ptr %18, align 4, !tbaa !20
  tail call void %14(ptr noundef %1, i32 noundef %17, i32 noundef %19, i32 noundef %3)
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %15, %12
  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 = { 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" }

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


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