; LLVM IR from yettabaa/cub3D :: bonus (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_object = type { i32, double, double, double, double, i32, double, double, double, double, double, ptr }
%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 }

; 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: nounwind uwtable
declare dso_local void @sprite_disc(ptr noundef, double noundef, double noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @render_sprite_minimap(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %37, %2
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %41

10:                                               ; preds = %7
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.s_object, ptr %11, i32 0, i32 4
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s_data, ptr %14, i32 0, i32 15
  %16 = getelementptr inbounds %struct.s_minimap, ptr %15, i32 0, i32 0
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fcmp olt double %13, %17
  br i1 %18, label %19, label %37

19:                                               ; preds = %10
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.s_object, ptr %21, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !23
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.s_data, ptr %24, i32 0, i32 15
  %26 = getelementptr inbounds %struct.s_minimap, ptr %25, i32 0, i32 1
  %27 = load double, ptr %26, align 8, !tbaa !24
  %28 = fadd double %23, %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.s_object, ptr %29, i32 0, i32 2
  %31 = load double, ptr %30, align 8, !tbaa !25
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_data, ptr %32, i32 0, i32 15
  %34 = getelementptr inbounds %struct.s_minimap, ptr %33, i32 0, i32 2
  %35 = load double, ptr %34, align 8, !tbaa !26
  %36 = fadd double %31, %35
  call void @sprite_disc(ptr noundef %20, double noundef %28, double noundef %36, i32 noundef 16711680)
  br label %37

37:                                               ; preds = %19, %10
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_object, ptr %38, i32 0, i32 11
  %40 = load ptr, ptr %39, align 8, !tbaa !27
  store ptr %40, ptr %5, align 8, !tbaa !5
  br label %7, !llvm.loop !28

41:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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/C++ TBAA"}
!9 = !{!10, !12, i64 32}
!10 = !{!"s_object", !11, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 144}
!14 = !{!"s_data", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !11, i64 80, !12, i64 88, !12, i64 96, !6, i64 104, !15, i64 112, !16, i64 144, !17, i64 184, !18, i64 208, !19, i64 336, !20, i64 376, !21, i64 456, !22, i64 528, !6, i64 584}
!15 = !{!"s_sprites", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!16 = !{!"s_minimap", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!17 = !{!"s_door", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!18 = !{!"s_textures", !11, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !6, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !6, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 116, !11, i64 120}
!19 = !{!"s_hook", !12, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!20 = !{!"s_map_result", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !7, i64 72}
!21 = !{!"s_rycast", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64}
!22 = !{!"s_mlx", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !11, i64 48}
!23 = !{!10, !12, i64 8}
!24 = !{!14, !12, i64 152}
!25 = !{!10, !12, i64 16}
!26 = !{!14, !12, i64 160}
!27 = !{!10, !6, i64 88}
!28 = distinct !{!28, !29}
!29 = !{!"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: nounwind uwtable
declare dso_local void @sprite_disc(ptr noundef, double noundef, double noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @render_sprite_minimap(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %.not10 = icmp eq ptr %1, null
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 144
  %4 = getelementptr inbounds i8, ptr %0, i64 152
  %5 = getelementptr inbounds i8, ptr %0, i64 160
  br label %6

6:                                                ; preds = %.lr.ph, %20
  %.011 = phi ptr [ %1, %.lr.ph ], [ %22, %20 ]
  %7 = getelementptr inbounds i8, ptr %.011, i64 32
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = load double, ptr %3, align 8, !tbaa !12
  %10 = fcmp olt double %8, %9
  br i1 %10, label %11, label %20

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %.011, i64 8
  %13 = load double, ptr %12, align 8, !tbaa !22
  %14 = load double, ptr %4, align 8, !tbaa !23
  %15 = fadd double %13, %14
  %16 = getelementptr inbounds i8, ptr %.011, i64 16
  %17 = load double, ptr %16, align 8, !tbaa !24
  %18 = load double, ptr %5, align 8, !tbaa !25
  %19 = fadd double %17, %18
  tail call void @sprite_disc(ptr noundef nonnull %0, double noundef %15, double noundef %19, i32 noundef 16711680)
  br label %20

20:                                               ; preds = %11, %6
  %21 = getelementptr inbounds i8, ptr %.011, i64 88
  %22 = load ptr, ptr %21, align 8, !tbaa !26
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !27

._crit_edge:                                      ; preds = %20, %2
  ret void
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass