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

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

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

30:                                               ; preds = %22
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %77

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

38:                                               ; preds = %31
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.rw::Plugin", ptr %39, i32 0, i32 8
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.rw::Plugin", ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !18
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.rw::Plugin", ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !19
  %49 = call noundef i32 %41(ptr noundef %42, i32 noundef %45, i32 noundef %48)
  store i32 %49, ptr %7, align 4, !tbaa !9
  %50 = icmp sle i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %38, %31
  store i32 4, ptr %10, align 4
  br label %72

52:                                               ; preds = %38
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.rw::Plugin", ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !20
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %53, i32 noundef %56, i32 noundef %57)
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.rw::Plugin", ptr %59, i32 0, i32 7
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.rw::Plugin", ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !18
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.rw::Plugin", ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !19
  %71 = call noundef ptr %61(ptr noundef %62, i32 noundef %63, ptr noundef %64, i32 noundef %67, i32 noundef %70)
  store i32 0, ptr %10, align 4
  br label %72

72:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %73 = load i32, ptr %10, align 4
  switch i32 %73, label %78 [
    i32 0, label %74
    i32 4, label %75
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74, %72
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %76, ptr %9, align 8, !tbaa !5
  br label %22, !llvm.loop !22

77:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void

78:                                               ; preds = %72
  unreachable
}

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

declare noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef, i32 noundef, i32 noundef) #3

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

!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, !6, i64 56}
!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, !10, i64 0}
!19 = !{!17, !10, i64 4}
!20 = !{!17, !10, i64 8}
!21 = !{!17, !6, i64 48}
!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 uwtable
define dso_local void @_ZN2rw10PluginList11streamWriteEPNS_6StreamEPv(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %2)
  %5 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef 3, i32 noundef %4)
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %.not23 = icmp eq ptr %7, %9
  br i1 %.not23, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %30, %3
  ret void

.lr.ph:                                           ; preds = %3, %30
  %10 = phi ptr [ %31, %30 ], [ %8, %3 ]
  %.024 = phi ptr [ %10, %30 ], [ %7, %3 ]
  %11 = getelementptr inbounds i8, ptr %.024, i64 -88
  %12 = getelementptr inbounds i8, ptr %.024, i64 -32
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = icmp eq ptr %13, null
  br i1 %14, label %30, label %15

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr %11, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %.024, i64 -84
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %19 = tail call noundef i32 %13(ptr noundef %2, i32 noundef %16, i32 noundef %18)
  %20 = icmp slt i32 %19, 1
  br i1 %20, label %30, label %21

21:                                               ; preds = %15
  %22 = getelementptr inbounds i8, ptr %.024, i64 -80
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = tail call noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef %1, i32 noundef %23, i32 noundef %19)
  %25 = getelementptr inbounds i8, ptr %.024, i64 -40
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = load i32, ptr %11, align 8, !tbaa !16
  %28 = load i32, ptr %17, align 4, !tbaa !17
  %29 = tail call noundef ptr %26(ptr noundef %1, i32 noundef %19, ptr noundef %2, i32 noundef %27, i32 noundef %28)
  br label %30

30:                                               ; preds = %.lr.ph, %15, %21
  %31 = load ptr, ptr %10, align 8, !tbaa !13
  %32 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  %.not = icmp eq ptr %10, %32
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #1 align 2

declare noundef zeroext i1 @_ZN2rw16writeChunkHeaderEPNS_6StreamEii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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" }
attributes #2 = { "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, !12, i64 56}
!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, !7, i64 0}
!17 = !{!15, !7, i64 4}
!18 = !{!15, !7, i64 8}
!19 = !{!15, !12, i64 48}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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