; LLVM IR from yettabaa/cub3D :: bonus/sprites_init.ll (sprites)

; 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.s_data = type { double, double, double, double, double, double, double, double, double, double, i32, double, double, ptr, %struct.s_sprites, %struct.s_minimap, %struct.s_door, %struct.s_textures, %struct.s_hook, %struct.s_map_result, %struct.s_rycast, %struct.s_mlx, ptr }
%struct.s_sprites = type { ptr, i32, i32, i32, i32, i32, i32 }
%struct.s_minimap = type { double, double, double, double, double }
%struct.s_door = type { ptr, i32, i32, i32 }
%struct.s_textures = type { i32, ptr, i32, i32, i32, ptr, i32, i32, i32, ptr, i32, i32, i32, ptr, i32, i32, i32, ptr, i32, i32, i32 }
%struct.s_hook = type { double, i32, double, double, double }
%struct.s_map_result = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i8 }
%struct.s_rycast = type { double, double, double, double, double, double, double, double, double }
%struct.s_mlx = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i32 }
%struct.s_GetSprites = type { i32, i32, double, double }

; Function Attrs: nounwind uwtable
define dso_local i32 @_sprites(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %9 = load i32, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.s_data, ptr %10, i32 0, i32 13
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds %struct.s_GetSprites, ptr %12, i64 %14
  %16 = getelementptr inbounds %struct.s_GetSprites, ptr %15, i32 0, i32 0
  store i32 %9, ptr %16, align 8, !tbaa !22
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.s_data, ptr %18, i32 0, i32 13
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.s_GetSprites, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.s_GetSprites, ptr %23, i32 0, i32 1
  store i32 %17, ptr %24, align 4, !tbaa !24
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = sitofp i32 %25 to double
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s_data, ptr %27, i32 0, i32 2
  %29 = load double, ptr %28, align 8, !tbaa !25
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.s_data, ptr %30, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !25
  %33 = fdiv double %32, 2.000000e+00
  %34 = call double @llvm.fmuladd.f64(double %26, double %29, double %33)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s_data, ptr %35, i32 0, i32 13
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.s_GetSprites, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.s_GetSprites, ptr %40, i32 0, i32 2
  store double %34, ptr %41, align 8, !tbaa !26
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sitofp i32 %42 to double
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.s_data, ptr %44, i32 0, i32 2
  %46 = load double, ptr %45, align 8, !tbaa !25
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.s_data, ptr %47, i32 0, i32 2
  %49 = load double, ptr %48, align 8, !tbaa !25
  %50 = fdiv double %49, 2.000000e+00
  %51 = call double @llvm.fmuladd.f64(double %43, double %46, double %50)
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.s_data, ptr %52, i32 0, i32 13
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds %struct.s_GetSprites, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.s_GetSprites, ptr %57, i32 0, i32 3
  store double %51, ptr %58, align 8, !tbaa !27
  ret i32 1
}

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 104}
!12 = !{!"s_data", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !10, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !14, i64 112, !15, i64 144, !16, i64 184, !17, i64 208, !18, i64 336, !19, i64 376, !20, i64 456, !21, i64 528, !6, i64 584}
!13 = !{!"double", !7, i64 0}
!14 = !{!"s_sprites", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!15 = !{!"s_minimap", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!16 = !{!"s_door", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!17 = !{!"s_textures", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !6, i64 104, !10, i64 112, !10, i64 116, !10, i64 120}
!18 = !{!"s_hook", !13, i64 0, !10, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!19 = !{!"s_map_result", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72}
!20 = !{!"s_rycast", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64}
!21 = !{!"s_mlx", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48}
!22 = !{!23, !10, i64 0}
!23 = !{!"s_GetSprites", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16}
!24 = !{!23, !10, i64 4}
!25 = !{!12, !13, i64 16}
!26 = !{!23, !13, i64 8}
!27 = !{!23, !13, i64 16}


; 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.s_GetSprites = type { i32, i32, double, double }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_sprites(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds %struct.s_GetSprites, ptr %6, i64 %7
  store i32 %2, ptr %8, align 8, !tbaa !20
  %9 = getelementptr inbounds %struct.s_GetSprites, ptr %6, i64 %7, i32 1
  store i32 %3, ptr %9, align 4, !tbaa !22
  %10 = insertelement <2 x i32> poison, i32 %2, i64 0
  %11 = insertelement <2 x i32> %10, i32 %3, i64 1
  %12 = sitofp <2 x i32> %11 to <2 x double>
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load double, ptr %13, align 8, !tbaa !23
  %15 = fmul double %14, 5.000000e-01
  %16 = getelementptr inbounds %struct.s_GetSprites, ptr %6, i64 %7, i32 2
  %17 = insertelement <2 x double> poison, double %14, i64 0
  %18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
  %19 = insertelement <2 x double> poison, double %15, i64 0
  %20 = shufflevector <2 x double> %19, <2 x double> poison, <2 x i32> zeroinitializer
  %21 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> %18, <2 x double> %20)
  store <2 x double> %21, ptr %16, align 8, !tbaa !24
  ret i32 1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !11, i64 104}
!6 = !{!"s_data", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !10, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !12, i64 112, !13, i64 144, !14, i64 184, !15, i64 208, !16, i64 336, !17, i64 376, !18, i64 456, !19, i64 528, !11, i64 584}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"s_sprites", !11, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!"s_minimap", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!14 = !{!"s_door", !11, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!15 = !{!"s_textures", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !11, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !11, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !11, i64 104, !10, i64 112, !10, i64 116, !10, i64 120}
!16 = !{!"s_hook", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!17 = !{!"s_map_result", !10, i64 0, !10, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !8, i64 72}
!18 = !{!"s_rycast", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64}
!19 = !{!"s_mlx", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !10, i64 44, !10, i64 48}
!20 = !{!21, !10, i64 0}
!21 = !{!"s_GetSprites", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16}
!22 = !{!21, !10, i64 4}
!23 = !{!6, !7, i64 16}
!24 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass