; LLVM IR from aap/librw :: src/d3d/d3d.ll (ZN2rw3d3d11allocateDXTEPNS_6RasterEiii)

; 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::d3d::D3dRaster" = type { ptr, ptr, ptr, i32, i32, i8, i8, i8 }
%"struct.rw::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }

@_ZN2rw3d3d18nativeRasterOffsetE = external dso_local global i32, align 4
@_ZZN2rw3d3d11allocateDXTEPNS_6RasterEiiiE6dxtMap = external hidden global [5 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw3d3d13createTextureEiiijj(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3d3d11allocateDXTEPNS_6RasterEiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = load i32, ptr @_ZN2rw3d3d18nativeRasterOffsetE, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  store ptr %13, ptr %9, align 8, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sub nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x i32], ptr @_ZZN2rw3d3d11allocateDXTEPNS_6RasterEiiiE6dxtMap, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %19, i32 0, i32 3
  store i32 %18, ptr %20, align 8, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %23, i32 0, i32 5
  %25 = zext i1 %22 to i8
  store i8 %25, ptr %24, align 8, !tbaa !14
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %26, i32 0, i32 6
  store i8 1, ptr %27, align 1, !tbaa !15
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %28, i32 0, i32 7
  %30 = load i8, ptr %29, align 2, !tbaa !16, !range !17, !noundef !18
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %33

32:                                               ; preds = %4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %42

33:                                               ; preds = %4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.rw::Raster", ptr %34, i32 0, i32 4
  %36 = load i32, ptr %35, align 8, !tbaa !19
  %37 = and i32 %36, 32768
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  br label %41

40:                                               ; preds = %33
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %40, %39
  br label %42

42:                                               ; preds = %41, %32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.rw::Raster", ptr %43, i32 0, i32 5
  %45 = load i32, ptr %44, align 4, !tbaa !21
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.rw::Raster", ptr %46, i32 0, i32 6
  %48 = load i32, ptr %47, align 8, !tbaa !22
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %50, i32 0, i32 7
  %52 = load i8, ptr %51, align 2, !tbaa !16, !range !17, !noundef !18
  %53 = trunc i8 %52 to i1
  %54 = zext i1 %53 to i64
  %55 = select i1 %53, i32 1024, i32 0
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 8, !tbaa !11
  %59 = call noundef ptr @_ZN2rw3d3d13createTextureEiiijj(i32 noundef %45, i32 noundef %48, i32 noundef %49, i32 noundef %55, i32 noundef %58)
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.rw::d3d::D3dRaster", ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !23
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.rw::Raster", ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 8, !tbaa !24
  %65 = and i32 %64, -129
  store i32 %65, ptr %63, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 24}
!12 = !{!"_ZTSN2rw3d3d9D3dRasterE", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !13, i64 32, !13, i64 33, !13, i64 34}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !13, i64 32}
!15 = !{!12, !13, i64 33}
!16 = !{!12, !13, i64 34}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !10, i64 16}
!20 = !{!"_ZTSN2rw6RasterE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !10, i64 88, !10, i64 92}
!21 = !{!20, !10, i64 20}
!22 = !{!20, !10, i64 24}
!23 = !{!12, !6, i64 0}
!24 = !{!20, !10, i64 8}


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

@_ZN2rw3d3d18nativeRasterOffsetE = external dso_local local_unnamed_addr global i32, align 4
@_ZZN2rw3d3d11allocateDXTEPNS_6RasterEiiiE6dxtMap = external hidden local_unnamed_addr global [5 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw3d3d13createTextureEiiijj(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3d3d11allocateDXTEPNS_6RasterEiii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr @_ZN2rw3d3d18nativeRasterOffsetE, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 %6
  %8 = add nsw i32 %1, -1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [5 x i32], ptr @_ZZN2rw3d3d11allocateDXTEPNS_6RasterEiiiE6dxtMap, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %7, i64 24
  store i32 %11, ptr %12, align 8, !tbaa !9
  %13 = icmp ne i32 %3, 0
  %14 = getelementptr inbounds i8, ptr %7, i64 32
  %15 = zext i1 %13 to i8
  store i8 %15, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %7, i64 33
  store i8 1, ptr %16, align 1, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %7, i64 34
  %18 = load i8, ptr %17, align 2, !tbaa !15, !range !16, !noundef !17
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %24, label %20

20:                                               ; preds = %4
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = and i32 %22, 32768
  %.not = icmp eq i32 %23, 0
  %spec.select = select i1 %.not, i32 1, i32 %2
  br label %24

24:                                               ; preds = %20, %4
  %25 = phi i32 [ 1024, %4 ], [ 0, %20 ]
  %.0 = phi i32 [ 0, %4 ], [ %spec.select, %20 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 20
  %27 = load i32, ptr %26, align 4, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %30 = tail call noundef ptr @_ZN2rw3d3d13createTextureEiiijj(i32 noundef %27, i32 noundef %29, i32 noundef %.0, i32 noundef %25, i32 noundef %11)
  store ptr %30, ptr %7, align 8, !tbaa !22
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  %32 = load i32, ptr %31, align 8, !tbaa !23
  %33 = and i32 %32, -129
  store i32 %33, ptr %31, align 8, !tbaa !23
  ret void
}

attributes #0 = { 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, !6, i64 24}
!10 = !{!"_ZTSN2rw3d3d9D3dRasterE", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 28, !12, i64 32, !12, i64 33, !12, i64 34}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !12, i64 32}
!14 = !{!10, !12, i64 33}
!15 = !{!10, !12, i64 34}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !6, i64 16}
!19 = !{!"_ZTSN2rw6RasterE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !11, i64 80, !6, i64 88, !6, i64 92}
!20 = !{!19, !6, i64 20}
!21 = !{!19, !6, i64 24}
!22 = !{!10, !11, i64 0}
!23 = !{!19, !6, i64 8}


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