; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Tagl/Rotate/gobj.ll (ZN13GraphicObject5ShinyEfff)

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

%class.GraphicObject = type <{ ptr, %class.Flags, [1024 x i32], i32, i32, [4 x i8] }>
%class.Flags = type { i32 }

; 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 void @_ZN13GraphicObject5ShinyEfff(ptr noundef nonnull align 8 dereferenceable(4116) %0, float noundef %1, float noundef %2, float noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  store float %3, ptr %8, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load float, ptr %7, align 4, !tbaa !9
  %12 = fmul float %11, 1.638400e+04
  %13 = fptosi float %12 to i32
  %14 = getelementptr inbounds %class.GraphicObject, ptr %10, i32 0, i32 4
  store i32 %13, ptr %14, align 8, !tbaa !11
  %15 = load float, ptr %8, align 4, !tbaa !9
  %16 = fmul float %15, 1.638400e+04
  %17 = fptosi float %16 to i32
  %18 = getelementptr inbounds %class.GraphicObject, ptr %10, i32 0, i32 3
  store i32 %17, ptr %18, align 4, !tbaa !15
  store i32 0, ptr %9, align 4, !tbaa !16
  br label %19

19:                                               ; preds = %34, %4
  %20 = load i32, ptr %9, align 4, !tbaa !16
  %21 = icmp slt i32 %20, 1024
  br i1 %21, label %22, label %37

22:                                               ; preds = %19
  %23 = load i32, ptr %9, align 4, !tbaa !16
  %24 = sitofp i32 %23 to float
  %25 = fdiv float %24, 1.024000e+03
  %26 = load float, ptr %6, align 4, !tbaa !9
  %27 = call noundef float @_ZSt3powff(float noundef %25, float noundef %26)
  %28 = fmul float 1.638400e+04, %27
  %29 = fptosi float %28 to i32
  %30 = getelementptr inbounds %class.GraphicObject, ptr %10, i32 0, i32 2
  %31 = load i32, ptr %9, align 4, !tbaa !16
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1024 x i32], ptr %30, i64 0, i64 %32
  store i32 %29, ptr %33, align 4, !tbaa !16
  br label %34

34:                                               ; preds = %22
  %35 = load i32, ptr %9, align 4, !tbaa !16
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !16
  br label %19, !llvm.loop !17

37:                                               ; preds = %19
  %38 = getelementptr inbounds %class.GraphicObject, ptr %10, i32 0, i32 1
  call void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4) %38, i32 noundef 1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3powff(float noundef, float noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2 align 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 = { 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 #3 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !14, i64 4112}
!12 = !{!"_ZTS13GraphicObject", !13, i64 8, !7, i64 12, !14, i64 4108, !14, i64 4112}
!13 = !{!"_ZTS5Flags", !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 4108}
!16 = !{!14, !14, 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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN13GraphicObject5ShinyEfff(ptr noundef nonnull align 8 dereferenceable(4116) %0, float noundef %1, float noundef %2, float noundef %3) unnamed_addr #0 align 2 {
  %5 = insertelement <2 x float> poison, float %3, i64 0
  %6 = insertelement <2 x float> %5, float %2, i64 1
  %7 = fmul <2 x float> %6, <float 1.638400e+04, float 1.638400e+04>
  %8 = getelementptr inbounds i8, ptr %0, i64 4108
  %9 = fptosi <2 x float> %7 to <2 x i32>
  store <2 x i32> %9, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 12
  br label %11

11:                                               ; preds = %4, %11
  %indvars.iv = phi i64 [ 0, %4 ], [ %indvars.iv.next, %11 ]
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = uitofp nneg i32 %12 to float
  %14 = fmul float %13, 0x3F50000000000000
  %15 = tail call noundef float @_ZSt3powff(float noundef %14, float noundef %1)
  %16 = fmul float %15, 1.638400e+04
  %17 = fptosi float %16 to i32
  %18 = getelementptr inbounds [1024 x i32], ptr %10, i64 0, i64 %indvars.iv
  store i32 %17, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1024
  br i1 %exitcond.not, label %19, label %11, !llvm.loop !9

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4) %20, i32 noundef 1)
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3powff(float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass