; LLVM IR from aap/librw :: src/image.ll (ZN2rw8flipDXT1EPhS0_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 uwtable
define dso_local void @_ZN2rw8flipDXT1EPhS0_jj(ptr noundef %0, ptr 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 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 %54

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

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 = %43, %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 %46

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

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

46:                                               ; 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 %53

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

53:                                               ; preds = %47, %46
  store i32 1, ptr %15, align 4
  br label %99

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

62:                                               ; preds = %95, %54
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %66, label %98

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

75:                                               ; preds = %86, %66
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %89

79:                                               ; preds = %75
  %80 = load ptr, ptr %17, align 8, !tbaa !5
  %81 = load ptr, ptr %16, align 8, !tbaa !5
  call void @_ZN2rwL9flipBlockEPhS0_(ptr noundef %80, ptr noundef %81)
  %82 = load ptr, ptr %16, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i64 8
  store ptr %83, ptr %16, align 8, !tbaa !5
  %84 = load ptr, ptr %17, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 8
  store ptr %85, ptr %17, align 8, !tbaa !5
  br label %86

86:                                               ; preds = %79
  %87 = load i32, ptr %9, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %9, align 4, !tbaa !9
  br label %75, !llvm.loop !13

89:                                               ; preds = %75
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = mul nsw i32 8, %90
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = sext i32 %91 to i64
  %94 = getelementptr inbounds i8, ptr %92, i64 %93
  store ptr %94, 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 %95

95:                                               ; preds = %89
  %96 = load i32, ptr %10, align 4, !tbaa !9
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %10, align 4, !tbaa !9
  br label %62, !llvm.loop !14

98:                                               ; preds = %62
  store i32 0, ptr %15, align 4
  br label %99

99:                                               ; preds = %98, %53
  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
  %100 = load i32, ptr %15, align 4
  switch i32 %100, label %102 [
    i32 0, label %101
    i32 1, label %101
  ]

101:                                              ; preds = %99, %99
  ret void

102:                                              ; preds = %99
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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
define dso_local void @_ZN2rw8flipDXT1EPhS0_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 %16

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

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

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.04051 = phi i32 [ %12, %.lr.ph ], [ 0, %.preheader ]
  tail call void @_ZN2rwL14flipBlock_halfEPhS0_(ptr noundef %0, ptr noundef %1)
  %12 = add nuw nsw i32 %.04051, 1
  %exitcond57.not = icmp eq i32 %12, %6
  br i1 %exitcond57.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

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

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

.lr.ph50:                                         ; preds = %16
  %17 = shl nsw i32 %6, 3
  %18 = zext nneg i32 %17 to i64
  %19 = sub nsw i64 0, %18
  %.not52 = icmp ult i32 %5, 4
  br i1 %.not52, label %.loopexit, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph50
  %20 = mul nuw nsw i32 %17, %8
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %0, i64 %21
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.03748.us = phi ptr [ %23, %._crit_edge.us ], [ %22, %.lr.ph.us.preheader ]
  %.03847.us = phi ptr [ %28, %._crit_edge.us ], [ %1, %.lr.ph.us.preheader ]
  %.03946.us = phi i32 [ %29, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %23 = getelementptr inbounds i8, ptr %.03748.us, i64 %19
  br label %24

24:                                               ; preds = %.lr.ph.us, %24
  %.045.us = phi ptr [ %23, %.lr.ph.us ], [ %26, %24 ]
  %.03444.us = phi ptr [ %.03847.us, %.lr.ph.us ], [ %25, %24 ]
  %.143.us = phi i32 [ 0, %.lr.ph.us ], [ %27, %24 ]
  tail call void @_ZN2rwL9flipBlockEPhS0_(ptr noundef %.045.us, ptr noundef %.03444.us)
  %25 = getelementptr inbounds i8, ptr %.03444.us, i64 8
  %26 = getelementptr inbounds i8, ptr %.045.us, i64 8
  %27 = add nuw nsw i32 %.143.us, 1
  %exitcond.not = icmp eq i32 %27, %6
  br i1 %exitcond.not, label %._crit_edge.us, label %24, !llvm.loop !7

._crit_edge.us:                                   ; preds = %24
  %28 = getelementptr inbounds i8, ptr %.03847.us, i64 %18
  %29 = add nuw nsw i32 %.03946.us, 1
  %exitcond56.not = icmp eq i32 %29, %8
  br i1 %exitcond56.not, label %.loopexit, label %.lr.ph.us, !llvm.loop !8

.loopexit:                                        ; preds = %._crit_edge.us, %.lr.ph, %.lr.ph50, %16, %.preheader, %13
  ret void
}

; 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

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