; LLVM IR from awawa-dev/HyperHDR :: sources/effects (Animation_RainbowWaves)

; 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.ColorRgb = type { i8, i8, i8 }
%class.Animation_RainbowWaves = type { %class.AnimationBase.base, i32, [4 x i8] }
%class.AnimationBase.base = type <{ ptr, i32, i8 }>

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN22Animation_RainbowWaves10hasLedDataERSt6vectorI8ColorRgbSaIS1_EE(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.ColorRgb, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #5
  %10 = icmp ugt i64 %9, 0
  br i1 %10, label %11, label %41

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 3, ptr %5) #5
  call void @_ZN8ColorRgbC2Ehhh(ptr noundef nonnull align 1 dereferenceable(3) %5, i8 noundef zeroext 0, i8 noundef zeroext 0, i8 noundef zeroext 0)
  %12 = getelementptr inbounds %class.Animation_RainbowWaves, ptr %7, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = trunc i32 %13 to i16
  %15 = getelementptr inbounds %struct.ColorRgb, ptr %5, i32 0, i32 0
  %16 = getelementptr inbounds %struct.ColorRgb, ptr %5, i32 0, i32 1
  %17 = getelementptr inbounds %struct.ColorRgb, ptr %5, i32 0, i32 2
  call void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 noundef zeroext %14, i8 noundef zeroext -1, i8 noundef zeroext -1, ptr noundef nonnull align 1 dereferenceable(1) %15, ptr noundef nonnull align 1 dereferenceable(1) %16, ptr noundef nonnull align 1 dereferenceable(1) %17)
  %18 = getelementptr inbounds %class.Animation_RainbowWaves, ptr %7, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 8, !tbaa !9
  %21 = icmp sgt i32 %20, 359
  br i1 %21, label %22, label %24

22:                                               ; preds = %11
  %23 = getelementptr inbounds %class.Animation_RainbowWaves, ptr %7, i32 0, i32 1
  store i32 0, ptr %23, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %22, %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %25

25:                                               ; preds = %37, %24
  %26 = load i32, ptr %6, align 4, !tbaa !14
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %27) #5
  %29 = trunc i64 %28 to i32
  %30 = icmp slt i32 %26, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %40

32:                                               ; preds = %25
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !14
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 1 dereferenceable(3) ptr @_ZNSt6vectorI8ColorRgbSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef %35) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr align 1 %5, i64 3, i1 false), !tbaa.struct !15
  br label %37

37:                                               ; preds = %32
  %38 = load i32, ptr %6, align 4, !tbaa !14
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %6, align 4, !tbaa !14
  br label %25, !llvm.loop !17

40:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 3, ptr %5) #5
  br label %41

41:                                               ; preds = %40, %2
  ret i1 true
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8ColorRgbC2Ehhh(ptr noundef nonnull align 1 dereferenceable(3), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #1 align 2

declare void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1)) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(3) ptr @_ZNSt6vectorI8ColorRgbSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 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) #4

; 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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 16}
!10 = !{!"_ZTS22Animation_RainbowWaves", !11, i64 0, !12, i64 16}
!11 = !{!"_ZTS13AnimationBase", !12, i64 8, !13, i64 12}
!12 = !{!"int", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{i64 0, i64 1, !16, i64 1, i64 1, !16, i64 2, i64 1, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

%struct.ColorRgb = type { i8, i8, i8 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN22Animation_RainbowWaves10hasLedDataERSt6vectorI8ColorRgbSaIS1_EE(ptr nocapture noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #0 align 2 {
  %3 = alloca %struct.ColorRgb, align 1
  %4 = tail call noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %21, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %3) #5
  call void @_ZN8ColorRgbC2Ehhh(ptr noundef nonnull align 1 dereferenceable(3) %3, i8 noundef zeroext 0, i8 noundef zeroext 0, i8 noundef zeroext 0)
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = trunc i32 %7 to i16
  %9 = getelementptr inbounds i8, ptr %3, i64 1
  %10 = getelementptr inbounds i8, ptr %3, i64 2
  call void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 noundef zeroext %8, i8 noundef zeroext -1, i8 noundef zeroext -1, ptr noundef nonnull align 1 dereferenceable(1) %3, ptr noundef nonnull align 1 dereferenceable(1) %9, ptr noundef nonnull align 1 dereferenceable(1) %10)
  %11 = load i32, ptr %6, align 8, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = icmp sgt i32 %11, 358
  %spec.select = select i1 %13, i32 0, i32 %12
  store i32 %spec.select, ptr %6, align 8, !tbaa !5
  %14 = call noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #5
  %15 = trunc i64 %14 to i32
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %5
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %3) #5
  br label %21

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %17 = call noundef nonnull align 1 dereferenceable(3) ptr @_ZNSt6vectorI8ColorRgbSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %indvars.iv) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %17, ptr noundef nonnull align 1 dereferenceable(3) %3, i64 3, i1 false), !tbaa.struct !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = call noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #5
  %sext = shl i64 %18, 32
  %19 = ashr exact i64 %sext, 32
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !14

21:                                               ; preds = %._crit_edge, %2
  ret i1 true
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI8ColorRgbSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8ColorRgbC2Ehhh(ptr noundef nonnull align 1 dereferenceable(3), i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) unnamed_addr #1 align 2

declare void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(3) ptr @_ZNSt6vectorI8ColorRgbSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; 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) #4

; Function Attrs: mustprogress 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 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !8, i64 16}
!6 = !{!"_ZTS22Animation_RainbowWaves", !7, i64 0, !8, i64 16}
!7 = !{!"_ZTS13AnimationBase", !8, i64 8, !11, i64 12}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{i64 0, i64 1, !13, i64 1, i64 1, !13, i64 2, i64 1, !13}
!13 = !{!9, !9, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass