; LLVM IR from google-deepmind/streetlearn :: streetlearn/engine/bitmap_util.ll (ZN11streetlearn24ConvertRGBPackedToPlanarEPKhiiPh)

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

21:                                               ; preds = %79, %4
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %82

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = mul nsw i32 %27, %28
  store i32 %29, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %75, %26
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %78

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = add nsw i32 %36, %37
  store i32 %38, ptr %15, align 4, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %15, align 4, !tbaa !9
  %41 = mul nsw i32 3, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  store i8 %44, ptr %48, align 1, !tbaa !11
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %15, align 4, !tbaa !9
  %51 = mul nsw i32 3, %50
  %52 = add nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %49, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !11
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load i32, ptr %15, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = add nsw i32 %57, %58
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %56, i64 %60
  store i8 %55, ptr %61, align 1, !tbaa !11
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = mul nsw i32 3, %63
  %65 = add nsw i32 %64, 2
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i8, ptr %62, i64 %66
  %68 = load i8, ptr %67, align 1, !tbaa !11
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load i32, ptr %15, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = add nsw i32 %70, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %69, i64 %73
  store i8 %68, ptr %74, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %75

75:                                               ; preds = %35
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %14, align 4, !tbaa !9
  br label %30, !llvm.loop !12

78:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %11, align 4, !tbaa !9
  br label %21, !llvm.loop !14

82:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN11streetlearn24ConvertRGBPackedToPlanarEPKhiiPh(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  %6 = icmp sgt i32 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %.lr.ph.us.preheader, label %._crit_edge31

.lr.ph.us.preheader:                              ; preds = %4
  %7 = mul nuw nsw i32 %2, %1
  %8 = shl nuw nsw i32 %7, 1
  %9 = zext nneg i32 %7 to i64
  %10 = zext nneg i32 %8 to i64
  %11 = zext nneg i32 %1 to i64
  %wide.trip.count37 = zext nneg i32 %2 to i64
  %invariant.gep = getelementptr inbounds i8, ptr %3, i64 %9
  %invariant.gep39 = getelementptr inbounds i8, ptr %3, i64 %10
  %xtraiter = and i64 %11, 1
  %12 = icmp eq i32 %1, 1
  %unroll_iter = and i64 %11, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv34 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next35, %._crit_edge.us ]
  %13 = mul nuw nsw i64 %indvars.iv34, %11
  br i1 %12, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %14 = add nuw nsw i64 %indvars.iv, %13
  %15 = mul nuw nsw i64 %14, 3
  %16 = getelementptr inbounds i8, ptr %0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %3, i64 %14
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = getelementptr i8, ptr %16, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %gep = getelementptr inbounds i8, ptr %invariant.gep, i64 %14
  store i8 %20, ptr %gep, align 1, !tbaa !5
  %21 = getelementptr i8, ptr %16, i64 2
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %gep40 = getelementptr inbounds i8, ptr %invariant.gep39, i64 %14
  store i8 %22, ptr %gep40, align 1, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = add nuw nsw i64 %indvars.iv.next, %13
  %24 = mul nuw nsw i64 %23, 3
  %25 = getelementptr inbounds i8, ptr %0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %3, i64 %23
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = getelementptr i8, ptr %25, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %gep.1 = getelementptr inbounds i8, ptr %invariant.gep, i64 %23
  store i8 %29, ptr %gep.1, align 1, !tbaa !5
  %30 = getelementptr i8, ptr %25, i64 2
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %gep40.1 = getelementptr inbounds i8, ptr %invariant.gep39, i64 %23
  store i8 %31, ptr %gep40.1, align 1, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !8

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next.1, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %32 = add nuw nsw i64 %indvars.iv.unr, %13
  %33 = mul nuw nsw i64 %32, 3
  %34 = getelementptr inbounds i8, ptr %0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %3, i64 %32
  store i8 %35, ptr %36, align 1, !tbaa !5
  %37 = getelementptr i8, ptr %34, i64 1
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %gep.epil = getelementptr inbounds i8, ptr %invariant.gep, i64 %32
  store i8 %38, ptr %gep.epil, align 1, !tbaa !5
  %39 = getelementptr i8, ptr %34, i64 2
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %gep40.epil = getelementptr inbounds i8, ptr %invariant.gep39, i64 %32
  store i8 %40, ptr %gep40.epil, align 1, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge31, label %.lr.ph.us, !llvm.loop !10

._crit_edge31:                                    ; preds = %._crit_edge.us, %4
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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