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

; 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::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }
%"struct.rw::ps2::Ps2Raster" = type { i64, i32, i16, i8, i8, i64, i64, i32, i32, i32, i8, ptr, i32 }
%"struct.rw::ps2::Ps2Raster::PixelPtr" = type { ptr, i32, 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: mustprogress uwtable
declare dso_local void @_ZN2rw3ps213swizzleRasterEPNS_6RasterE(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3ps212rasterUnlockEPNS_6RasterEi(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load i32, ptr @_ZN2rw3ps218nativeRasterOffsetE, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %6, i64 %8
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.rw::Raster", ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = and i32 %12, 24576
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN2rw3ps213swizzleRasterEPNS_6RasterE(ptr noundef %16)
  br label %17

17:                                               ; preds = %15, %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.rw::Raster", ptr %18, i32 0, i32 12
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.rw::Raster", ptr %21, i32 0, i32 5
  store i32 %20, ptr %22, align 4, !tbaa !14
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::Raster", ptr %23, i32 0, i32 13
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::Raster", ptr %26, i32 0, i32 6
  store i32 %25, ptr %27, align 8, !tbaa !16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::Raster", ptr %28, i32 0, i32 11
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.rw::Raster", ptr %31, i32 0, i32 9
  store ptr %30, ptr %32, align 8, !tbaa !18
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Raster", ptr %33, i32 0, i32 14
  %35 = load i32, ptr %34, align 8, !tbaa !19
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.rw::Raster", ptr %36, i32 0, i32 8
  store i32 %35, ptr %37, align 8, !tbaa !20
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.rw::ps2::Ps2Raster", ptr %38, i32 0, i32 10
  %40 = load i8, ptr %39, align 4, !tbaa !21
  %41 = sext i8 %40 to i32
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %53

44:                                               ; preds = %17
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.rw::Raster", ptr %45, i32 0, i32 9
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = getelementptr inbounds %"struct.rw::ps2::Ps2Raster::PixelPtr", ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  %50 = getelementptr inbounds i8, ptr %49, i64 80
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.rw::Raster", ptr %51, i32 0, i32 9
  store ptr %50, ptr %52, align 8, !tbaa !18
  br label %53

53:                                               ; preds = %44, %17
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.rw::Raster", ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !27
  %57 = and i32 %56, -7
  store i32 %57, ptr %55, align 4, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 16}
!12 = !{!"_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}
!13 = !{!12, !10, i64 64}
!14 = !{!12, !10, i64 20}
!15 = !{!12, !10, i64 68}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !6, i64 56}
!18 = !{!12, !6, i64 40}
!19 = !{!12, !10, i64 72}
!20 = !{!12, !10, i64 32}
!21 = !{!22, !7, i64 44}
!22 = !{!"_ZTSN2rw3ps29Ps2RasterE", !23, i64 0, !10, i64 8, !24, i64 12, !7, i64 14, !7, i64 15, !23, i64 16, !23, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 44, !6, i64 48, !10, i64 56}
!23 = !{!"long", !7, i64 0}
!24 = !{!"short", !7, i64 0}
!25 = !{!26, !6, i64 0}
!26 = !{!"_ZTSN2rw3ps29Ps2Raster8PixelPtrE", !6, i64 0, !10, i64 8, !10, i64 12}
!27 = !{!12, !10, i64 12}


; 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 uwtable
declare dso_local void @_ZN2rw3ps213swizzleRasterEPNS_6RasterE(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3ps212rasterUnlockEPNS_6RasterEi(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @_ZN2rw3ps218nativeRasterOffsetE, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i8, ptr %0, i64 %4
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = and i32 %7, 24576
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %2
  tail call void @_ZN2rw3ps213swizzleRasterEPNS_6RasterE(ptr noundef nonnull %0)
  br label %10

10:                                               ; preds = %9, %2
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  %12 = getelementptr inbounds i8, ptr %0, i64 20
  %13 = load <2 x i32>, ptr %11, align 8, !tbaa !5
  store <2 x i32> %13, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %15, ptr %16, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %18, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %5, i64 44
  %21 = load i8, ptr %20, align 4, !tbaa !16
  %22 = and i8 %21, 1
  %.not15 = icmp eq i8 %22, 0
  br i1 %.not15, label %26, label %23

23:                                               ; preds = %10
  %24 = load ptr, ptr %15, align 8, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %24, i64 80
  store ptr %25, ptr %16, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %23, %10
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  %28 = load i32, ptr %27, align 4, !tbaa !22
  %29 = and i32 %28, -7
  store i32 %29, ptr %27, align 4, !tbaa !22
  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 16}
!10 = !{!"_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}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 56}
!13 = !{!10, !11, i64 40}
!14 = !{!10, !6, i64 72}
!15 = !{!10, !6, i64 32}
!16 = !{!17, !7, i64 44}
!17 = !{!"_ZTSN2rw3ps29Ps2RasterE", !18, i64 0, !6, i64 8, !19, i64 12, !7, i64 14, !7, i64 15, !18, i64 16, !18, i64 24, !6, i64 32, !6, i64 36, !6, i64 40, !7, i64 44, !11, i64 48, !6, i64 56}
!18 = !{!"long", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!21, !11, i64 0}
!21 = !{!"_ZTSN2rw3ps29Ps2Raster8PixelPtrE", !11, i64 0, !6, i64 8, !6, i64 12}
!22 = !{!10, !6, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass