; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseYuvToHue.ll (ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm)

; 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"

@.str = external hidden unnamed_addr constant [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm = external hidden unnamed_addr constant [140 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i64 noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9) #0 {
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca i64, align 8
  %24 = alloca i64, align 8
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i64 %1, ptr %12, align 8, !tbaa !9
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i64 %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !9
  store i64 %6, ptr %17, align 8, !tbaa !9
  store i64 %7, ptr %18, align 8, !tbaa !9
  store ptr %8, ptr %19, align 8, !tbaa !5
  store i64 %9, ptr %20, align 8, !tbaa !9
  %27 = load i64, ptr %17, align 8, !tbaa !9
  %28 = urem i64 %27, 2
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %30, label %40

30:                                               ; preds = %10
  %31 = load i64, ptr %18, align 8, !tbaa !9
  %32 = urem i64 %31, 2
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %40

34:                                               ; preds = %30
  %35 = load i64, ptr %17, align 8, !tbaa !9
  %36 = icmp uge i64 %35, 2
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load i64, ptr %18, align 8, !tbaa !9
  %39 = icmp uge i64 %38, 2
  br label %40

40:                                               ; preds = %37, %34, %30, %10
  %41 = phi i1 [ false, %34 ], [ false, %30 ], [ false, %10 ], [ %39, %37 ]
  br i1 %41, label %42, label %43

42:                                               ; preds = %40
  br label %45

43:                                               ; preds = %40
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 63, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm) #4
  unreachable

44:                                               ; No predecessors!
  br label %45

45:                                               ; preds = %44, %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  store i64 0, ptr %21, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %148, %45
  %47 = load i64, ptr %21, align 8, !tbaa !9
  %48 = load i64, ptr %18, align 8, !tbaa !9
  %49 = icmp ult i64 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 2, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %151

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  store i64 0, ptr %23, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #5
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %128, %51
  %53 = load i64, ptr %24, align 8, !tbaa !9
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = icmp ult i64 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  store i32 5, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  br label %133

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #5
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i64, ptr %23, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  store i32 %62, ptr %25, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #5
  %63 = load ptr, ptr %15, align 8, !tbaa !5
  %64 = load i64, ptr %23, align 8, !tbaa !9
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !11
  %67 = zext i8 %66 to i32
  store i32 %67, ptr %26, align 4, !tbaa !12
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load i64, ptr %24, align 8, !tbaa !9
  %70 = getelementptr inbounds i8, ptr %68, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !11
  %72 = zext i8 %71 to i32
  %73 = load i32, ptr %25, align 4, !tbaa !12
  %74 = load i32, ptr %26, align 4, !tbaa !12
  %75 = call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %72, i32 noundef %73, i32 noundef %74)
  %76 = trunc i32 %75 to i8
  %77 = load ptr, ptr %19, align 8, !tbaa !5
  %78 = load i64, ptr %24, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  store i8 %76, ptr %79, align 1, !tbaa !11
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load i64, ptr %24, align 8, !tbaa !9
  %82 = add i64 %81, 1
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = zext i8 %84 to i32
  %86 = load i32, ptr %25, align 4, !tbaa !12
  %87 = load i32, ptr %26, align 4, !tbaa !12
  %88 = call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %85, i32 noundef %86, i32 noundef %87)
  %89 = trunc i32 %88 to i8
  %90 = load ptr, ptr %19, align 8, !tbaa !5
  %91 = load i64, ptr %24, align 8, !tbaa !9
  %92 = add i64 %91, 1
  %93 = getelementptr inbounds i8, ptr %90, i64 %92
  store i8 %89, ptr %93, align 1, !tbaa !11
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  %95 = load i64, ptr %24, align 8, !tbaa !9
  %96 = load i64, ptr %12, align 8, !tbaa !9
  %97 = add i64 %95, %96
  %98 = getelementptr inbounds i8, ptr %94, i64 %97
  %99 = load i8, ptr %98, align 1, !tbaa !11
  %100 = zext i8 %99 to i32
  %101 = load i32, ptr %25, align 4, !tbaa !12
  %102 = load i32, ptr %26, align 4, !tbaa !12
  %103 = call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %100, i32 noundef %101, i32 noundef %102)
  %104 = trunc i32 %103 to i8
  %105 = load ptr, ptr %19, align 8, !tbaa !5
  %106 = load i64, ptr %24, align 8, !tbaa !9
  %107 = load i64, ptr %20, align 8, !tbaa !9
  %108 = add i64 %106, %107
  %109 = getelementptr inbounds i8, ptr %105, i64 %108
  store i8 %104, ptr %109, align 1, !tbaa !11
  %110 = load ptr, ptr %11, align 8, !tbaa !5
  %111 = load i64, ptr %24, align 8, !tbaa !9
  %112 = load i64, ptr %12, align 8, !tbaa !9
  %113 = add i64 %111, %112
  %114 = add i64 %113, 1
  %115 = getelementptr inbounds i8, ptr %110, i64 %114
  %116 = load i8, ptr %115, align 1, !tbaa !11
  %117 = zext i8 %116 to i32
  %118 = load i32, ptr %25, align 4, !tbaa !12
  %119 = load i32, ptr %26, align 4, !tbaa !12
  %120 = call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %117, i32 noundef %118, i32 noundef %119)
  %121 = trunc i32 %120 to i8
  %122 = load ptr, ptr %19, align 8, !tbaa !5
  %123 = load i64, ptr %24, align 8, !tbaa !9
  %124 = load i64, ptr %20, align 8, !tbaa !9
  %125 = add i64 %123, %124
  %126 = add i64 %125, 1
  %127 = getelementptr inbounds i8, ptr %122, i64 %126
  store i8 %121, ptr %127, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #5
  br label %128

128:                                              ; preds = %57
  %129 = load i64, ptr %24, align 8, !tbaa !9
  %130 = add i64 %129, 2
  store i64 %130, ptr %24, align 8, !tbaa !9
  %131 = load i64, ptr %23, align 8, !tbaa !9
  %132 = add i64 %131, 1
  store i64 %132, ptr %23, align 8, !tbaa !9
  br label %52, !llvm.loop !14

133:                                              ; preds = %56
  %134 = load i64, ptr %12, align 8, !tbaa !9
  %135 = mul i64 2, %134
  %136 = load ptr, ptr %11, align 8, !tbaa !5
  %137 = getelementptr inbounds i8, ptr %136, i64 %135
  store ptr %137, ptr %11, align 8, !tbaa !5
  %138 = load i64, ptr %14, align 8, !tbaa !9
  %139 = load ptr, ptr %13, align 8, !tbaa !5
  %140 = getelementptr inbounds i8, ptr %139, i64 %138
  store ptr %140, ptr %13, align 8, !tbaa !5
  %141 = load i64, ptr %16, align 8, !tbaa !9
  %142 = load ptr, ptr %15, align 8, !tbaa !5
  %143 = getelementptr inbounds i8, ptr %142, i64 %141
  store ptr %143, ptr %15, align 8, !tbaa !5
  %144 = load i64, ptr %20, align 8, !tbaa !9
  %145 = mul i64 2, %144
  %146 = load ptr, ptr %19, align 8, !tbaa !5
  %147 = getelementptr inbounds i8, ptr %146, i64 %145
  store ptr %147, ptr %19, align 8, !tbaa !5
  br label %148

148:                                              ; preds = %133
  %149 = load i64, ptr %21, align 8, !tbaa !9
  %150 = add i64 %149, 2
  store i64 %150, ptr %21, align 8, !tbaa !9
  br label %46, !llvm.loop !16

151:                                              ; preds = %50
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef, i32 noundef, i32 noundef) #3

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

attributes #0 = { 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 #1 = { noreturn nounwind "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { alwaysinline 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 = { noreturn nounwind }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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"

@.str = external hidden unnamed_addr constant [71 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm = external hidden unnamed_addr constant [140 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5, i64 noundef %6, i64 noundef %7, ptr nocapture noundef writeonly %8, i64 noundef %9) local_unnamed_addr #0 {
  %11 = and i64 %6, 1
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %10
  %14 = and i64 %7, 1
  %15 = icmp eq i64 %14, 0
  %16 = icmp ugt i64 %6, 1
  %or.cond = and i1 %16, %15
  %17 = icmp ugt i64 %7, 1
  %or.cond3 = and i1 %17, %or.cond
  br i1 %or.cond3, label %.preheader61, label %.critedge

.preheader61:                                     ; preds = %13
  %18 = shl i64 %1, 1
  %19 = shl i64 %9, 1
  br label %.preheader

.critedge:                                        ; preds = %13, %10
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 63, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base12Yuv420pToHueEPKhmS2_mS2_mmmPhm) #3
  unreachable

