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

; 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_KnightRider = type <{ %class.AnimationBase.base, [3 x i8], double, double, %struct.Point3d, i8, i32, i32, i32, [75 x i8], [5 x i8] }>
%class.AnimationBase.base = type <{ ptr, i32, i8 }>

; 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 void @_ZN21Animation_KnightRider4InitER10HyperImagei(ptr noundef nonnull align 8 dereferenceable(123) %0, ptr noundef nonnull align 8 dereferenceable(27) %1, i32 noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.Point3d, align 1
  %8 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN10HyperImage6resizeEii(ptr noundef nonnull align 8 dereferenceable(27) %10, i32 noundef 25, i32 noundef 25)
  %11 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 2
  store double 1.000000e+00, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 3
  store double 0x3FE6666666666666, ptr %12, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 3, ptr %7) #5
  %13 = getelementptr inbounds %struct.Point3d, ptr %7, i32 0, i32 0
  store i8 -1, ptr %13, align 1, !tbaa !18
  %14 = getelementptr inbounds %struct.Point3d, ptr %7, i32 0, i32 1
  store i8 0, ptr %14, align 1, !tbaa !19
  %15 = getelementptr inbounds %struct.Point3d, ptr %7, i32 0, i32 2
  store i8 0, ptr %15, align 1, !tbaa !20
  %16 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr align 1 %7, i64 3, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 3, ptr %7) #5
  %17 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 4
  %18 = getelementptr inbounds %struct.Point3d, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 8, !tbaa !23
  %20 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 9
  %21 = getelementptr inbounds [75 x i8], ptr %20, i64 0, i64 0
  store i8 %19, ptr %21, align 8, !tbaa !22
  %22 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 4
  %23 = getelementptr inbounds %struct.Point3d, ptr %22, i32 0, i32 1
  %24 = load i8, ptr %23, align 1, !tbaa !24
  %25 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 9
  %26 = getelementptr inbounds [75 x i8], ptr %25, i64 0, i64 1
  store i8 %24, ptr %26, align 1, !tbaa !22
  %27 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 4
  %28 = getelementptr inbounds %struct.Point3d, ptr %27, i32 0, i32 2
  %29 = load i8, ptr %28, align 2, !tbaa !25
  %30 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 9
  %31 = getelementptr inbounds [75 x i8], ptr %30, i64 0, i64 2
  store i8 %29, ptr %31, align 2, !tbaa !22
  %32 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 6
  store i32 1, ptr %32, align 4, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %33 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 2
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = fmul double %34, 2.500000e+01
  %36 = fdiv double 1.000000e+00, %35
  store double %36, ptr %8, align 8, !tbaa !27
  br label %37

37:                                               ; preds = %40, %3
  %38 = load double, ptr %8, align 8, !tbaa !27
  %39 = fcmp olt double %38, 5.000000e-02
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  %41 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 6
  %42 = load i32, ptr %41, align 4, !tbaa !26
  %43 = mul nsw i32 %42, 2
  store i32 %43, ptr %41, align 4, !tbaa !26
  %44 = load double, ptr %8, align 8, !tbaa !27
  %45 = fmul double %44, 2.000000e+00
  store double %45, ptr %8, align 8, !tbaa !27
  br label %37, !llvm.loop !28

46:                                               ; preds = %37
  %47 = load double, ptr %8, align 8, !tbaa !27
  %48 = fmul double %47, 1.000000e+03
  %49 = call double @llvm.round.f64(double %48)
  %50 = fptosi double %49 to i32
  call void @_ZN13AnimationBase12SetSleepTimeEi(ptr noundef nonnull align 8 dereferenceable(13) %9, i32 noundef %50)
  %51 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 7
  store i32 0, ptr %51, align 8, !tbaa !30
  %52 = getelementptr inbounds %class.Animation_KnightRider, ptr %9, i32 0, i32 8
  store i32 1, ptr %52, align 4, !tbaa !31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  ret void
}

declare void @_ZN10HyperImage6resizeEii(ptr noundef nonnull align 8 dereferenceable(27), i32 noundef, i32 noundef) #3

declare void @_ZN13AnimationBase12SetSleepTimeEi(ptr noundef nonnull align 8 dereferenceable(13), i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #4

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 = { "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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 16}
!12 = !{!"_ZTS21Animation_KnightRider", !13, i64 0, !15, i64 16, !15, i64 24, !16, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48}
!13 = !{!"_ZTS13AnimationBase", !10, i64 8, !14, i64 12}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTS7Point3d", !7, i64 0, !7, i64 1, !7, i64 2}
!17 = !{!12, !15, i64 24}
!18 = !{!16, !7, i64 0}
!19 = !{!16, !7, i64 1}
!20 = !{!16, !7, i64 2}
!21 = !{i64 0, i64 1, !22, i64 1, i64 1, !22, i64 2, i64 1, !22}
!22 = !{!7, !7, i64 0}
!23 = !{!12, !7, i64 32}
!24 = !{!12, !7, i64 33}
!25 = !{!12, !7, i64 34}
!26 = !{!12, !10, i64 36}
!27 = !{!15, !15, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!12, !10, i64 40}
!31 = !{!12, !10, i64 44}


; 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 uwtable
define dso_local void @_ZN21Animation_KnightRider4InitER10HyperImagei(ptr noundef nonnull align 8 dereferenceable(123) %0, ptr noundef nonnull align 8 dereferenceable(27) %1, i32 noundef %2) unnamed_addr #0 align 2 {
  tail call void @_ZN10HyperImage6resizeEii(ptr noundef nonnull align 8 dereferenceable(27) %1, i32 noundef 25, i32 noundef 25)
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x double> <double 1.000000e+00, double 0x3FE6666666666666>, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  store i8 -1, ptr %5, align 8, !tbaa !9
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 33
  store i8 0, ptr %.sroa.4.0..sroa_idx, align 1, !tbaa !9
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 34
  store i8 0, ptr %.sroa.5.0..sroa_idx, align 2, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 -1, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 49
  store i8 0, ptr %7, align 1, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %0, i64 50
  store i8 0, ptr %8, align 2, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 2, ptr %9, align 4, !tbaa !10
  tail call void @_ZN13AnimationBase12SetSleepTimeEi(ptr noundef nonnull align 8 dereferenceable(13) %0, i32 noundef 80)
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 0, ptr %10, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 1, ptr %11, align 4, !tbaa !17
  ret void
}

declare void @_ZN10HyperImage6resizeEii(ptr noundef nonnull align 8 dereferenceable(27), i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @_ZN13AnimationBase12SetSleepTimeEi(ptr noundef nonnull align 8 dereferenceable(13), i32 noundef) local_unnamed_addr #1

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 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !13, i64 36}
!11 = !{!"_ZTS21Animation_KnightRider", !12, i64 0, !6, i64 16, !6, i64 24, !15, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !7, i64 48}
!12 = !{!"_ZTS13AnimationBase", !13, i64 8, !14, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTS7Point3d", !7, i64 0, !7, i64 1, !7, i64 2}
!16 = !{!11, !13, i64 40}
!17 = !{!11, !13, i64 44}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,SLPVectorizerPass,SROAPass,TailCallElimPass