; LLVM IR from aap/librw :: src/image.ll (ZN2rw8flipDXT3EPhS0_jj)

; 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: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL14flipBlock_halfEPhS0_(ptr noundef, ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL9flipBlockEPhS0_(ptr noundef, ptr noundef) #1

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

26:                                               ; preds = %4
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 2
  br i1 %28, label %29, label %51

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %30, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %31, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %47, %29
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %50

36:                                               ; preds = %32
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_ZN2rwL20flipAlphaBlock3_halfEPhS0_(ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 8
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 8
  call void @_ZN2rwL14flipBlock_halfEPhS0_(ptr noundef %40, ptr noundef %42)
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 16
  store ptr %44, ptr %13, align 8, !tbaa !5
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  store ptr %46, ptr %14, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %36
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %32, !llvm.loop !11

50:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %57

51:                                               ; preds = %26
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = mul nsw i32 16, %54
  %56 = sext i32 %55 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %52, ptr align 1 %53, i64 %56, i1 false)
  br label %57

57:                                               ; preds = %51, %50
  store i32 1, ptr %15, align 4
  br label %107

58:                                               ; preds = %4
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = mul nsw i32 16, %59
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = mul nsw i32 %60, %61
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = sext i32 %62 to i64
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  store ptr %65, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %103, %58
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %70, label %106

70:                                               ; preds = %66
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = mul nsw i32 16, %71
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = sext i32 %72 to i64
  %75 = sub i64 0, %74
  %76 = getelementptr inbounds i8, ptr %73, i64 %75
  store ptr %76, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %77, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %78, ptr %17, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %94, %70
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = load i32, ptr %11, align 4, !tbaa !9
  %82 = icmp slt i32 %80, %81
  br i1 %82, label %83, label %97

83:                                               ; preds = %79
  %84 = load ptr, ptr %17, align 8, !tbaa !5
  %85 = load ptr, ptr %16, align 8, !tbaa !5
  call void @_ZN2rwL15flipAlphaBlock3EPhS0_(ptr noundef %84, ptr noundef %85)
  %86 = load ptr, ptr %17, align 8, !tbaa !5
  %87 = getelementptr inbounds i8, ptr %86, i64 8
  %88 = load ptr, ptr %16, align 8, !tbaa !5
  %89 = getelementptr inbounds i8, ptr %88, i64 8
  call void @_ZN2rwL9flipBlockEPhS0_(ptr noundef %87, ptr noundef %89)
  %90 = load ptr, ptr %16, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i64 16
  store ptr %91, ptr %16, align 8, !tbaa !5
  %92 = load ptr, ptr %17, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i64 16
  store ptr %93, ptr %17, align 8, !tbaa !5
  br label %94

94:                                               ; preds = %83
  %95 = load i32, ptr %9, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %9, align 4, !tbaa !9
  br label %79, !llvm.loop !13

97:                                               ; preds = %79
  %98 = load i32, ptr %11, align 4, !tbaa !9
  %99 = mul nsw i32 16, %98
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = sext i32 %99 to i64
  %102 = getelementptr inbounds i8, ptr %100, i64 %101
  store ptr %102, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %103

103:                                              ; preds = %97
  %104 = load i32, ptr %10, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %10, align 4, !tbaa !9
  br label %66, !llvm.loop !14

106:                                              ; preds = %66
  store i32 0, ptr %15, align 4
  br label %107

107:                                              ; preds = %106, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %108 = load i32, ptr %15, align 4
  switch i32 %108, label %110 [
    i32 0, label %109
    i32 1, label %109
  ]

109:                                              ; preds = %107, %107
  ret void

110:                                              ; preds = %107
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL20flipAlphaBlock3_halfEPhS0_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL15flipAlphaBlock3EPhS0_(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL14flipBlock_halfEPhS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL9flipBlockEPhS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw8flipDXT3EPhS0_jj(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = add i32 %2, 3
  %6 = lshr i32 %5, 2
  %7 = add i32 %3, 3
  %8 = lshr i32 %7, 2
  %9 = icmp ult i32 %3, 4
  br i1 %9, label %10, label %20

10:                                               ; preds = %4
  %11 = icmp eq i32 %3, 2
  br i1 %11, label %.preheader, label %17

.preheader:                                       ; preds = %10
  %.not59 = icmp ult i32 %5, 4
  br i1 %.not59, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.03957 = phi ptr [ %15, %.lr.ph ], [ %0, %.preheader ]
  %.04056 = phi ptr [ %14, %.lr.ph ], [ %1, %.preheader ]
  %.04455 = phi i32 [ %16, %.lr.ph ], [ 0, %.preheader ]
  tail call void @_ZN2rwL20flipAlphaBlock3_halfEPhS0_(ptr noundef %.03957, ptr noundef %.04056)
  %12 = getelementptr inbounds i8, ptr %.03957, i64 8
  %13 = getelementptr inbounds i8, ptr %.04056, i64 8
  tail call void @_ZN2rwL14flipBlock_halfEPhS0_(ptr noundef nonnull %12, ptr noundef nonnull %13)
  %14 = getelementptr inbounds i8, ptr %.04056, i64 16
  %15 = getelementptr inbounds i8, ptr %.03957, i64 16
  %16 = add nuw nsw i32 %.04455, 1
  %exitcond63.not = icmp eq i32 %16, %6
  br i1 %exitcond63.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

17:                                               ; preds = %10
  %18 = shl nsw i32 %6, 4
  %19 = zext nneg i32 %18 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %0, ptr align 1 %1, i64 %19, i1 false)
  br label %.loopexit

20:                                               ; preds = %4
  %.not = icmp ult i32 %7, 4
  br i1 %.not, label %.loopexit, label %.lr.ph54

.lr.ph54:                                         ; preds = %20
  %21 = shl nsw i32 %6, 4
  %22 = zext nneg i32 %21 to i64
  %23 = sub nsw i64 0, %22
  %.not58 = icmp ult i32 %5, 4
  br i1 %.not58, label %.loopexit, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph54
  %24 = mul nuw nsw i32 %21, %8
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %0, i64 %25
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.04152.us = phi ptr [ %27, %._crit_edge.us ], [ %26, %.lr.ph.us.preheader ]
  %.04251.us = phi ptr [ %34, %._crit_edge.us ], [ %1, %.lr.ph.us.preheader ]
  %.04350.us = phi i32 [ %35, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %27 = getelementptr inbounds i8, ptr %.04152.us, i64 %23
  br label %28

28:                                               ; preds = %.lr.ph.us, %28
  %.049.us = phi ptr [ %27, %.lr.ph.us ], [ %32, %28 ]
  %.03848.us = phi ptr [ %.04251.us, %.lr.ph.us ], [ %31, %28 ]
  %.147.us = phi i32 [ 0, %.lr.ph.us ], [ %33, %28 ]
  tail call void @_ZN2rwL15flipAlphaBlock3EPhS0_(ptr noundef %.049.us, ptr noundef %.03848.us)
  %29 = getelementptr inbounds i8, ptr %.049.us, i64 8
  %30 = getelementptr inbounds i8, ptr %.03848.us, i64 8
  tail call void @_ZN2rwL9flipBlockEPhS0_(ptr noundef nonnull %29, ptr noundef nonnull %30)
  %31 = getelementptr inbounds i8, ptr %.03848.us, i64 16
  %32 = getelementptr inbounds i8, ptr %.049.us, i64 16
  %33 = add nuw nsw i32 %.147.us, 1
  %exitcond.not = icmp eq i32 %33, %6
  br i1 %exitcond.not, label %._crit_edge.us, label %28, !llvm.loop !7

._crit_edge.us:                                   ; preds = %28
  %34 = getelementptr inbounds i8, ptr %.04251.us, i64 %22
  %35 = add nuw nsw i32 %.04350.us, 1
  %exitcond62.not = icmp eq i32 %35, %8
  br i1 %exitcond62.not, label %.loopexit, label %.lr.ph.us, !llvm.loop !8

.loopexit:                                        ; preds = %._crit_edge.us, %.lr.ph, %.lr.ph54, %20, %.preheader, %17
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL20flipAlphaBlock3_halfEPhS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rwL15flipAlphaBlock3EPhS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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}
!8 = distinct !{!8, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass