; 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_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: 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 speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

; 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
define dso_local ptr @visible_sprite(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i32 -1, ptr %3, align 4, !tbaa !9
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %68, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.s_data, ptr %9, i32 0, i32 14
  %11 = getelementptr inbounds %struct.s_sprites, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp slt i32 %8, %12
  br i1 %13, label %14, label %69

14:                                               ; preds = %6
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.s_data, ptr %15, i32 0, i32 3
  %17 = load double, ptr %16, align 8, !tbaa !22
  %18 = call double @normalize_angle_360(double noundef %17)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_data, ptr %19, i32 0, i32 13
  %21 = load ptr, ptr %20, align 8, !tbaa !23
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.s_GetSprites, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.s_GetSprites, ptr %24, i32 0, i32 3
  %26 = load double, ptr %25, align 8, !tbaa !24
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s_data, ptr %27, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !26
  %30 = fsub double %26, %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s_data, ptr %31, i32 0, i32 13
  %33 = load ptr, ptr %32, align 8, !tbaa !23
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.s_GetSprites, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.s_GetSprites, ptr %36, i32 0, i32 2
  %38 = load double, ptr %37, align 8, !tbaa !27
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.s_data, ptr %39, i32 0, i32 0
  %41 = load double, ptr %40, align 8, !tbaa !28
  %42 = fsub double %38, %41
  %43 = call double @atan2(double noundef %30, double noundef %42) #5
  %44 = call double @_deg(double noundef %43)
  %45 = call double @normalize_angle_360(double noundef %44)
  %46 = fsub double %18, %45
  %47 = call double @llvm.fabs.f64(double %46)
  store double %47, ptr %4, align 8, !tbaa !29
  %48 = load double, ptr %4, align 8, !tbaa !29
  %49 = fcmp ogt double %48, 3.300000e+02
  br i1 %49, label %50, label %54

50:                                               ; preds = %14
  %51 = load double, ptr %4, align 8, !tbaa !29
  %52 = fsub double %51, 3.300000e+02
  store double %52, ptr %4, align 8, !tbaa !29
  %53 = fcmp une double %52, 0.000000e+00
  br label %54

54:                                               ; preds = %50, %14
  %55 = phi i1 [ false, %14 ], [ %53, %50 ]
  %56 = zext i1 %55 to i32
  %57 = load double, ptr %4, align 8, !tbaa !29
  %58 = fcmp ole double %57, 3.000000e+01
  br i1 %58, label %59, label %68

59:                                               ; preds = %54
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.s_data, ptr %61, i32 0, i32 13
  %63 = load ptr, ptr %62, align 8, !tbaa !23
  %64 = load i32, ptr %3, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.s_GetSprites, ptr %63, i64 %65
  %67 = call ptr @newsprite(ptr noundef %60, ptr noundef byval(%struct.s_GetSprites) align 8 %66)
  call void @addobjt(ptr noundef %5, ptr noundef %67)
  br label %68

68:                                               ; preds = %59, %54
  br label %6, !llvm.loop !30

69:                                               ; preds = %6
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr %70
}

declare double @normalize_angle_360(double noundef) #3

declare double @_deg(double noundef) #3

; Function Attrs: nounwind
declare double @atan2(double noundef, double noundef) #4

declare void @addobjt(ptr noundef, ptr noundef) #3

declare ptr @newsprite(ptr noundef, ptr noundef byval(%struct.s_GetSprites) align 8) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { "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 "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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 132}
!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 = !{!12, !13, i64 24}
!23 = !{!12, !6, i64 104}
!24 = !{!25, !13, i64 16}
!25 = !{!"s_GetSprites", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 16}
!26 = !{!12, !13, i64 8}
!27 = !{!25, !13, i64 8}
!28 = !{!12, !13, i64 0}
!29 = !{!13, !13, i64 0}
!30 = distinct !{!30, !31}
!31 = !{!"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"

%struct.s_GetSprites = type { i32, i32, double, double }

; 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 speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @visible_sprite(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store ptr null, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 132
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = getelementptr inbounds i8, ptr %0, i64 104
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br label %9

9:                                                ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %10 = load double, ptr %6, align 8, !tbaa !21
  %11 = call double @normalize_angle_360(double noundef %10) #5
  %12 = load ptr, ptr %7, align 8, !tbaa !22
  %13 = getelementptr inbounds %struct.s_GetSprites, ptr %12, i64 %indvars.iv
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load double, ptr %14, align 8, !tbaa !23
  %16 = load double, ptr %8, align 8, !tbaa !25
  %17 = fsub double %15, %16
  %18 = getelementptr inbounds i8, ptr %13, i64 8
  %19 = load double, ptr %18, align 8, !tbaa !26
  %20 = load double, ptr %0, align 8, !tbaa !27
  %21 = fsub double %19, %20
  %22 = call double @atan2(double noundef %17, double noundef %21) #5
  %23 = call double @_deg(double noundef %22) #5
  %24 = call double @normalize_angle_360(double noundef %23) #5
  %25 = fsub double %11, %24
  %26 = call double @llvm.fabs.f64(double %25)
  %27 = fcmp ogt double %26, 3.300000e+02
  %28 = fadd double %26, -3.300000e+02
  %.0 = select i1 %27, double %28, double %26
  %29 = fcmp ugt double %.0, 3.000000e+01
  br i1 %29, label %34, label %30

30:                                               ; preds = %9
  %31 = load ptr, ptr %7, align 8, !tbaa !22
  %32 = getelementptr inbounds %struct.s_GetSprites, ptr %31, i64 %indvars.iv
  %33 = call ptr @newsprite(ptr noundef nonnull %0, ptr noundef byval(%struct.s_GetSprites) align 8 %32) #5
  call void @addobjt(ptr noundef nonnull %2, ptr noundef %33) #5
  br label %34

34:                                               ; preds = %30, %9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = icmp slt i64 %indvars.iv.next, %36
  br i1 %37, label %9, label %._crit_edge.loopexit, !llvm.loop !28

._crit_edge.loopexit:                             ; preds = %34
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %38 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ null, %1 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret ptr %38
}

declare double @normalize_angle_360(double noundef) local_unnamed_addr #3

declare double @_deg(double noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @atan2(double noundef, double noundef) local_unnamed_addr #4

declare void @addobjt(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @newsprite(ptr noundef, ptr noundef byval(%struct.s_GetSprites) align 8) local_unnamed_addr #3

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


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