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

; 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
declare dso_local void @wfETC1_DecodeBlock(ptr noalias noundef, ptr noalias noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @wfETC1_DecodeImage(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  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
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = udiv i32 %17, 4
  store i32 %18, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = udiv i32 %19, 4
  store i32 %20, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %48, %4
  %22 = load i32, ptr %14, align 4, !tbaa !9
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = icmp ne i32 %22, %23
  br i1 %24, label %25, label %51

25:                                               ; preds = %21
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %38, %25
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = icmp ne i32 %27, %28
  br i1 %29, label %30, label %41

30:                                               ; preds = %26
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  call void @wfETC1_DecodeBlock(ptr noundef %31, ptr noundef %32, i32 noundef %33)
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 8
  store ptr %35, ptr %9, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  store ptr %37, ptr %10, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %30
  %39 = load i32, ptr %13, align 4, !tbaa !9
  %40 = add i32 %39, 1
  store i32 %40, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !11

41:                                               ; preds = %26
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = mul i32 %42, 4
  %44 = mul i32 %43, 3
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = zext i32 %44 to i64
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  store ptr %47, ptr %10, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %41
  %49 = load i32, ptr %14, align 4, !tbaa !9
  %50 = add i32 %49, 1
  store i32 %50, ptr %14, align 4, !tbaa !9
  br label %21, !llvm.loop !13

51:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

; Function Attrs: nounwind uwtable
declare dso_local void @wfETC1_DecodeBlock(ptr noalias noundef, ptr noalias noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @wfETC1_DecodeImage(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = lshr i32 %2, 2
  %6 = lshr i32 %3, 2
  %.not26 = icmp ult i32 %3, 4
  br i1 %.not26, label %._crit_edge30, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %4
  %.not2021 = icmp ult i32 %2, 4
  %7 = mul i32 %2, 12
  %8 = zext i32 %7 to i64
  br i1 %.not2021, label %._crit_edge30, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %.029 = phi i32 [ %14, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.01728 = phi ptr [ %10, %._crit_edge ], [ %0, %.preheader.lr.ph ]
  %.01827 = phi ptr [ %13, %._crit_edge ], [ %1, %.preheader.lr.ph ]
  br label %9

9:                                                ; preds = %.preheader, %9
  %.01624 = phi i32 [ 0, %.preheader ], [ %12, %9 ]
  %.123 = phi ptr [ %.01728, %.preheader ], [ %10, %9 ]
  %.11922 = phi ptr [ %.01827, %.preheader ], [ %11, %9 ]
  tail call void @wfETC1_DecodeBlock(ptr noundef %.123, ptr noundef %.11922, i32 noundef %2)
  %10 = getelementptr inbounds i8, ptr %.123, i64 8
  %11 = getelementptr inbounds i8, ptr %.11922, i64 16
  %12 = add nuw nsw i32 %.01624, 1
  %.not20 = icmp eq i32 %12, %5
  br i1 %.not20, label %._crit_edge, label %9, !llvm.loop !5

._crit_edge:                                      ; preds = %9
  %13 = getelementptr inbounds i8, ptr %11, i64 %8
  %14 = add nuw nsw i32 %.029, 1
  %.not = icmp eq i32 %14, %6
  br i1 %.not, label %._crit_edge30, label %.preheader, !llvm.loop !7

._crit_edge30:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %4
  ret void
}

attributes #0 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass