; LLVM IR from zchrissirhcz/pixel :: perfs/flip (flip)

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

; 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 @flip_horiz_rgb_idxopt(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.px_image_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 3, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.px_image_t, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !13
  store i32 %20, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.px_image_t, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !14
  store i32 %23, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %24 = load i32, ptr %7, align 4, !tbaa !12
  %25 = mul nsw i32 %24, 3
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %9, align 8, !tbaa !15
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %9, align 8, !tbaa !15
  %29 = sub i64 0, %28
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  store ptr %30, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %31

31:                                               ; preds = %88, %2
  %32 = load i32, ptr %10, align 4, !tbaa !12
  %33 = load i32, ptr %8, align 4, !tbaa !12
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %91

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.px_image_t, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr %10, align 4, !tbaa !12
  %41 = add nsw i32 %40, 1
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.px_image_t, ptr %42, i32 0, i32 4
  %44 = load i32, ptr %43, align 4, !tbaa !17
  %45 = mul nsw i32 %41, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %39, i64 %46
  store ptr %47, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.px_image_t, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr %10, align 4, !tbaa !12
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.px_image_t, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 4, !tbaa !17
  %55 = mul nsw i32 %51, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %50, i64 %56
  store ptr %57, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !12
  br label %58

58:                                               ; preds = %84, %36
  %59 = load i32, ptr %14, align 4, !tbaa !12
  %60 = load i32, ptr %7, align 4, !tbaa !12
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %87

63:                                               ; preds = %58
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 -3
  %66 = load i8, ptr %65, align 1, !tbaa !18
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 %66, ptr %67, align 1, !tbaa !18
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %13, align 8, !tbaa !5
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 -2
  %72 = load i8, ptr %71, align 1, !tbaa !18
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 %72, ptr %73, align 1, !tbaa !18
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i32 1
  store ptr %75, ptr %13, align 8, !tbaa !5
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i64 -1
  %78 = load i8, ptr %77, align 1, !tbaa !18
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  store i8 %78, ptr %79, align 1, !tbaa !18
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i32 1
  store ptr %81, ptr %13, align 8, !tbaa !5
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i64 -3
  store ptr %83, ptr %5, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %63
  %85 = load i32, ptr %14, align 4, !tbaa !12
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %14, align 4, !tbaa !12
  br label %58, !llvm.loop !19

87:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %10, align 4, !tbaa !12
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %10, align 4, !tbaa !12
  br label %31, !llvm.loop !21

91:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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, !6, i64 0}
!10 = !{!"px_image_t", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 12}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !11, i64 20}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @flip_horiz_rgb_idxopt(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph35, label %._crit_edge

.lr.ph35:                                         ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = getelementptr inbounds i8, ptr %1, i64 20
  %10 = icmp sgt i32 %4, 0
  br i1 %10, label %.lr.ph.us.preheader, label %._crit_edge

.lr.ph.us.preheader:                              ; preds = %.lr.ph35
  %xtraiter = and i32 %4, 1
  %11 = icmp eq i32 %4, 1
  %unroll_iter = and i32 %4, 2147483646
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %..loopexit_crit_edge.us
  %.02933.us = phi i32 [ %13, %..loopexit_crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %12 = load ptr, ptr %0, align 8, !tbaa !12
  %13 = add nuw nsw i32 %.02933.us, 1
  %14 = load i32, ptr %8, align 4, !tbaa !13
  %15 = mul nsw i32 %14, %13
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %12, i64 %16
  %18 = load ptr, ptr %1, align 8, !tbaa !12
  %19 = load i32, ptr %9, align 4, !tbaa !13
  %20 = mul nsw i32 %19, %.02933.us
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  %23 = getelementptr inbounds i8, ptr %17, i64 -3
  %24 = getelementptr inbounds i8, ptr %17, i64 -2
  %25 = getelementptr inbounds i8, ptr %17, i64 -1
  br i1 %11, label %..loopexit_crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %.02731.us = phi ptr [ %37, %.lr.ph.us.new ], [ %22, %.lr.ph.us ]
  %niter = phi i32 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %26 = load i8, ptr %23, align 1, !tbaa !14
  store i8 %26, ptr %.02731.us, align 1, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %.02731.us, i64 1
  %28 = load i8, ptr %24, align 1, !tbaa !14
  store i8 %28, ptr %27, align 1, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %.02731.us, i64 2
  %30 = load i8, ptr %25, align 1, !tbaa !14
  store i8 %30, ptr %29, align 1, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %.02731.us, i64 3
  %32 = load i8, ptr %23, align 1, !tbaa !14
  store i8 %32, ptr %31, align 1, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %.02731.us, i64 4
  %34 = load i8, ptr %24, align 1, !tbaa !14
  store i8 %34, ptr %33, align 1, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %.02731.us, i64 5
  %36 = load i8, ptr %25, align 1, !tbaa !14
  store i8 %36, ptr %35, align 1, !tbaa !14
  %37 = getelementptr inbounds i8, ptr %.02731.us, i64 6
  %niter.next.1 = add i32 %niter, 2
  %niter.ncmp.1 = icmp eq i32 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %..loopexit_crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !15

..loopexit_crit_edge.us.unr-lcssa:                ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.02731.us.unr = phi ptr [ %22, %.lr.ph.us ], [ %37, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %..loopexit_crit_edge.us, label %..loopexit_crit_edge.us.epilog-lcssa

..loopexit_crit_edge.us.epilog-lcssa:             ; preds = %..loopexit_crit_edge.us.unr-lcssa
  %38 = load i8, ptr %23, align 1, !tbaa !14
  store i8 %38, ptr %.02731.us.unr, align 1, !tbaa !14
  %39 = getelementptr inbounds i8, ptr %.02731.us.unr, i64 1
  %40 = load i8, ptr %24, align 1, !tbaa !14
  store i8 %40, ptr %39, align 1, !tbaa !14
  %41 = getelementptr inbounds i8, ptr %.02731.us.unr, i64 2
  %42 = load i8, ptr %25, align 1, !tbaa !14
  store i8 %42, ptr %41, align 1, !tbaa !14
  br label %..loopexit_crit_edge.us

..loopexit_crit_edge.us:                          ; preds = %..loopexit_crit_edge.us.unr-lcssa, %..loopexit_crit_edge.us.epilog-lcssa
  %exitcond37.not = icmp eq i32 %13, %6
  br i1 %exitcond37.not, label %._crit_edge, label %.lr.ph.us, !llvm.loop !17

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %.lr.ph35, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !10, i64 8}
!6 = !{!"px_image_t", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 20}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass