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

; 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_Plasma = type { %class.AnimationBase.base, i64, [3600 x i32], [1080 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN16Animation_Plasma4PlayER10HyperImage(ptr noundef nonnull align 8 dereferenceable(15504) %0, ptr noundef nonnull align 8 dereferenceable(27) %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.ColorRgb, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  store i8 1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %14 = getelementptr inbounds %class.Animation_Plasma, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = add nsw i64 %15, 1
  store i64 %16, ptr %14, align 8, !tbaa !11
  store i64 %15, ptr %6, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !17
  br label %17

17:                                               ; preds = %67, %2
  %18 = load i32, ptr %7, align 4, !tbaa !17
  %19 = icmp slt i32 %18, 45
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %70

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !17
  br label %22

22:                                               ; preds = %63, %21
  %23 = load i32, ptr %9, align 4, !tbaa !17
  %24 = icmp slt i32 %23, 80
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %66

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %27 = load i32, ptr %7, align 4, !tbaa !17
  %28 = mul nsw i32 %27, 80
  store i32 %28, ptr %10, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %29 = getelementptr inbounds %class.Animation_Plasma, ptr %13, i32 0, i32 2
  %30 = load i32, ptr %10, align 4, !tbaa !17
  %31 = load i32, ptr %9, align 4, !tbaa !17
  %32 = add nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [3600 x i32], ptr %29, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !17
  %36 = sext i32 %35 to i64
  %37 = load i64, ptr %6, align 8, !tbaa !16
  %38 = add nsw i64 %36, %37
  %39 = srem i64 %38, 360
  %40 = trunc i64 %39 to i32
  %41 = mul nsw i32 %40, 3
  store i32 %41, ptr %11, align 4, !tbaa !17
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 3, ptr %12) #4
  %43 = getelementptr inbounds %class.Animation_Plasma, ptr %13, i32 0, i32 3
  %44 = load i32, ptr %11, align 4, !tbaa !17
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1080 x i8], ptr %43, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !18
  %48 = getelementptr inbounds %class.Animation_Plasma, ptr %13, i32 0, i32 3
  %49 = load i32, ptr %11, align 4, !tbaa !17
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1080 x i8], ptr %48, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !18
  %54 = getelementptr inbounds %class.Animation_Plasma, ptr %13, i32 0, i32 3
  %55 = load i32, ptr %11, align 4, !tbaa !17
  %56 = add nsw i32 %55, 2
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1080 x i8], ptr %54, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !18
  call void @_ZN8ColorRgbC2Ehhh(ptr noundef nonnull align 1 dereferenceable(3) %12, i8 noundef zeroext %47, i8 noundef zeroext %53, i8 noundef zeroext %59)
  call void @_ZN10HyperImage6setPenERK8ColorRgb(ptr noundef nonnull align 8 dereferenceable(27) %42, ptr noundef nonnull align 1 dereferenceable(3) %12)
  call void @llvm.lifetime.end.p0(i64 3, ptr %12) #4
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !17
  %62 = load i32, ptr %7, align 4, !tbaa !17
  call void @_ZN10HyperImage9drawPointEii(ptr noundef nonnull align 8 dereferenceable(27) %60, i32 noundef %61, i32 noundef %62)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %63

63:                                               ; preds = %26
  %64 = load i32, ptr %9, align 4, !tbaa !17
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %9, align 4, !tbaa !17
  br label %22, !llvm.loop !19

66:                                               ; preds = %25
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %7, align 4, !tbaa !17
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %7, align 4, !tbaa !17
  br label %17, !llvm.loop !21

70:                                               ; preds = %20
  %71 = load i8, ptr %5, align 1, !tbaa !9, !range !22, !noundef !23
  %72 = trunc i8 %71 to i1
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  ret i1 %72
}

declare void @_ZN10HyperImage6setPenERK8ColorRgb(ptr noundef nonnull align 8 dereferenceable(27), ptr noundef nonnull align 1 dereferenceable(3)) #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 #3 align 2

declare void @_ZN10HyperImage9drawPointEii(ptr noundef nonnull align 8 dereferenceable(27), i32 noundef, i32 noundef) #2

attributes #0 = { 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 = { "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 = { 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 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !15, i64 16}
!12 = !{!"_ZTS16Animation_Plasma", !13, i64 0, !15, i64 16, !7, i64 24, !7, i64 14424}
!13 = !{!"_ZTS13AnimationBase", !14, i64 8, !10, i64 12}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!14, !14, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = !{i8 0, i8 2}
!23 = !{}


; 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 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 noundef zeroext i1 @_ZN16Animation_Plasma4PlayER10HyperImage(ptr nocapture noundef nonnull align 8 dereferenceable(15504) %0, ptr noundef nonnull align 8 dereferenceable(27) %1) unnamed_addr #1 align 2 {
  %3 = alloca %struct.ColorRgb, align 1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = add nsw i64 %5, 1
  store i64 %6, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 14424
  br label %.preheader

.preheader:                                       ; preds = %2, %12
  %indvars.iv20 = phi i64 [ 0, %2 ], [ %indvars.iv.next21, %12 ]
  %9 = mul nuw nsw i64 %indvars.iv20, 80
  %10 = trunc nuw nsw i64 %indvars.iv20 to i32
  br label %13

11:                                               ; preds = %12
  ret i1 true

12:                                               ; preds = %13
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond23.not = icmp eq i64 %indvars.iv.next21, 45
  br i1 %exitcond23.not, label %11, label %.preheader, !llvm.loop !13

13:                                               ; preds = %.preheader, %13
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %13 ]
  %14 = add nuw nsw i64 %indvars.iv, %9
  %15 = getelementptr inbounds [3600 x i32], ptr %7, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %5, %17
  %19 = srem i64 %18, 360
  %20 = trunc nsw i64 %19 to i32
  %21 = mul nsw i32 %20, 3
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %3) #4
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1080 x i8], ptr %8, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !16
  %25 = add nsw i32 %21, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1080 x i8], ptr %8, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !16
  %29 = add nsw i32 %21, 2
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1080 x i8], ptr %8, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !16
  call void @_ZN8ColorRgbC2Ehhh(ptr noundef nonnull align 1 dereferenceable(3) %3, i8 noundef zeroext %24, i8 noundef zeroext %28, i8 noundef zeroext %32)
  call void @_ZN10HyperImage6setPenERK8ColorRgb(ptr noundef nonnull align 8 dereferenceable(27) %1, ptr noundef nonnull align 1 dereferenceable(3) %3)
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %3) #4
  %33 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_ZN10HyperImage9drawPointEii(ptr noundef nonnull align 8 dereferenceable(27) %1, i32 noundef %33, i32 noundef %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 80
  br i1 %exitcond.not, label %12, label %13, !llvm.loop !17
}

declare void @_ZN10HyperImage6setPenERK8ColorRgb(ptr noundef nonnull align 8 dereferenceable(27), ptr noundef nonnull align 1 dereferenceable(3)) local_unnamed_addr #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 #3 align 2

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

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 = { "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 = { 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 = { 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, !12, i64 16}
!6 = !{!"_ZTS16Animation_Plasma", !7, i64 0, !12, i64 16, !9, i64 24, !9, i64 14424}
!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 = !{!"long long", !9, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!8, !8, i64 0}
!16 = !{!9, !9, i64 0}
!17 = distinct !{!17, !14}


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