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

; 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::Error" = type { i32, i32 }
%"struct.rw::Image" = type { i32, i32, i32, i32, i32, i32, ptr, ptr }
%"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 }

@_ZN2rw3ps218nativeRasterOffsetE = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) #2

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rw3ps2L15transferMinSizeEiiPiS1_(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw3ps215rasterFromImageEPNS_6RasterEPNS_5ImageE(ptr noundef %0, ptr noundef %1) #5 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %"struct.rw::Error", align 4
  %9 = alloca i32, align 4
  %10 = alloca %"struct.rw::Error", align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr @_ZN2rw3ps218nativeRasterOffsetE, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  store ptr %23, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.rw::Image", ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !11
  switch i32 %26, label %60 [
    i32 24, label %27
    i32 32, label %27
    i32 16, label %39
    i32 8, label %46
    i32 4, label %53
  ]

27:                                               ; preds = %2, %2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::Raster", ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = icmp ne i32 %30, 1280
  br i1 %31, label %32, label %38

32:                                               ; preds = %27
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Raster", ptr %33, i32 0, i32 4
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = icmp ne i32 %35, 1536
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  br label %61

38:                                               ; preds = %32, %27
  br label %72

39:                                               ; preds = %2
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.rw::Raster", ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = icmp ne i32 %42, 256
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  br label %61

45:                                               ; preds = %39
  br label %72

46:                                               ; preds = %2
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.rw::Raster", ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !13
  %50 = icmp ne i32 %49, 9472
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  br label %61

52:                                               ; preds = %46
  store i32 256, ptr %7, align 4, !tbaa !9
  br label %72

53:                                               ; preds = %2
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.rw::Raster", ptr %54, i32 0, i32 4
  %56 = load i32, ptr %55, align 8, !tbaa !13
  %57 = icmp ne i32 %56, 17664
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  br label %61

59:                                               ; preds = %53
  store i32 16, ptr %7, align 4, !tbaa !9
  br label %72

60:                                               ; preds = %2
  br label %61

61:                                               ; preds = %60, %58, %51, %44, %37
  br label %62

62:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %63 = getelementptr inbounds %"struct.rw::Error", ptr %8, i32 0, i32 0
  store i32 2816, ptr %63, align 4, !tbaa !15
  %64 = getelementptr inbounds %"struct.rw::Error", ptr %8, i32 0, i32 1
  store i32 -2147483638, ptr %64, align 4, !tbaa !17
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 1641) #7
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.3, ptr noundef %68) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %70

70:                                               ; preds = %62
  br label %71

71:                                               ; preds = %70
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %289

72:                                               ; preds = %59, %52, %45, %38
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.rw::Raster", ptr %73, i32 0, i32 4
  %75 = load i32, ptr %74, align 8, !tbaa !13
  %76 = and i32 %75, 3840
  %77 = icmp eq i32 %76, 1536
  br i1 %77, label %78, label %89

78:                                               ; preds = %72
  br label %79

79:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %80 = getelementptr inbounds %"struct.rw::Error", ptr %10, i32 0, i32 0
  store i32 2816, ptr %80, align 4, !tbaa !15
  %81 = getelementptr inbounds %"struct.rw::Error", ptr %10, i32 0, i32 1
  store i32 -2147483638, ptr %81, align 4, !tbaa !17
  %82 = load ptr, ptr @stderr, align 8, !tbaa !5
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 1647) #7
  %84 = load ptr, ptr @stderr, align 8, !tbaa !5
  %85 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %84, ptr noundef @.str.3, ptr noundef %85) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %87

87:                                               ; preds = %79
  br label %88

88:                                               ; preds = %87
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %289

89:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %"struct.rw::Image", ptr %90, i32 0, i32 3
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = icmp sle i32 %92, 8
  br i1 %93, label %94, label %127

94:                                               ; preds = %89
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %"struct.rw::Image", ptr %95, i32 0, i32 7
  %97 = load ptr, ptr %96, align 8, !tbaa !18
  store ptr %97, ptr %11, align 8, !tbaa !5
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = call noundef ptr @_ZN2rw6Raster11lockPaletteEi(ptr noundef nonnull align 8 dereferenceable(96) %98, i32 noundef 5)
  store ptr %99, ptr %12, align 8, !tbaa !5
  %100 = load ptr, ptr %12, align 8, !tbaa !5
  %101 = load ptr, ptr %11, align 8, !tbaa !5
  %102 = load i32, ptr %7, align 4, !tbaa !9
  %103 = mul nsw i32 4, %102
  %104 = sext i32 %103 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %100, ptr align 1 %101, i64 %104, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %105

105:                                              ; preds = %122, %94
  %106 = load i32, ptr %13, align 4, !tbaa !9
  %107 = load i32, ptr %7, align 4, !tbaa !9
  %108 = icmp slt i32 %106, %107
  br i1 %108, label %110, label %109

109:                                              ; preds = %105
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %125

110:                                              ; preds = %105
  %111 = load ptr, ptr %12, align 8, !tbaa !5
  %112 = getelementptr inbounds i8, ptr %111, i64 3
  %113 = load i8, ptr %112, align 1, !tbaa !19
  %114 = zext i8 %113 to i32
  %115 = mul nsw i32 %114, 128
  %116 = sdiv i32 %115, 255
  %117 = trunc i32 %116 to i8
  %118 = load ptr, ptr %12, align 8, !tbaa !5
  %119 = getelementptr inbounds i8, ptr %118, i64 3
  store i8 %117, ptr %119, align 1, !tbaa !19
  %120 = load ptr, ptr %12, align 8, !tbaa !5
  %121 = getelementptr inbounds i8, ptr %120, i64 4
  store ptr %121, ptr %12, align 8, !tbaa !5
  br label %122

122:                                              ; preds = %110
  %123 = load i32, ptr %13, align 4, !tbaa !9
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %13, align 4, !tbaa !9
  br label %105, !llvm.loop !20

125:                                              ; preds = %109
  %126 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw6Raster13unlockPaletteEv(ptr noundef nonnull align 8 dereferenceable(96) %126)
  br label %127

127:                                              ; preds = %125, %89
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  %128 = load ptr, ptr %5, align 8, !tbaa !5
  %129 = getelementptr inbounds %"struct.rw::Image", ptr %128, i32 0, i32 3
  %130 = load i32, ptr %129, align 4, !tbaa !11
  %131 = icmp eq i32 %130, 4
  %132 = zext i1 %131 to i64
  %133 = select i1 %131, i32 20, i32 19
  %134 = load ptr, ptr %6, align 8, !tbaa !5
  %135 = getelementptr inbounds %"struct.rw::ps2::Ps2Raster", ptr %134, i32 0, i32 10
  %136 = load i8, ptr %135, align 4, !tbaa !22
  %137 = sext i8 %136 to i32
  call void @_ZN2rw3ps2L15transferMinSizeEiiPiS1_(i32 noundef %133, i32 noundef %137, ptr noundef %14, ptr noundef %15)
  %138 = load ptr, ptr %5, align 8, !tbaa !5
  %139 = getelementptr inbounds %"struct.rw::Image", ptr %138, i32 0, i32 1
  %140 = load i32, ptr %139, align 4, !tbaa !26
  %141 = load i32, ptr %14, align 4, !tbaa !9
  %142 = icmp sgt i32 %140, %141
  br i1 %142, label %143, label %147

143:                                              ; preds = %127
  %144 = load ptr, ptr %5, align 8, !tbaa !5
  %145 = getelementptr inbounds %"struct.rw::Image", ptr %144, i32 0, i32 1
  %146 = load i32, ptr %145, align 4, !tbaa !26
  br label %149

147:                                              ; preds = %127
  %148 = load i32, ptr %14, align 4, !tbaa !9
  br label %149

149:                                              ; preds = %147, %143
  %150 = phi i32 [ %146, %143 ], [ %148, %147 ]
  store i32 %150, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #7
  %151 = load ptr, ptr %5, align 8, !tbaa !5
  %152 = getelementptr inbounds %"struct.rw::Image", ptr %151, i32 0, i32 6
  %153 = load ptr, ptr %152, align 8, !tbaa !27
  store ptr %153, ptr %17, align 8, !tbaa !5
  %154 = load ptr, ptr %4, align 8, !tbaa !5
  %155 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %154, i32 noundef 0, i32 noundef 5)
  store ptr %155, ptr %12, align 8, !tbaa !5
  %156 = load ptr, ptr %5, align 8, !tbaa !5
  %157 = getelementptr inbounds %"struct.rw::Image", ptr %156, i32 0, i32 3
  %158 = load i32, ptr %157, align 4, !tbaa !11
  %159 = icmp eq i32 %158, 4
  br i1 %159, label %160, label %174

160:                                              ; preds = %149
  %161 = load ptr, ptr %12, align 8, !tbaa !5
  %162 = load i32, ptr %16, align 4, !tbaa !9
  %163 = sdiv i32 %162, 2
  %164 = load ptr, ptr %17, align 8, !tbaa !5
  %165 = load ptr, ptr %5, align 8, !tbaa !5
  %166 = getelementptr inbounds %"struct.rw::Image", ptr %165, i32 0, i32 5
  %167 = load i32, ptr %166, align 4, !tbaa !28
  %168 = load ptr, ptr %5, align 8, !tbaa !5
  %169 = getelementptr inbounds %"struct.rw::Image", ptr %168, i32 0, i32 1
  %170 = load i32, ptr %169, align 4, !tbaa !26
  %171 = load ptr, ptr %5, align 8, !tbaa !5
  %172 = getelementptr inbounds %"struct.rw::Image", ptr %171, i32 0, i32 2
  %173 = load i32, ptr %172, align 8, !tbaa !29
  call void @_ZN2rw12compressPal4EPhjS0_jii(ptr noundef %161, i32 noundef %163, ptr noundef %164, i32 noundef %167, i32 noundef %170, i32 noundef %173)
  br label %287

174:                                              ; preds = %149
  %175 = load ptr, ptr %5, align 8, !tbaa !5
  %176 = getelementptr inbounds %"struct.rw::Image", ptr %175, i32 0, i32 3
  %177 = load i32, ptr %176, align 4, !tbaa !11
  %178 = icmp eq i32 %177, 8
  br i1 %178, label %179, label %192

179:                                              ; preds = %174
  %180 = load ptr, ptr %12, align 8, !tbaa !5
  %181 = load i32, ptr %16, align 4, !tbaa !9
  %182 = load ptr, ptr %17, align 8, !tbaa !5
  %183 = load ptr, ptr %5, align 8, !tbaa !5
  %184 = getelementptr inbounds %"struct.rw::Image", ptr %183, i32 0, i32 5
  %185 = load i32, ptr %184, align 4, !tbaa !28
  %186 = load ptr, ptr %5, align 8, !tbaa !5
  %187 = getelementptr inbounds %"struct.rw::Image", ptr %186, i32 0, i32 1
  %188 = load i32, ptr %187, align 4, !tbaa !26
  %189 = load ptr, ptr %5, align 8, !tbaa !5
  %190 = getelementptr inbounds %"struct.rw::Image", ptr %189, i32 0, i32 2
  %191 = load i32, ptr %190, align 8, !tbaa !29
  call void @_ZN2rw8copyPal8EPhjS0_jii(ptr noundef %180, i32 noundef %181, ptr noundef %182, i32 noundef %185, i32 noundef %188, i32 noundef %191)
  br label %286

192:                                              ; preds = %174
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #7
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %193

193:                                              ; preds = %282, %192
  %194 = load i32, ptr %18, align 4, !tbaa !9
  %195 = load ptr, ptr %5, align 8, !tbaa !5
  %196 = getelementptr inbounds %"struct.rw::Image", ptr %195, i32 0, i32 2
  %197 = load i32, ptr %196, align 8, !tbaa !29
  %198 = icmp slt i32 %194, %197
  br i1 %198, label %200, label %199

199:                                              ; preds = %193
  store i32 11, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #7
  br label %285

200:                                              ; preds = %193
  %201 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %201, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #7
  store i32 0, ptr %19, align 4, !tbaa !9
  br label %202

202:                                              ; preds = %272, %200
  %203 = load i32, ptr %19, align 4, !tbaa !9
  %204 = load ptr, ptr %5, align 8, !tbaa !5
  %205 = getelementptr inbounds %"struct.rw::Image", ptr %204, i32 0, i32 1
  %206 = load i32, ptr %205, align 4, !tbaa !26
  %207 = icmp slt i32 %203, %206
  br i1 %207, label %209, label %208

208:                                              ; preds = %202
  store i32 14, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #7
  br label %275

209:                                              ; preds = %202
  %210 = load ptr, ptr %5, align 8, !tbaa !5
  %211 = getelementptr inbounds %"struct.rw::Image", ptr %210, i32 0, i32 3
  %212 = load i32, ptr %211, align 4, !tbaa !11
  switch i32 %212, label %265 [
    i32 16, label %213
    i32 24, label %218
    i32 32, label %238
  ]

213:                                              ; preds = %209
  %214 = load ptr, ptr %12, align 8, !tbaa !5
  %215 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_ZN2rw27conv_ARGB1555_from_ABGR1555EPhS0_(ptr noundef %214, ptr noundef %215)
  %216 = load ptr, ptr %12, align 8, !tbaa !5
  %217 = getelementptr inbounds i8, ptr %216, i64 2
  store ptr %217, ptr %12, align 8, !tbaa !5
  br label %265

218:                                              ; preds = %209
  %219 = load ptr, ptr %11, align 8, !tbaa !5
  %220 = getelementptr inbounds i8, ptr %219, i64 0
  %221 = load i8, ptr %220, align 1, !tbaa !19
  %222 = load ptr, ptr %12, align 8, !tbaa !5
  %223 = getelementptr inbounds i8, ptr %222, i64 0
  store i8 %221, ptr %223, align 1, !tbaa !19
  %224 = load ptr, ptr %11, align 8, !tbaa !5
  %225 = getelementptr inbounds i8, ptr %224, i64 1
  %226 = load i8, ptr %225, align 1, !tbaa !19
  %227 = load ptr, ptr %12, align 8, !tbaa !5
  %228 = getelementptr inbounds i8, ptr %227, i64 1
  store i8 %226, ptr %228, align 1, !tbaa !19
  %229 = load ptr, ptr %11, align 8, !tbaa !5
  %230 = getelementptr inbounds i8, ptr %229, i64 2
  %231 = load i8, ptr %230, align 1, !tbaa !19
  %232 = load ptr, ptr %12, align 8, !tbaa !5
  %233 = getelementptr inbounds i8, ptr %232, i64 2
  store i8 %231, ptr %233, align 1, !tbaa !19
  %234 = load ptr, ptr %12, align 8, !tbaa !5
  %235 = getelementptr inbounds i8, ptr %234, i64 3
  store i8 -128, ptr %235, align 1, !tbaa !19
  %236 = load ptr, ptr %12, align 8, !tbaa !5
  %237 = getelementptr inbounds i8, ptr %236, i64 4
  store ptr %237, ptr %12, align 8, !tbaa !5
  br label %265

238:                                              ; preds = %209
  %239 = load ptr, ptr %11, align 8, !tbaa !5
  %240 = getelementptr inbounds i8, ptr %239, i64 0
  %241 = load i8, ptr %240, align 1, !tbaa !19
  %242 = load ptr, ptr %12, align 8, !tbaa !5
  %243 = getelementptr inbounds i8, ptr %242, i64 0
  store i8 %241, ptr %243, align 1, !tbaa !19
  %244 = load ptr, ptr %11, align 8, !tbaa !5
  %245 = getelementptr inbounds i8, ptr %244, i64 1
  %246 = load i8, ptr %245, align 1, !tbaa !19
  %247 = load ptr, ptr %12, align 8, !tbaa !5
  %248 = getelementptr inbounds i8, ptr %247, i64 1
  store i8 %246, ptr %248, align 1, !tbaa !19
  %249 = load ptr, ptr %11, align 8, !tbaa !5
  %250 = getelementptr inbounds i8, ptr %249, i64 2
  %251 = load i8, ptr %250, align 1, !tbaa !19
  %252 = load ptr, ptr %12, align 8, !tbaa !5
  %253 = getelementptr inbounds i8, ptr %252, i64 2
  store i8 %251, ptr %253, align 1, !tbaa !19
  %254 = load ptr, ptr %11, align 8, !tbaa !5
  %255 = getelementptr inbounds i8, ptr %254, i64 3
  %256 = load i8, ptr %255, align 1, !tbaa !19
  %257 = zext i8 %256 to i32
  %258 = mul nsw i32 %257, 128
  %259 = sdiv i32 %258, 255
  %260 = trunc i32 %259 to i8
  %261 = load ptr, ptr %12, align 8, !tbaa !5
  %262 = getelementptr inbounds i8, ptr %261, i64 3
  store i8 %260, ptr %262, align 1, !tbaa !19
  %263 = load ptr, ptr %12, align 8, !tbaa !5
  %264 = getelementptr inbounds i8, ptr %263, i64 4
  store ptr %264, ptr %12, align 8, !tbaa !5
  br label %265

265:                                              ; preds = %238, %218, %213, %209
  %266 = load ptr, ptr %5, align 8, !tbaa !5
  %267 = getelementptr inbounds %"struct.rw::Image", ptr %266, i32 0, i32 4
  %268 = load i32, ptr %267, align 8, !tbaa !30
  %269 = load ptr, ptr %11, align 8, !tbaa !5
  %270 = sext i32 %268 to i64
  %271 = getelementptr inbounds i8, ptr %269, i64 %270
  store ptr %271, ptr %11, align 8, !tbaa !5
  br label %272

272:                                              ; preds = %265
  %273 = load i32, ptr %19, align 4, !tbaa !9
  %274 = add nsw i32 %273, 1
  store i32 %274, ptr %19, align 4, !tbaa !9
  br label %202, !llvm.loop !31

275:                                              ; preds = %208
  %276 = load ptr, ptr %5, align 8, !tbaa !5
  %277 = getelementptr inbounds %"struct.rw::Image", ptr %276, i32 0, i32 5
  %278 = load i32, ptr %277, align 4, !tbaa !28
  %279 = load ptr, ptr %17, align 8, !tbaa !5
  %280 = sext i32 %278 to i64
  %281 = getelementptr inbounds i8, ptr %279, i64 %280
  store ptr %281, ptr %17, align 8, !tbaa !5
  br label %282

282:                                              ; preds = %275
  %283 = load i32, ptr %18, align 4, !tbaa !9
  %284 = add nsw i32 %283, 1
  store i32 %284, ptr %18, align 4, !tbaa !9
  br label %193, !llvm.loop !32

285:                                              ; preds = %199
  br label %286

286:                                              ; preds = %285, %179
  br label %287

287:                                              ; preds = %286, %160
  %288 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %288, i32 noundef 0)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %289

289:                                              ; preds = %287, %88, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %290 = load i32, ptr %3, align 4
  ret i32 %290
}

declare noundef ptr @_ZN2rw6Raster11lockPaletteEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) #2

declare void @_ZN2rw6Raster13unlockPaletteEv(ptr noundef nonnull align 8 dereferenceable(96)) #2

declare noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef, i32 noundef) #2

declare void @_ZN2rw12compressPal4EPhjS0_jii(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare void @_ZN2rw8copyPal8EPhjS0_jii(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN2rw27conv_ARGB1555_from_ABGR1555EPhS0_(ptr noundef, ptr noundef) #6

declare void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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" }
attributes #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { inlinehint 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 #7 = { 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 12}
!12 = !{!"_ZTSN2rw5ImageE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32}
!13 = !{!14, !10, i64 16}
!14 = !{!"_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}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN2rw5ErrorE", !10, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 4}
!18 = !{!12, !6, i64 32}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !7, i64 44}
!23 = !{!"_ZTSN2rw3ps29Ps2RasterE", !24, i64 0, !10, i64 8, !25, i64 12, !7, i64 14, !7, i64 15, !24, i64 16, !24, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 44, !6, i64 48, !10, i64 56}
!24 = !{!"long", !7, i64 0}
!25 = !{!"short", !7, i64 0}
!26 = !{!12, !10, i64 4}
!27 = !{!12, !6, i64 24}
!28 = !{!12, !10, i64 20}
!29 = !{!12, !10, i64 8}
!30 = !{!12, !10, i64 16}
!31 = distinct !{!31, !21}
!32 = distinct !{!32, !21}


; 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::Error" = type { i32, i32 }

@_ZN2rw3ps218nativeRasterOffsetE = external dso_local local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) local_unnamed_addr #2

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rw3ps2L15transferMinSizeEiiPiS1_(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN2rw3ps215rasterFromImageEPNS_6RasterEPNS_5ImageE(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #5 {
  %3 = alloca %"struct.rw::Error", align 4
  %4 = alloca %"struct.rw::Error", align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = load i32, ptr @_ZN2rw3ps218nativeRasterOffsetE, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 %8
  %10 = getelementptr inbounds i8, ptr %1, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = add i32 %11, -4
  %13 = tail call i32 @llvm.fshl.i32(i32 %12, i32 %12, i32 30)
  switch i32 %13, label %26 [
    i32 5, label %14
    i32 7, label %14
    i32 3, label %17
    i32 1, label %20
    i32 0, label %23
  ]

14:                                               ; preds = %2, %2
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !12
  switch i32 %16, label %26 [
    i32 1280, label %33
    i32 1536, label %33
  ]

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %.not86 = icmp eq i32 %19, 256
  br i1 %.not86, label %.thread, label %26

20:                                               ; preds = %2
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %.not85 = icmp eq i32 %22, 9472
  br i1 %.not85, label %.thread, label %26

23:                                               ; preds = %2
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i32, ptr %24, align 8, !tbaa !12
  %.not = icmp eq i32 %25, 17664
  br i1 %.not, label %.thread, label %26

26:                                               ; preds = %14, %17, %20, %23, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  store i32 2816, ptr %3, align 4, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 -2147483638, ptr %27, align 4, !tbaa !16
  %28 = load ptr, ptr @stderr, align 8, !tbaa !17
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 1641) #9
  %30 = load ptr, ptr @stderr, align 8, !tbaa !17
  %31 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str.3, ptr noundef %31) #9
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  br label %151

33:                                               ; preds = %14, %14
  %34 = and i32 %16, 3840
  %35 = icmp eq i32 %34, 1536
  br i1 %35, label %36, label %.thread

36:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  store i32 2816, ptr %4, align 4, !tbaa !14
  %37 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 -2147483638, ptr %37, align 4, !tbaa !16
  %38 = load ptr, ptr @stderr, align 8, !tbaa !17
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 1647) #9
  %40 = load ptr, ptr @stderr, align 8, !tbaa !17
  %41 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.3, ptr noundef %41) #9
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  br label %151