.preheader:                                       ; preds = %.preheader61, %21
  %.068 = phi ptr [ %0, %.preheader61 ], [ %22, %21 ]
  %.05367 = phi ptr [ %2, %.preheader61 ], [ %23, %21 ]
  %.05666 = phi i64 [ 0, %.preheader61 ], [ %26, %21 ]
  %.05765 = phi ptr [ %4, %.preheader61 ], [ %24, %21 ]
  %.05864 = phi ptr [ %8, %.preheader61 ], [ %25, %21 ]
  br label %28

20:                                               ; preds = %21
  ret void

21:                                               ; preds = %28
  %22 = getelementptr inbounds i8, ptr %.068, i64 %18
  %23 = getelementptr inbounds i8, ptr %.05367, i64 %3
  %24 = getelementptr inbounds i8, ptr %.05765, i64 %5
  %25 = getelementptr inbounds i8, ptr %.05864, i64 %19
  %26 = add i64 %.05666, 2
  %27 = icmp ult i64 %26, %7
  br i1 %27, label %.preheader, label %20, !llvm.loop !5

28:                                               ; preds = %.preheader, %28
  %.05463 = phi i64 [ 0, %.preheader ], [ %64, %28 ]
  %.05562 = phi i64 [ 0, %.preheader ], [ %65, %28 ]
  %29 = getelementptr inbounds i8, ptr %.05367, i64 %.05562
  %30 = load i8, ptr %29, align 1, !tbaa !7
  %31 = zext i8 %30 to i32
  %32 = getelementptr inbounds i8, ptr %.05765, i64 %.05562
  %33 = load i8, ptr %32, align 1, !tbaa !7
  %34 = zext i8 %33 to i32
  %35 = getelementptr inbounds i8, ptr %.068, i64 %.05463
  %36 = load i8, ptr %35, align 1, !tbaa !7
  %37 = zext i8 %36 to i32
  %38 = tail call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %37, i32 noundef %31, i32 noundef %34)
  %39 = trunc i32 %38 to i8
  %40 = getelementptr inbounds i8, ptr %.05864, i64 %.05463
  store i8 %39, ptr %40, align 1, !tbaa !7
  %41 = or disjoint i64 %.05463, 1
  %42 = getelementptr inbounds i8, ptr %.068, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !7
  %44 = zext i8 %43 to i32
  %45 = tail call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %44, i32 noundef %31, i32 noundef %34)
  %46 = trunc i32 %45 to i8
  %47 = getelementptr inbounds i8, ptr %.05864, i64 %41
  store i8 %46, ptr %47, align 1, !tbaa !7
  %48 = add i64 %.05463, %1
  %49 = getelementptr inbounds i8, ptr %.068, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !7
  %51 = zext i8 %50 to i32
  %52 = tail call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %51, i32 noundef %31, i32 noundef %34)
  %53 = trunc i32 %52 to i8
  %54 = add i64 %.05463, %9
  %55 = getelementptr inbounds i8, ptr %.05864, i64 %54
  store i8 %53, ptr %55, align 1, !tbaa !7
  %56 = add i64 %48, 1
  %57 = getelementptr inbounds i8, ptr %.068, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !7
  %59 = zext i8 %58 to i32
  %60 = tail call noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef %59, i32 noundef %31, i32 noundef %34)
  %61 = trunc i32 %60 to i8
  %62 = add i64 %54, 1
  %63 = getelementptr inbounds i8, ptr %.05864, i64 %62
  store i8 %61, ptr %63, align 1, !tbaa !7
  %64 = add i64 %.05463, 2
  %65 = add i64 %.05562, 1
  %66 = icmp ult i64 %64, %6
  br i1 %66, label %28, label %21, !llvm.loop !10
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base8YuvToHueEiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { noreturn nounwind "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 = { alwaysinline 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 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass