; LLVM IR from awawa-dev/HyperHDR :: sources/effects/Animation_CandleLight.ll (ZN21Animation_CandleLight9CandleRgbEv)

; 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.Point3d = type { i8, i8, i8 }
%class.Animation_CandleLight = type { %class.AnimationBase.base, i32, %struct.Point3d, %struct.Point3dhsv, %"class.std::vector" }
%class.AnimationBase.base = type <{ ptr, i32, i8 }>
%struct.Point3dhsv = type { i16, i8, i8 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ColorRgb, std::allocator<ColorRgb>>::_Vector_impl" }
%"struct.std::_Vector_base<ColorRgb, std::allocator<ColorRgb>>::_Vector_impl" = type { %"struct.std::_Vector_base<ColorRgb, std::allocator<ColorRgb>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ColorRgb, std::allocator<ColorRgb>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 i24 @_ZN21Animation_CandleLight9CandleRgbEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #2 align 2 {
  %2 = alloca %struct.Point3d, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i24, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %12 = call i32 @rand() #6
  %13 = getelementptr inbounds %class.Animation_CandleLight, ptr %11, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = mul nsw i32 %14, 2
  %16 = add nsw i32 %15, 1
  %17 = srem i32 %12, %16
  %18 = getelementptr inbounds %class.Animation_CandleLight, ptr %11, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = sub nsw i32 %17, %19
  store i32 %20, ptr %4, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %21 = getelementptr inbounds %class.Animation_CandleLight, ptr %11, i32 0, i32 3
  %22 = getelementptr inbounds %struct.Point3dhsv, ptr %21, i32 0, i32 0
  %23 = load i16, ptr %22, align 8, !tbaa !22
  %24 = zext i16 %23 to i32
  %25 = load i32, ptr %4, align 4, !tbaa !21
  %26 = add nsw i32 %24, %25
  %27 = add nsw i32 %26, 360
  %28 = srem i32 %27, 360
  store i32 %28, ptr %5, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !21
  %29 = call i32 @rand() #6
  %30 = srem i32 %29, 16
  store i32 %30, ptr %4, align 4, !tbaa !21
  br label %31

31:                                               ; preds = %41, %1
  %32 = load i32, ptr %4, align 4, !tbaa !21
  %33 = and i32 %32, 12
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %39

35:                                               ; preds = %31
  %36 = load i32, ptr %6, align 4, !tbaa !21
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !21
  %38 = icmp slt i32 %36, 100
  br label %39

39:                                               ; preds = %35, %31
  %40 = phi i1 [ false, %31 ], [ %38, %35 ]
  br i1 %40, label %41, label %44

41:                                               ; preds = %39
  %42 = call i32 @rand() #6
  %43 = srem i32 %42, 16
  store i32 %43, ptr %4, align 4, !tbaa !21
  br label %31, !llvm.loop !23

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %45 = load i32, ptr %4, align 4, !tbaa !21
  %46 = mul nsw i32 %45, 17
  store i32 %46, ptr %8, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 255, ptr %9, align 4, !tbaa !21
  %47 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %48 = load i32, ptr %47, align 4, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  store i32 %48, ptr %7, align 4, !tbaa !21
  %49 = load i32, ptr %5, align 4, !tbaa !21
  %50 = trunc i32 %49 to i16
  %51 = getelementptr inbounds %class.Animation_CandleLight, ptr %11, i32 0, i32 3
  %52 = getelementptr inbounds %struct.Point3dhsv, ptr %51, i32 0, i32 1
  %53 = load i8, ptr %52, align 2, !tbaa !25
  %54 = load i32, ptr %7, align 4, !tbaa !21
  %55 = trunc i32 %54 to i8
  %56 = getelementptr inbounds %struct.Point3d, ptr %2, i32 0, i32 0
  %57 = getelementptr inbounds %struct.Point3d, ptr %2, i32 0, i32 1
  %58 = getelementptr inbounds %struct.Point3d, ptr %2, i32 0, i32 2
  call void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 noundef zeroext %50, i8 noundef zeroext %53, i8 noundef zeroext %55, ptr noundef nonnull align 1 dereferenceable(1) %56, ptr noundef nonnull align 1 dereferenceable(1) %57, ptr noundef nonnull align 1 dereferenceable(1) %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 1 %2, i64 3, i1 false)
  %59 = load i24, ptr %10, align 4
  ret i24 %59
}

; Function Attrs: nounwind
declare i32 @rand() #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

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)) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 "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 = { 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 #5 = { "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 #6 = { 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 = !{!"_ZTS21Animation_CandleLight", !11, i64 0, !12, i64 16, !14, i64 20, !15, i64 24, !17, i64 32}
!11 = !{!"_ZTS13AnimationBase", !12, i64 8, !13, i64 12}
!12 = !{!"int", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTS7Point3d", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!"_ZTS10Point3dhsv", !16, i64 0, !7, i64 2, !7, i64 3}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTSSt6vectorI8ColorRgbSaIS0_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseI8ColorRgbSaIS0_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseI8ColorRgbSaIS0_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseI8ColorRgbSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!12, !12, i64 0}
!22 = !{!10, !16, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!10, !7, i64 26}


; 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.Point3d = type { i8, i8, i8 }

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

; Function Attrs: mustprogress 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 i24 @_ZN21Animation_CandleLight9CandleRgbEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %struct.Point3d, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call i32 @rand() #5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i16, ptr %8, align 8, !tbaa !20
  %10 = tail call i32 @rand() #5
  %.08 = srem i32 %10, 16
  %11 = and i32 %.08, 12
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.079 = phi i32 [ %13, %.lr.ph ], [ 0, %1 ]
  %13 = add nuw nsw i32 %.079, 1
  %14 = tail call i32 @rand() #5
  %.0 = srem i32 %14, 16
  %15 = and i32 %.0, 12
  %16 = icmp eq i32 %15, 0
  %17 = icmp ult i32 %.079, 99
  %or.cond = select i1 %16, i1 %17, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !21

.critedge:                                        ; preds = %.lr.ph, %1
  %.0.lcssa = phi i32 [ %.08, %1 ], [ %.0, %.lr.ph ]
  %18 = shl nsw i32 %7, 1
  %19 = or disjoint i32 %18, 1
  %20 = srem i32 %5, %19
  %21 = zext i16 %9 to i32
  %reass.sub = sub i32 %21, %7
  %22 = add i32 %reass.sub, 360
  %23 = add i32 %22, %20
  %24 = srem i32 %23, 360
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %25 = mul nsw i32 %.0.lcssa, 17
  store i32 %25, ptr %3, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  store i32 255, ptr %4, align 4, !tbaa !23
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %27 = load i32, ptr %26, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  %28 = trunc nsw i32 %24 to i16
  %29 = getelementptr inbounds i8, ptr %0, i64 26
  %30 = load i8, ptr %29, align 2, !tbaa !24
  %31 = trunc i32 %27 to i8
  %32 = getelementptr inbounds i8, ptr %2, i64 1
  %33 = getelementptr inbounds i8, ptr %2, i64 2
  call void @_ZN8ColorRgb7hsv2rgbEthhRhS0_S0_(i16 noundef zeroext %28, i8 noundef zeroext %30, i8 noundef zeroext %31, ptr noundef nonnull align 1 dereferenceable(1) %2, ptr noundef nonnull align 1 dereferenceable(1) %32, ptr noundef nonnull align 1 dereferenceable(1) %33)
  %.0.copyload = load i24, ptr %2, align 4
  ret i24 %.0.copyload
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #4 = { "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 #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 = !{!"_ZTS21Animation_CandleLight", !7, i64 0, !8, i64 16, !12, i64 20, !13, i64 24, !15, i64 32}
!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 = !{!"_ZTS7Point3d", !9, i64 0, !9, i64 1, !9, i64 2}
!13 = !{!"_ZTS10Point3dhsv", !14, i64 0, !9, i64 2, !9, i64 3}
!14 = !{!"short", !9, i64 0}
!15 = !{!"_ZTSSt6vectorI8ColorRgbSaIS0_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseI8ColorRgbSaIS0_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseI8ColorRgbSaIS0_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseI8ColorRgbSaIS0_EE17_Vector_impl_dataE", !19, i64 0, !19, i64 8, !19, i64 16}
!19 = !{!"any pointer", !9, i64 0}
!20 = !{!6, !14, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!8, !8, i64 0}
!24 = !{!6, !9, i64 26}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass