; LLVM IR from TobiasKozel/VAE :: external/tracy/client/TracyDxt1.ll (ZN5tracy17CompressImageDxt1EPKcPcii)

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

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__._ZN5tracy17CompressImageDxt1EPKcPcii = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5tracy17CompressImageDxt1EPKcPcii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [16 x i32], align 16
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  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
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = srem i32 %15, 4
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %4
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = srem i32 %19, 4
  %21 = icmp eq i32 %20, 0
  br label %22

22:                                               ; preds = %18, %4
  %23 = phi i1 [ false, %4 ], [ %21, %18 ]
  br i1 %23, label %24, label %25

24:                                               ; preds = %22
  br label %27

25:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 584, ptr noundef @__PRETTY_FUNCTION__._ZN5tracy17CompressImageDxt1EPKcPcii) #5
  unreachable

26:                                               ; No predecessors!
  br label %27

27:                                               ; preds = %26, %24
  call void @llvm.lifetime.start.p0(i64 64, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %28, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = mul nsw i32 %29, %30
  %32 = sdiv i32 %31, 16
  store i32 %32, ptr %12, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %78, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %34 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  store ptr %34, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %35, ptr align 1 %36, i64 16, i1 false)
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = mul nsw i32 %40, 4
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %38, ptr align 1 %43, i64 16, i1 false)
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 32
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = mul nsw i32 %47, 8
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %46, i64 %49
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %45, ptr align 1 %50, i64 16, i1 false)
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 48
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !9
  %55 = mul nsw i32 %54, 12
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %53, i64 %56
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %52, ptr align 1 %57, i64 16, i1 false)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 16
  store ptr %59, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %10, align 4, !tbaa !9
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = sdiv i32 %62, 4
  %64 = icmp eq i32 %61, %63
  br i1 %64, label %65, label %72

65:                                               ; preds = %33
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = mul nsw i32 %66, 3
  %68 = mul nsw i32 %67, 4
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  store ptr %71, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %65, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %73 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  %74 = call noundef i64 @_ZN5tracyL10ProcessRGBEPKh(ptr noundef %73)
  store i64 %74, ptr %14, align 8, !tbaa !11
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %75, ptr align 8 %14, i64 8, i1 false)
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 8
  store ptr %77, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %78

78:                                               ; preds = %72
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = add nsw i32 %79, -1
  store i32 %80, ptr %12, align 4, !tbaa !9
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %33, label %82, !llvm.loop !13

82:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 64, ptr %9) #6
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; 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) #3

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZN5tracyL10ProcessRGBEPKh(ptr noundef) #4

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

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 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { alwaysinline 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 #5 = { noreturn nounwind }
attributes #6 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [85 x i8], align 1
@__PRETTY_FUNCTION__._ZN5tracy17CompressImageDxt1EPKcPcii = external hidden unnamed_addr constant [62 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5tracy17CompressImageDxt1EPKcPcii(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [16 x i32], align 16
  %6 = or i32 %3, %2
  %7 = and i32 %6, 3
  %or.cond = icmp eq i32 %7, 0
  br i1 %or.cond, label %8, label %.critedge

.critedge:                                        ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 584, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5tracy17CompressImageDxt1EPKcPcii) #5
  unreachable

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #6
  %9 = mul nsw i32 %3, %2
  %10 = ashr exact i32 %9, 4
  %11 = getelementptr inbounds i8, ptr %5, i64 16
  %12 = shl nsw i32 %2, 2
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %5, i64 32
  %15 = shl nsw i32 %2, 3
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %5, i64 48
  %18 = mul nsw i32 %2, 12
  %19 = sext i32 %18 to i64
  %20 = ashr exact i32 %2, 2
  br label %21

21:                                               ; preds = %21, %8
  %.026 = phi ptr [ %1, %8 ], [ %29, %21 ]
  %.025 = phi i32 [ %10, %8 ], [ %30, %21 ]
  %.023 = phi i32 [ 0, %8 ], [ %.124, %21 ]
  %.0 = phi ptr [ %0, %8 ], [ %.1, %21 ]
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %5, ptr noundef nonnull align 1 dereferenceable(16) %.0, i64 16, i1 false)
  %22 = getelementptr inbounds i8, ptr %.0, i64 %13
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %11, ptr noundef nonnull align 1 dereferenceable(16) %22, i64 16, i1 false)
  %23 = getelementptr inbounds i8, ptr %.0, i64 %16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %14, ptr noundef nonnull align 1 dereferenceable(16) %23, i64 16, i1 false)
  %24 = getelementptr inbounds i8, ptr %.0, i64 %19
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %17, ptr noundef nonnull align 1 dereferenceable(16) %24, i64 16, i1 false)
  %25 = getelementptr inbounds i8, ptr %.0, i64 16
  %26 = add nsw i32 %.023, 1
  %27 = icmp eq i32 %26, %20
  %.124 = select i1 %27, i32 0, i32 %26
  %.1.idx = select i1 %27, i64 %19, i64 0
  %.1 = getelementptr inbounds i8, ptr %25, i64 %.1.idx
  %28 = call noundef i64 @_ZN5tracyL10ProcessRGBEPKh(ptr noundef nonnull %5)
  store i64 %28, ptr %.026, align 1
  %29 = getelementptr inbounds i8, ptr %.026, i64 8
  %30 = add nsw i32 %.025, -1
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %31, label %21, !llvm.loop !5

31:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #6
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

; 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) #3

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef i64 @_ZN5tracyL10ProcessRGBEPKh(ptr noundef) local_unnamed_addr #4

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

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 = { noreturn 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { alwaysinline 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 #5 = { noreturn nounwind }
attributes #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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