.thread:                                          ; preds = %23, %20, %17, %33
  %.080104 = phi i32 [ 0, %33 ], [ 16, %23 ], [ 256, %20 ], [ 0, %17 ]
  %43 = phi i1 [ false, %33 ], [ true, %23 ], [ true, %20 ], [ false, %17 ]
  %44 = icmp slt i32 %11, 9
  br i1 %44, label %45, label %73

45:                                               ; preds = %.thread
  %46 = getelementptr inbounds i8, ptr %1, i64 32
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = tail call noundef ptr @_ZN2rw6Raster11lockPaletteEi(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef 5)
  %49 = shl nuw nsw i32 %.080104, 2
  %50 = zext nneg i32 %49 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %47, i64 %50, i1 false)
  br i1 %43, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %45
  %umax = tail call i32 @llvm.umax.i32(i32 %.080104, i32 1)
  %xtraiter = and i32 %umax, 1
  %51 = icmp eq i32 %umax, 1
  br i1 %51, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %umax, 272
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.07890.unr = phi ptr [ %48, %.lr.ph.preheader ], [ %72, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %52 = getelementptr inbounds i8, ptr %.07890.unr, i64 3
  %53 = load i8, ptr %52, align 1, !tbaa !19
  %54 = zext i8 %53 to i16
  %55 = shl nuw nsw i16 %54, 7
  %56 = udiv i16 %55, 255
  %57 = trunc nuw i16 %56 to i8
  store i8 %57, ptr %52, align 1, !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %45
  tail call void @_ZN2rw6Raster13unlockPaletteEv(ptr noundef nonnull align 8 dereferenceable(96) %0)
  %.pre = load i32, ptr %10, align 4, !tbaa !9
  %58 = icmp eq i32 %.pre, 4
  %59 = select i1 %58, i32 20, i32 19
  br label %73

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.07890 = phi ptr [ %48, %.lr.ph.preheader.new ], [ %72, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %60 = getelementptr inbounds i8, ptr %.07890, i64 3
  %61 = load i8, ptr %60, align 1, !tbaa !19
  %62 = zext i8 %61 to i16
  %63 = shl nuw nsw i16 %62, 7
  %64 = udiv i16 %63, 255
  %65 = trunc nuw i16 %64 to i8
  store i8 %65, ptr %60, align 1, !tbaa !19
  %66 = getelementptr inbounds i8, ptr %.07890, i64 7
  %67 = load i8, ptr %66, align 1, !tbaa !19
  %68 = zext i8 %67 to i16
  %69 = shl nuw nsw i16 %68, 7
  %70 = udiv i16 %69, 255
  %71 = trunc nuw i16 %70 to i8
  store i8 %71, ptr %66, align 1, !tbaa !19
  %72 = getelementptr inbounds i8, ptr %.07890, i64 8
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !20

73:                                               ; preds = %._crit_edge, %.thread
  %74 = phi i32 [ %59, %._crit_edge ], [ 19, %.thread ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #8
  %75 = getelementptr inbounds i8, ptr %9, i64 44
  %76 = load i8, ptr %75, align 4, !tbaa !22
  %77 = sext i8 %76 to i32
  call void @_ZN2rw3ps2L15transferMinSizeEiiPiS1_(i32 noundef %74, i32 noundef %77, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %78 = getelementptr inbounds i8, ptr %1, i64 4
  %79 = load i32, ptr %78, align 4, !tbaa !26
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %. = call i32 @llvm.smax.i32(i32 %79, i32 %80)
  %81 = getelementptr inbounds i8, ptr %1, i64 24
  %82 = load ptr, ptr %81, align 8, !tbaa !27
  %83 = call noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef 0, i32 noundef 5)
  %84 = load i32, ptr %10, align 4, !tbaa !9
  switch i32 %84, label %.preheader89 [
    i32 4, label %92
    i32 8, label %99
  ]

.preheader89:                                     ; preds = %73
  %85 = getelementptr inbounds i8, ptr %1, i64 8
  %86 = load i32, ptr %85, align 8, !tbaa !28
  %87 = icmp sgt i32 %86, 0
  br i1 %87, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %.preheader89
  %88 = getelementptr inbounds i8, ptr %1, i64 16
  %89 = getelementptr inbounds i8, ptr %1, i64 20
  %90 = load i32, ptr %78, align 4, !tbaa !26
  %91 = icmp sgt i32 %90, 0
  br i1 %91, label %.preheader, label %.loopexit

92:                                               ; preds = %73
  %93 = sdiv i32 %., 2
  %94 = getelementptr inbounds i8, ptr %1, i64 20
  %95 = load i32, ptr %94, align 4, !tbaa !29
  %96 = load i32, ptr %78, align 4, !tbaa !26
  %97 = getelementptr inbounds i8, ptr %1, i64 8
  %98 = load i32, ptr %97, align 8, !tbaa !28
  call void @_ZN2rw12compressPal4EPhjS0_jii(ptr noundef %83, i32 noundef %93, ptr noundef %82, i32 noundef %95, i32 noundef %96, i32 noundef %98)
  br label %.loopexit

99:                                               ; preds = %73
  %100 = getelementptr inbounds i8, ptr %1, i64 20
  %101 = load i32, ptr %100, align 4, !tbaa !29
  %102 = load i32, ptr %78, align 4, !tbaa !26
  %103 = getelementptr inbounds i8, ptr %1, i64 8
  %104 = load i32, ptr %103, align 8, !tbaa !28
  call void @_ZN2rw8copyPal8EPhjS0_jii(ptr noundef %83, i32 noundef %., ptr noundef %82, i32 noundef %101, i32 noundef %102, i32 noundef %104)
  br label %.loopexit

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge96
  %105 = phi i32 [ %108, %._crit_edge96 ], [ %86, %.preheader.lr.ph ]
  %106 = phi i32 [ %109, %._crit_edge96 ], [ %90, %.preheader.lr.ph ]
  %.07499 = phi i32 [ %113, %._crit_edge96 ], [ 0, %.preheader.lr.ph ]
  %.07598 = phi ptr [ %112, %._crit_edge96 ], [ %82, %.preheader.lr.ph ]
  %.197 = phi ptr [ %.2.lcssa, %._crit_edge96 ], [ %83, %.preheader.lr.ph ]
  %107 = icmp sgt i32 %106, 0
  br i1 %107, label %.lr.ph95, label %._crit_edge96

._crit_edge96.loopexit:                           ; preds = %144
  %.pre101 = load i32, ptr %85, align 8, !tbaa !28
  br label %._crit_edge96

._crit_edge96:                                    ; preds = %._crit_edge96.loopexit, %.preheader
  %108 = phi i32 [ %105, %.preheader ], [ %.pre101, %._crit_edge96.loopexit ]
  %109 = phi i32 [ %106, %.preheader ], [ %149, %._crit_edge96.loopexit ]
  %.2.lcssa = phi ptr [ %.197, %.preheader ], [ %.3, %._crit_edge96.loopexit ]
  %110 = load i32, ptr %89, align 4, !tbaa !29
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i8, ptr %.07598, i64 %111
  %113 = add nuw nsw i32 %.07499, 1
  %114 = icmp slt i32 %113, %108
  br i1 %114, label %.preheader, label %.loopexit, !llvm.loop !30

.lr.ph95:                                         ; preds = %.preheader, %144
  %.094 = phi i32 [ %148, %144 ], [ 0, %.preheader ]
  %.293 = phi ptr [ %.3, %144 ], [ %.197, %.preheader ]
  %.07992 = phi ptr [ %147, %144 ], [ %.07598, %.preheader ]
  %115 = load i32, ptr %10, align 4, !tbaa !9
  switch i32 %115, label %144 [
    i32 16, label %116
    i32 24, label %118
    i32 32, label %128
  ]

116:                                              ; preds = %.lr.ph95
  call void @_ZN2rw27conv_ARGB1555_from_ABGR1555EPhS0_(ptr noundef %.293, ptr noundef %.07992)
  %117 = getelementptr inbounds i8, ptr %.293, i64 2
  br label %144

118:                                              ; preds = %.lr.ph95
  %119 = load i8, ptr %.07992, align 1, !tbaa !19
  store i8 %119, ptr %.293, align 1, !tbaa !19
  %120 = getelementptr inbounds i8, ptr %.07992, i64 1
  %121 = load i8, ptr %120, align 1, !tbaa !19
  %122 = getelementptr inbounds i8, ptr %.293, i64 1
  store i8 %121, ptr %122, align 1, !tbaa !19
  %123 = getelementptr inbounds i8, ptr %.07992, i64 2
  %124 = load i8, ptr %123, align 1, !tbaa !19
  %125 = getelementptr inbounds i8, ptr %.293, i64 2
  store i8 %124, ptr %125, align 1, !tbaa !19
  %126 = getelementptr inbounds i8, ptr %.293, i64 3
  store i8 -128, ptr %126, align 1, !tbaa !19
  %127 = getelementptr inbounds i8, ptr %.293, i64 4
  br label %144

128:                                              ; preds = %.lr.ph95
  %129 = load i8, ptr %.07992, align 1, !tbaa !19
  store i8 %129, ptr %.293, align 1, !tbaa !19
  %130 = getelementptr inbounds i8, ptr %.07992, i64 1
  %131 = load i8, ptr %130, align 1, !tbaa !19
  %132 = getelementptr inbounds i8, ptr %.293, i64 1
  store i8 %131, ptr %132, align 1, !tbaa !19
  %133 = getelementptr inbounds i8, ptr %.07992, i64 2
  %134 = load i8, ptr %133, align 1, !tbaa !19
  %135 = getelementptr inbounds i8, ptr %.293, i64 2
  store i8 %134, ptr %135, align 1, !tbaa !19
  %136 = getelementptr inbounds i8, ptr %.07992, i64 3
  %137 = load i8, ptr %136, align 1, !tbaa !19
  %138 = zext i8 %137 to i16
  %139 = shl nuw nsw i16 %138, 7
  %140 = udiv i16 %139, 255
  %141 = trunc nuw i16 %140 to i8
  %142 = getelementptr inbounds i8, ptr %.293, i64 3
  store i8 %141, ptr %142, align 1, !tbaa !19
  %143 = getelementptr inbounds i8, ptr %.293, i64 4
  br label %144

144:                                              ; preds = %128, %118, %116, %.lr.ph95
  %.3 = phi ptr [ %.293, %.lr.ph95 ], [ %143, %128 ], [ %127, %118 ], [ %117, %116 ]
  %145 = load i32, ptr %88, align 8, !tbaa !32
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds i8, ptr %.07992, i64 %146
  %148 = add nuw nsw i32 %.094, 1
  %149 = load i32, ptr %78, align 4, !tbaa !26
  %150 = icmp slt i32 %148, %149
  br i1 %150, label %.lr.ph95, label %._crit_edge96.loopexit, !llvm.loop !33

.loopexit:                                        ; preds = %._crit_edge96, %.preheader.lr.ph, %.preheader89, %99, %92
  call void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96) %0, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  br label %151

151:                                              ; preds = %.loopexit, %36, %26
  %.076 = phi i32 [ 0, %26 ], [ 0, %36 ], [ 1, %.loopexit ]
  ret i32 %.076
}

declare noundef ptr @_ZN2rw6Raster11lockPaletteEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) local_unnamed_addr #2

declare void @_ZN2rw6Raster13unlockPaletteEv(ptr noundef nonnull align 8 dereferenceable(96)) local_unnamed_addr #2

declare noundef ptr @_ZN2rw6Raster4lockEii(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @_ZN2rw12compressPal4EPhjS0_jii(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @_ZN2rw8copyPal8EPhjS0_jii(ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN2rw27conv_ARGB1555_from_ABGR1555EPhS0_(ptr noundef, ptr noundef) local_unnamed_addr #6

declare void @_ZN2rw6Raster6unlockEi(ptr noundef nonnull align 8 dereferenceable(96), i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #7

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #7

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #7

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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" }
attributes #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { inlinehint 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 #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { cold 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 12}
!10 = !{!"_ZTSN2rw5ImageE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !11, i64 24, !11, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"_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}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN2rw5ErrorE", !6, i64 0, !6, i64 4}
!16 = !{!15, !6, i64 4}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !11, i64 32}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!23, !7, i64 44}
!23 = !{!"_ZTSN2rw3ps29Ps2RasterE", !24, i64 0, !6, i64 8, !25, i64 12, !7, i64 14, !7, i64 15, !24, i64 16, !24, i64 24, !6, i64 32, !6, i64 36, !6, i64 40, !7, i64 44, !11, i64 48, !6, i64 56}
!24 = !{!"long", !7, i64 0}
!25 = !{!"short", !7, i64 0}
!26 = !{!10, !6, i64 4}
!27 = !{!10, !11, i64 24}
!28 = !{!10, !6, i64 8}
!29 = !{!10, !6, i64 20}
!30 = distinct !{!30, !21, !31}
!31 = !{!"llvm.loop.unswitch.partial.disable"}
!32 = !{!10, !6, i64 16}
!33 = distinct !{!33, !21}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass