; LLVM IR from aap/librw :: src/ps2/ps2raster.ll (ZN2rw3ps220getSizeNativeTextureEPNS_7TextureE)

; 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::Texture" = type { ptr, ptr, %"struct.rw::LLLink", [32 x i8], [32 x i8], i32, i32, %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::ps2::Ps2Raster" = type { i64, i32, i16, i8, i8, i64, i64, i32, i32, i32, i8, ptr, i32 }

@_ZN2rw3ps218nativeRasterOffsetE = external dso_local 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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN2rw3ps220getSizeNativeTextureEPNS_7TextureE(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 20, ptr %3, align 4, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %"struct.rw::Texture", ptr %5, i32 0, i32 3
  %7 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 0
  %8 = call i64 @strlen(ptr noundef %7) #4
  %9 = add i64 12, %8
  %10 = add i64 %9, 4
  %11 = and i64 %10, -4
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = add i64 %13, %11
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %3, align 4, !tbaa !9
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.rw::Texture", ptr %16, i32 0, i32 4
  %18 = getelementptr inbounds [32 x i8], ptr %17, i64 0, i64 0
  %19 = call i64 @strlen(ptr noundef %18) #4
  %20 = add i64 12, %19
  %21 = add i64 %20, 4
  %22 = and i64 %21, -4
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = add i64 %24, %22
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %3, align 4, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add i32 %27, 12
  store i32 %28, ptr %3, align 4, !tbaa !9
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add i32 %29, 76
  store i32 %30, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.rw::Texture", ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr @_ZN2rw3ps218nativeRasterOffsetE, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  store ptr %36, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.rw::ps2::Ps2Raster", ptr %37, i32 0, i32 7
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = add i32 12, %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.rw::ps2::Ps2Raster", ptr %41, i32 0, i32 8
  %43 = load i32, ptr %42, align 4, !tbaa !18
  %44 = add i32 %40, %43
  %45 = load i32, ptr %3, align 4, !tbaa !9
  %46 = add i32 %45, %44
  store i32 %46, ptr %3, align 4, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %47
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!"_ZTSN2rw7TextureE", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 32, !7, i64 64, !10, i64 96, !10, i64 100, !13, i64 104}
!13 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!14 = !{!15, !10, i64 32}
!15 = !{!"_ZTSN2rw3ps29Ps2RasterE", !16, i64 0, !10, i64 8, !17, i64 12, !7, i64 14, !7, i64 15, !16, i64 16, !16, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 44, !6, i64 48, !10, i64 56}
!16 = !{!"long", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!15, !10, i64 36}


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

@_ZN2rw3ps218nativeRasterOffsetE = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN2rw3ps220getSizeNativeTextureEPNS_7TextureE(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #2
  %4 = add i64 %3, 36
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %5) #2
  %7 = and i64 %6, 4294967292
  %8 = add nuw nsw i64 %7, 16
  %9 = and i64 %4, 4294967292
  %10 = add nuw nsw i64 %8, %9
  %11 = trunc i64 %10 to i32
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = load i32, ptr @_ZN2rw3ps218nativeRasterOffsetE, align 4, !tbaa !12
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %12, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 32
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %15, i64 36
  %19 = load i32, ptr %18, align 4, !tbaa !17
  %20 = add i32 %17, 100
  %21 = add i32 %20, %11
  %22 = add i32 %21, %19
  ret i32 %22
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 nofree nounwind willreturn memory(read, inaccessiblemem: none) 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 = { nounwind willreturn memory(read) }

!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, !7, i64 0}
!6 = !{!"_ZTSN2rw7TextureE", !7, i64 0, !7, i64 8, !10, i64 16, !8, i64 32, !8, i64 64, !11, i64 96, !11, i64 100, !10, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN2rw6LLLinkE", !7, i64 0, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 32}
!14 = !{!"_ZTSN2rw3ps29Ps2RasterE", !15, i64 0, !11, i64 8, !16, i64 12, !8, i64 14, !8, i64 15, !15, i64 16, !15, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !8, i64 44, !7, i64 48, !11, i64 56}
!15 = !{!"long", !8, i64 0}
!16 = !{!"short", !8, i64 0}
!17 = !{!14, !11, i64 36}


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