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

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

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

29:                                               ; preds = %21
  store i32 2, ptr %14, align 4
  br label %57

30:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 -88
  store ptr %32, ptr %15, align 8, !tbaa !5
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Plugin", ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %51

38:                                               ; preds = %30
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %15, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.rw::Plugin", ptr %40, i32 0, i32 6
  store ptr %39, ptr %41, align 8, !tbaa !18
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.rw::Plugin", ptr %43, i32 0, i32 7
  store ptr %42, ptr %44, align 8, !tbaa !19
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.rw::Plugin", ptr %46, i32 0, i32 8
  store ptr %45, ptr %47, align 8, !tbaa !20
  %48 = load ptr, ptr %15, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.rw::Plugin", ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !21
  store i32 %50, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %52

51:                                               ; preds = %30
  store i32 0, ptr %14, align 4
  br label %52

52:                                               ; preds = %51, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  %53 = load i32, ptr %14, align 4
  switch i32 %53, label %57 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %56, ptr %13, align 8, !tbaa !5
  br label %21, !llvm.loop !22

57:                                               ; preds = %52, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %58 = load i32, ptr %14, align 4
  switch i32 %58, label %62 [
    i32 2, label %59
    i32 1, label %60
  ]

59:                                               ; preds = %57
  store i32 -1, ptr %6, align 4
  br label %60

60:                                               ; preds = %59, %57
  %61 = load i32, ptr %6, align 4
  ret i32 %61

62:                                               ; preds = %57
  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 40}
!19 = !{!17, !6, i64 48}
!20 = !{!17, !6, i64 56}
!21 = !{!17, !10, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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 nounwind uwtable
define dso_local noundef i32 @_ZN2rw10PluginList14registerStreamEjPFPNS_6StreamES2_iPviiES5_PFiS3_iiE(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  br label %8

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

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %.018, i64 -80
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %.not19 = icmp eq i32 %13, %1
  br i1 %.not19, label %.thread, label %8

.thread:                                          ; preds = %11
  %14 = getelementptr inbounds i8, ptr %.018, i64 -88
  %15 = getelementptr inbounds i8, ptr %.018, i64 -48
  store ptr %2, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %.018, i64 -40
  store ptr %3, ptr %16, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %.018, i64 -32
  store ptr %4, ptr %17, align 8, !tbaa !18
  %18 = load i32, ptr %14, align 8, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %8, %.thread
  %spec.select = phi i32 [ %18, %.thread ], [ -1, %8 ]
  ret i32 %spec.select
}

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

!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 = !{!15, !12, i64 40}
!17 = !{!15, !12, i64 48}
!18 = !{!15, !12, i64 56}
!19 = !{!15, !7, i64 0}


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