; LLVM IR from aap/librw :: src/texture.ll (ZN2rw13TexDictionary13streamGetSizeEv)

; 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::TexDictionary" = type { %"struct.rw::Object", %"struct.rw::LinkList", %"struct.rw::LLLink" }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }

@_ZN2rw13TexDictionary9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw7Texture9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw13TexDictionary13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 16, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %7, i32 0, i32 1
  %9 = getelementptr inbounds %"struct.rw::LinkList", ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds %"struct.rw::LLLink", ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %5, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %34, %1
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.rw::LLLink", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  store ptr %15, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %7, i32 0, i32 1
  %18 = call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %17)
  %19 = icmp ne ptr %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %36

21:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef %22)
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call noundef i32 @_ZN2rw7Texture19streamGetSizeNativeEv(ptr noundef nonnull align 8 dereferenceable(120) %24)
  %26 = add i32 12, %25
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add i32 %27, %26
  store i32 %28, ptr %3, align 4, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef %29)
  %31 = add nsw i32 12, %30
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = add i32 %32, %31
  store i32 %33, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %34

34:                                               ; preds = %21
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %35, ptr %5, align 8, !tbaa !5
  br label %12, !llvm.loop !17

36:                                               ; preds = %20
  %37 = call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw13TexDictionary9s_plglistE, ptr noundef %7)
  %38 = add nsw i32 12, %37
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = add i32 %39, %38
  store i32 %40, ptr %3, align 4, !tbaa !9
  %41 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %41
}

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

declare noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr 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 16}
!12 = !{!"_ZTSN2rw13TexDictionaryE", !13, i64 0, !14, i64 16, !15, i64 32}
!13 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!14 = !{!"_ZTSN2rw8LinkListE", !15, i64 0}
!15 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }

@_ZN2rw13TexDictionary9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw7Texture9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8

; 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
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw13TexDictionary13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !13
  %5 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %.not11 = icmp eq ptr %3, %5
  br i1 %.not11, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %6 = add i32 %15, 12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.0.lcssa = phi i32 [ 28, %1 ], [ %6, %._crit_edge.loopexit ]
  %7 = tail call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw13TexDictionary9s_plglistE, ptr noundef nonnull %0)
  %8 = add i32 %.0.lcssa, %7
  ret i32 %8

.lr.ph:                                           ; preds = %1, %.lr.ph
  %9 = phi ptr [ %16, %.lr.ph ], [ %4, %1 ]
  %.013 = phi i32 [ %15, %.lr.ph ], [ 16, %1 ]
  %.01012 = phi ptr [ %9, %.lr.ph ], [ %3, %1 ]
  %10 = tail call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef nonnull %.01012)
  %11 = tail call noundef i32 @_ZN2rw7Texture19streamGetSizeNativeEv(ptr noundef nonnull align 8 dereferenceable(120) %10)
  %12 = tail call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw7Texture9s_plglistE, ptr noundef nonnull %10)
  %13 = add i32 %.013, 24
  %14 = add i32 %13, %11
  %15 = add i32 %14, %12
  %16 = load ptr, ptr %9, align 8, !tbaa !13
  %17 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %.not = icmp eq ptr %9, %17
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14
}

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

declare noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr 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, !10, i64 16}
!6 = !{!"_ZTSN2rw13TexDictionaryE", !7, i64 0, !11, i64 16, !12, i64 32}
!7 = !{!"_ZTSN2rw6ObjectE", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !10, i64 8}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN2rw8LinkListE", !12, i64 0}
!12 = !{!"_ZTSN2rw6LLLinkE", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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