; LLVM IR from TheNachoBIT/GeoFenix-Engine :: Libraries/SOIL2/include (wfETC)

; 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._wfETC1_Block = type { i32, i32 }

@wfETC1_Color3IdxLUT = external dso_local constant [8 x i32], align 16

; 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 uwtable
define dso_local void @wfETC1_ReadColor53(ptr noundef %0, i32 noundef %1, ptr noalias noundef %2, ptr noalias noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = add i32 %14, 3
  %16 = sub i32 64, %15
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = add i32 %17, 3
  %19 = urem i32 %18, 8
  %20 = sub i32 4, %19
  %21 = mul i32 %20, 2
  %22 = sub i32 %16, %21
  store i32 %22, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._wfETC1_Block, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sub i32 %26, 3
  %28 = ashr i32 %25, %27
  %29 = and i32 %28, 248
  store i32 %29, ptr %10, align 4, !tbaa !9
  %30 = load i32, ptr %10, align 4, !tbaa !9
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = ashr i32 %31, 5
  %33 = or i32 %30, %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %33, ptr %34, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sub i32 64, %35
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = urem i32 %37, 8
  %39 = sub i32 4, %38
  %40 = mul i32 %39, 2
  %41 = sub i32 %36, %40
  store i32 %41, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._wfETC1_Block, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = ashr i32 %44, %45
  %47 = and i32 %46, 7
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [8 x i32], ptr @wfETC1_Color3IdxLUT, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  store i32 %50, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = ashr i32 %52, 3
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = add nsw i32 %53, %54
  store i32 %55, ptr %13, align 4, !tbaa !9
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = shl i32 %56, 3
  store i32 %57, ptr %13, align 4, !tbaa !9
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = ashr i32 %58, 5
  %60 = and i32 %59, 7
  %61 = load i32, ptr %13, align 4, !tbaa !9
  %62 = or i32 %61, %60
  store i32 %62, ptr %13, align 4, !tbaa !9
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %63, ptr %64, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_wfETC1_Block", !10, i64 0, !10, i64 4}


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

@wfETC1_Color3IdxLUT = external dso_local local_unnamed_addr constant [8 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @wfETC1_ReadColor53(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noalias nocapture noundef writeonly %2, ptr noalias nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = shl i32 %1, 1
  %6 = add i32 %5, 6
  %7 = and i32 %6, 14
  %8 = load i32, ptr %0, align 4, !tbaa !5
  %reass.sub = sub i32 %7, %1
  %9 = add i32 %reass.sub, 50
  %10 = ashr i32 %8, %9
  %11 = and i32 %10, 248
  %12 = lshr i32 %11, 5
  %13 = or disjoint i32 %12, %11
  store i32 %13, ptr %2, align 4, !tbaa !10
  %14 = and i32 %5, 14
  %reass.sub17 = sub i32 %14, %1
  %15 = add i32 %reass.sub17, 56
  %16 = ashr i32 %8, %15
  %17 = and i32 %16, 7
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds [8 x i32], ptr @wfETC1_Color3IdxLUT, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %21 = shl i32 %20, 3
  %22 = add i32 %21, %11
  %23 = lshr i32 %22, 5
  %24 = and i32 %23, 7
  %25 = or disjoint i32 %24, %22
  store i32 %25, ptr %3, align 4, !tbaa !10
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !7, i64 0}
!6 = !{!"_wfETC1_Block", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}


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