; LLVM IR from aap/librw :: src/geometry.ll (ZN2rw8Material13streamGetSizeEv)

; 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::Material" = type { ptr, %"struct.rw::RGBA", %"struct.rw::SurfaceProperties", ptr, i32 }
%"struct.rw::RGBA" = type { i8, i8, i8, i8 }
%"struct.rw::SurfaceProperties" = type { float, float, float }

@_ZN2rw8Material9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw7versionE = external global i32, align 4

; 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

declare noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw8Material13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = zext i32 %5 to i64
  %7 = add i64 %6, 28
  %8 = trunc i64 %7 to i32
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !9
  %10 = icmp sge i32 %9, 197632
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = add i32 %12, 12
  store i32 %13, ptr %3, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %11, %1
  %15 = getelementptr inbounds %"struct.rw::Material", ptr %4, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = getelementptr inbounds %"struct.rw::Material", ptr %4, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = call noundef i32 @_ZN2rw7Texture13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120) %20)
  %22 = add i32 12, %21
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = add i32 %23, %22
  store i32 %24, ptr %3, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %18, %14
  %26 = call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw8Material9s_plglistE, ptr noundef %4)
  %27 = add nsw i32 12, %26
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = add i32 %28, %27
  store i32 %29, ptr %3, align 4, !tbaa !9
  %30 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %30
}

declare noundef i32 @_ZN2rw7Texture13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 0}
!12 = !{!"_ZTSN2rw8MaterialE", !6, i64 0, !13, i64 8, !14, i64 12, !6, i64 24, !10, i64 32}
!13 = !{!"_ZTSN2rw4RGBAE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!14 = !{!"_ZTSN2rw17SurfacePropertiesE", !15, i64 0, !15, i64 4, !15, i64 8}
!15 = !{!"float", !7, i64 0}


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

@_ZN2rw8Material9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw7versionE = external local_unnamed_addr global i32, align 4

declare noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw8Material13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #1 align 2 {
  %2 = load i32, ptr @_ZN2rw7versionE, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 197631
  %spec.select = select i1 %3, i32 40, i32 28
  %4 = load ptr, ptr %0, align 8, !tbaa !9
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %9, label %5

5:                                                ; preds = %1
  %6 = tail call noundef i32 @_ZN2rw7Texture13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120) %4)
  %7 = add nuw nsw i32 %spec.select, 12
  %8 = add i32 %7, %6
  br label %9

9:                                                ; preds = %5, %1
  %.1 = phi i32 [ %8, %5 ], [ %spec.select, %1 ]
  %10 = tail call noundef i32 @_ZN2rw10PluginList13streamGetSizeEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw8Material9s_plglistE, ptr noundef nonnull %0)
  %11 = add i32 %.1, 12
  %12 = add i32 %11, %10
  ret i32 %12
}

declare noundef i32 @_ZN2rw7Texture13streamGetSizeEv(ptr noundef nonnull align 8 dereferenceable(120)) local_unnamed_addr #0

attributes #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN2rw8MaterialE", !11, i64 0, !12, i64 8, !13, i64 12, !11, i64 24, !6, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTSN2rw4RGBAE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!13 = !{!"_ZTSN2rw17SurfacePropertiesE", !14, i64 0, !14, i64 4, !14, i64 8}
!14 = !{!"float", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass