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

; Function Attrs: nounwind uwtable
declare dso_local void @dda_sprite(ptr noundef, ptr noundef, double noundef, double noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @render_ssprite(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.s_data, ptr %5, i32 0, i32 14
  %7 = getelementptr inbounds %struct.s_sprites, ptr %6, i32 0, i32 5
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 8001
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.s_data, ptr %11, i32 0, i32 14
  %13 = getelementptr inbounds %struct.s_sprites, ptr %12, i32 0, i32 5
  store i32 0, ptr %13, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %10, %2
  %15 = phi i1 [ false, %2 ], [ false, %10 ]
  %16 = zext i1 %15 to i32
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.s_data, ptr %17, i32 0, i32 14
  %19 = getelementptr inbounds %struct.s_sprites, ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = icmp eq i32 %20, 8000
  br i1 %21, label %22, label %29

22:                                               ; preds = %14
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s_data, ptr %23, i32 0, i32 14
  %25 = getelementptr inbounds %struct.s_sprites, ptr %24, i32 0, i32 6
  %26 = load i32, ptr %25, align 4, !tbaa !21
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !21
  %28 = icmp ne i32 %27, 0
  br label %29

29:                                               ; preds = %22, %14
  %30 = phi i1 [ false, %14 ], [ %28, %22 ]
  %31 = zext i1 %30 to i32
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_data, ptr %32, i32 0, i32 14
  %34 = getelementptr inbounds %struct.s_sprites, ptr %33, i32 0, i32 6
  %35 = load i32, ptr %34, align 4, !tbaa !21
  %36 = icmp eq i32 %35, 5
  br i1 %36, label %37, label %41

37:                                               ; preds = %29
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_data, ptr %38, i32 0, i32 14
  %40 = getelementptr inbounds %struct.s_sprites, ptr %39, i32 0, i32 6
  store i32 0, ptr %40, align 4, !tbaa !21
  br label %41

41:                                               ; preds = %37, %29
  %42 = phi i1 [ false, %29 ], [ false, %37 ]
  %43 = zext i1 %42 to i32
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.s_data, ptr %45, i32 0, i32 14
  %47 = getelementptr inbounds %struct.s_sprites, ptr %46, i32 0, i32 6
  %48 = load i32, ptr %47, align 4, !tbaa !21
  %49 = srem i32 %48, 5
  call void @fill_sprite(ptr noundef %44, i32 noundef %49)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_data, ptr %50, i32 0, i32 14
  %52 = getelementptr inbounds %struct.s_sprites, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 8, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %52, align 8, !tbaa !9
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.s_object, ptr %55, i32 0, i32 9
  %57 = load double, ptr %56, align 8, !tbaa !22
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s_data, ptr %58, i32 0, i32 11
  store double %57, ptr %59, align 8, !tbaa !24
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s_object, ptr %60, i32 0, i32 10
  %62 = load double, ptr %61, align 8, !tbaa !25
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.s_data, ptr %63, i32 0, i32 12
  store double %62, ptr %64, align 8, !tbaa !26
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s_data, ptr %65, i32 0, i32 10
  %67 = load i32, ptr %66, align 8, !tbaa !27
  %68 = sitofp i32 %67 to double
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.s_object, ptr %69, i32 0, i32 7
  %71 = load double, ptr %70, align 8, !tbaa !28
  %72 = fcmp oge double %68, %71
  br i1 %72, label %73, label %91

73:                                               ; preds = %41
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.s_data, ptr %74, i32 0, i32 10
  %76 = load i32, ptr %75, align 8, !tbaa !27
  %77 = sitofp i32 %76 to double
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.s_object, ptr %78, i32 0, i32 8
  %80 = load double, ptr %79, align 8, !tbaa !29
  %81 = fcmp ole double %77, %80
  br i1 %81, label %82, label %91

82:                                               ; preds = %73
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.s_data, ptr %85, i32 0, i32 11
  %87 = load double, ptr %86, align 8, !tbaa !24
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.s_data, ptr %88, i32 0, i32 12
  %90 = load double, ptr %89, align 8, !tbaa !26
  call void @dda_sprite(ptr noundef %83, ptr noundef %84, double noundef %87, double noundef %90)
  br label %91

91:                                               ; preds = %82, %73, %41
  ret void
}

declare void @fill_sprite(ptr noundef, i32 noundef) #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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 136}
!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, !12, i64 140}
!22 = !{!23, !11, i64 72}
!23 = !{!"s_object", !12, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !6, i64 88}
!24 = !{!10, !11, i64 88}
!25 = !{!23, !11, i64 80}
!26 = !{!10, !11, i64 96}
!27 = !{!10, !12, i64 80}
!28 = !{!23, !11, i64 56}
!29 = !{!23, !11, i64 64}


; 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 @dda_sprite(ptr noundef, ptr noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @render_ssprite(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 136
  %4 = load i32, ptr %3, align 8, !tbaa !5
  switch i32 %4, label %9 [
    i32 8001, label %.thread
    i32 8000, label %5
  ]

.thread:                                          ; preds = %2
  store i32 0, ptr %3, align 8, !tbaa !5
  br label %9

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 140
  %7 = load i32, ptr %6, align 4, !tbaa !20
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %6, align 4, !tbaa !20
  br label %9

9:                                                ; preds = %2, %.thread, %5
  %10 = getelementptr inbounds i8, ptr %0, i64 140
  %11 = load i32, ptr %10, align 4, !tbaa !20
  %12 = icmp eq i32 %11, 5
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  store i32 0, ptr %10, align 4, !tbaa !20
  br label %14

14:                                               ; preds = %13, %9
  %15 = phi i32 [ 0, %13 ], [ %11, %9 ]
  %16 = srem i32 %15, 5
  tail call void @fill_sprite(ptr noundef nonnull %0, i32 noundef %16) #2
  %17 = load i32, ptr %3, align 8, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 72
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  %21 = load <2 x double>, ptr %19, align 8, !tbaa !21
  store <2 x double> %21, ptr %20, align 8, !tbaa !21
  %22 = getelementptr inbounds i8, ptr %0, i64 80
  %23 = load i32, ptr %22, align 8, !tbaa !22
  %24 = sitofp i32 %23 to double
  %25 = getelementptr inbounds i8, ptr %1, i64 56
  %26 = load double, ptr %25, align 8, !tbaa !23
  %27 = fcmp ugt double %26, %24
  br i1 %27, label %35, label %28

28:                                               ; preds = %14
  %29 = getelementptr inbounds i8, ptr %1, i64 64
  %30 = load double, ptr %29, align 8, !tbaa !25
  %31 = fcmp ult double %30, %24
  br i1 %31, label %35, label %32

32:                                               ; preds = %28
  %33 = extractelement <2 x double> %21, i64 0
  %34 = extractelement <2 x double> %21, i64 1
  tail call void @dda_sprite(ptr noundef nonnull %0, ptr noundef nonnull %1, double noundef %33, double noundef %34)
  br label %35

35:                                               ; preds = %32, %28, %14
  ret void
}

declare void @fill_sprite(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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, !10, i64 136}
!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 = !{!6, !10, i64 140}
!21 = !{!7, !7, i64 0}
!22 = !{!6, !10, i64 80}
!23 = !{!24, !7, i64 56}
!24 = !{!"s_object", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !11, i64 88}
!25 = !{!24, !7, i64 64}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass