; LLVM IR from NVIDIA/tensorflow :: tensorflow/examples/android/jni (rgb2yuv)

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

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

30:                                               ; preds = %82, %4
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %78, %35
  %37 = load i32, ptr %14, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %81

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds i16, ptr %42, i32 1
  store ptr %43, ptr %11, align 8, !tbaa !5
  %44 = load i16, ptr %42, align 2, !tbaa !11
  %45 = zext i16 %44 to i32
  store i32 %45, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = lshr i32 %46, 11
  %48 = and i32 %47, 31
  store i32 %48, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = lshr i32 %49, 5
  %51 = and i32 %50, 63
  store i32 %51, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %52 = load i32, ptr %15, align 4, !tbaa !9
  %53 = and i32 %52, 31
  store i32 %53, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %54 = load i32, ptr %16, align 4, !tbaa !9
  %55 = shl i32 %54, 3
  %56 = load i32, ptr %16, align 4, !tbaa !9
  %57 = ashr i32 %56, 2
  %58 = or i32 %55, %57
  store i32 %58, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %59 = load i32, ptr %17, align 4, !tbaa !9
  %60 = shl i32 %59, 2
  %61 = load i32, ptr %17, align 4, !tbaa !9
  %62 = ashr i32 %61, 4
  %63 = or i32 %60, %62
  store i32 %63, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %64 = load i32, ptr %18, align 4, !tbaa !9
  %65 = shl i32 %64, 3
  %66 = load i32, ptr %18, align 4, !tbaa !9
  %67 = ashr i32 %66, 2
  %68 = or i32 %65, %67
  store i32 %68, ptr %21, align 4, !tbaa !9
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = load i32, ptr %19, align 4, !tbaa !9
  %73 = load i32, ptr %20, align 4, !tbaa !9
  %74 = load i32, ptr %21, align 4, !tbaa !9
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = getelementptr inbounds i8, ptr %75, i32 1
  store ptr %76, ptr %9, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZL8WriteYUViiiiiiPhS_(i32 noundef %69, i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74, ptr noundef %75, ptr noundef %77)
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %78

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

81:                                               ; preds = %40
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %12, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %12, align 4, !tbaa !9
  br label %30, !llvm.loop !15

85:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #3 = { 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 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZL8WriteYUViiiiiiPhS_(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @ConvertRGB565ToYUV420SP(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = mul nsw i32 %3, %2
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i8, ptr %1, i64 %6
  %8 = icmp sgt i32 %3, 0
  %9 = icmp sgt i32 %2, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %.preheader.us, label %._crit_edge40

.preheader.us:                                    ; preds = %4, %._crit_edge.us
  %.039.us = phi ptr [ %27, %._crit_edge.us ], [ %1, %4 ]
  %.02838.us = phi ptr [ %11, %._crit_edge.us ], [ %0, %4 ]
  %.03037.us = phi i32 [ %29, %._crit_edge.us ], [ 0, %4 ]
  br label %10

10:                                               ; preds = %.preheader.us, %10
  %.135.us = phi ptr [ %.039.us, %.preheader.us ], [ %27, %10 ]
  %.12934.us = phi ptr [ %.02838.us, %.preheader.us ], [ %11, %10 ]
  %.03133.us = phi i32 [ 0, %.preheader.us ], [ %28, %10 ]
  %11 = getelementptr inbounds i8, ptr %.12934.us, i64 2
  %12 = load i16, ptr %.12934.us, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = lshr i32 %13, 5
  %15 = and i32 %14, 63
  %16 = and i32 %13, 31
  %17 = lshr i32 %13, 8
  %18 = and i32 %17, 248
  %19 = lshr i32 %13, 13
  %20 = or disjoint i32 %18, %19
  %21 = shl nuw nsw i32 %15, 2
  %22 = lshr i32 %15, 4
  %23 = or disjoint i32 %21, %22
  %24 = shl nuw nsw i32 %16, 3
  %25 = lshr i32 %16, 2
  %26 = or disjoint i32 %24, %25
  %27 = getelementptr inbounds i8, ptr %.135.us, i64 1
  tail call void @_ZL8WriteYUViiiiiiPhS_(i32 noundef %.03133.us, i32 noundef %.03037.us, i32 noundef %2, i32 noundef %20, i32 noundef %23, i32 noundef %26, ptr noundef %.135.us, ptr noundef nonnull %7)
  %28 = add nuw nsw i32 %.03133.us, 1
  %exitcond.not = icmp eq i32 %28, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %10, !llvm.loop !9

._crit_edge.us:                                   ; preds = %10
  %29 = add nuw nsw i32 %.03037.us, 1
  %exitcond43.not = icmp eq i32 %29, %3
  br i1 %exitcond43.not, label %._crit_edge40, label %.preheader.us, !llvm.loop !11

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

attributes #0 = { inlinehint 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 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" }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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