; LLVM IR from yettabaa/cub3D :: Mandatory (raycasting)

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

declare i32 @is(ptr noundef, double noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @visualize_maps(ptr noundef %0, double noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.s_data, ptr %9, i32 0, i32 20
  %11 = getelementptr inbounds %struct.s_rycast, ptr %10, i32 0, i32 0
  %12 = load double, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.s_data, ptr %13, i32 0, i32 2
  %15 = load double, ptr %14, align 8, !tbaa !22
  %16 = fdiv double %12, %15
  %17 = fptosi double %16 to i32
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !23
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_data, ptr %19, i32 0, i32 20
  %21 = getelementptr inbounds %struct.s_rycast, ptr %20, i32 0, i32 1
  %22 = load double, ptr %21, align 8, !tbaa !24
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s_data, ptr %23, i32 0, i32 2
  %25 = load double, ptr %24, align 8, !tbaa !22
  %26 = fdiv double %22, %25
  %27 = fptosi double %26 to i32
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %27, ptr %28, align 4, !tbaa !23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load double, ptr %6, align 8, !tbaa !9
  %31 = call i32 @is(ptr noundef %29, double noundef %30, i32 noundef 4)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %49

33:                                               ; preds = %4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.s_data, ptr %34, i32 0, i32 20
  %36 = getelementptr inbounds %struct.s_rycast, ptr %35, i32 0, i32 0
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_data, ptr %38, i32 0, i32 4
  %40 = load double, ptr %39, align 8, !tbaa !25
  %41 = fsub double %37, %40
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.s_data, ptr %42, i32 0, i32 2
  %44 = load double, ptr %43, align 8, !tbaa !22
  %45 = fdiv double %41, %44
  %46 = fptosi double %45 to i32
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %46, ptr %47, align 4, !tbaa !23
  %48 = icmp ne i32 %46, 0
  br label %49

49:                                               ; preds = %33, %4
  %50 = phi i1 [ false, %4 ], [ %48, %33 ]
  %51 = zext i1 %50 to i32
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load double, ptr %6, align 8, !tbaa !9
  %54 = call i32 @is(ptr noundef %52, double noundef %53, i32 noundef 5)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %72

56:                                               ; preds = %49
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s_data, ptr %57, i32 0, i32 20
  %59 = getelementptr inbounds %struct.s_rycast, ptr %58, i32 0, i32 0
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.s_data, ptr %61, i32 0, i32 4
  %63 = load double, ptr %62, align 8, !tbaa !25
  %64 = fadd double %60, %63
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s_data, ptr %65, i32 0, i32 2
  %67 = load double, ptr %66, align 8, !tbaa !22
  %68 = fdiv double %64, %67
  %69 = fptosi double %68 to i32
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %69, ptr %70, align 4, !tbaa !23
  %71 = icmp ne i32 %69, 0
  br label %72

72:                                               ; preds = %56, %49
  %73 = phi i1 [ false, %49 ], [ %71, %56 ]
  %74 = zext i1 %73 to i32
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load double, ptr %6, align 8, !tbaa !9
  %77 = call i32 @is(ptr noundef %75, double noundef %76, i32 noundef 2)
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %83, label %79

79:                                               ; preds = %72
  %80 = load double, ptr %6, align 8, !tbaa !9
  %81 = fptosi double %80 to i32
  %82 = icmp eq i32 %81, 180
  br i1 %82, label %83, label %99

83:                                               ; preds = %79, %72
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.s_data, ptr %84, i32 0, i32 20
  %86 = getelementptr inbounds %struct.s_rycast, ptr %85, i32 0, i32 1
  %87 = load double, ptr %86, align 8, !tbaa !24
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.s_data, ptr %88, i32 0, i32 4
  %90 = load double, ptr %89, align 8, !tbaa !25
  %91 = fsub double %87, %90
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.s_data, ptr %92, i32 0, i32 2
  %94 = load double, ptr %93, align 8, !tbaa !22
  %95 = fdiv double %91, %94
  %96 = fptosi double %95 to i32
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %96, ptr %97, align 4, !tbaa !23
  %98 = icmp ne i32 %96, 0
  br label %99

99:                                               ; preds = %83, %79
  %100 = phi i1 [ false, %79 ], [ %98, %83 ]
  %101 = zext i1 %100 to i32
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = load double, ptr %6, align 8, !tbaa !9
  %104 = call i32 @is(ptr noundef %102, double noundef %103, i32 noundef 3)
  %105 = icmp ne i32 %104, 0
  br i1 %105, label %110, label %106

106:                                              ; preds = %99
  %107 = load double, ptr %6, align 8, !tbaa !9
  %108 = fptosi double %107 to i32
  %109 = icmp ne i32 %108, 0
  br i1 %109, label %126, label %110

110:                                              ; preds = %106, %99
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.s_data, ptr %111, i32 0, i32 20
  %113 = getelementptr inbounds %struct.s_rycast, ptr %112, i32 0, i32 1
  %114 = load double, ptr %113, align 8, !tbaa !24
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.s_data, ptr %115, i32 0, i32 4
  %117 = load double, ptr %116, align 8, !tbaa !25
  %118 = fadd double %114, %117
  %119 = load ptr, ptr %5, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.s_data, ptr %119, i32 0, i32 2
  %121 = load double, ptr %120, align 8, !tbaa !22
  %122 = fdiv double %118, %121
  %123 = fptosi double %122 to i32
  %124 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %123, ptr %124, align 4, !tbaa !23
  %125 = icmp ne i32 %123, 0
  br label %126

126:                                              ; preds = %110, %106
  %127 = phi i1 [ false, %106 ], [ %125, %110 ]
  %128 = zext i1 %127 to i32
  ret void
}

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


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

declare i32 @is(ptr noundef, double noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @visualize_maps(ptr noundef %0, double noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 456
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load double, ptr %7, align 8, !tbaa !20
  %9 = fdiv double %6, %8
  %10 = fptosi double %9 to i32
  store i32 %10, ptr %2, align 4, !tbaa !21
  %11 = getelementptr inbounds i8, ptr %0, i64 464
  %12 = load double, ptr %11, align 8, !tbaa !22
  %13 = fdiv double %12, %8
  %14 = fptosi double %13 to i32
  store i32 %14, ptr %3, align 4, !tbaa !21
  %15 = tail call i32 @is(ptr noundef %0, double noundef %1, i32 noundef 4) #2
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %24, label %16

16:                                               ; preds = %4
  %17 = load double, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load double, ptr %18, align 8, !tbaa !23
  %20 = fsub double %17, %19
  %21 = load double, ptr %7, align 8, !tbaa !20
  %22 = fdiv double %20, %21
  %23 = fptosi double %22 to i32
  store i32 %23, ptr %2, align 4, !tbaa !21
  br label %24

24:                                               ; preds = %16, %4
  %25 = tail call i32 @is(ptr noundef nonnull %0, double noundef %1, i32 noundef 5) #2
  %.not32 = icmp eq i32 %25, 0
  br i1 %.not32, label %34, label %26

26:                                               ; preds = %24
  %27 = load double, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load double, ptr %28, align 8, !tbaa !23
  %30 = fadd double %27, %29
  %31 = load double, ptr %7, align 8, !tbaa !20
  %32 = fdiv double %30, %31
  %33 = fptosi double %32 to i32
  store i32 %33, ptr %2, align 4, !tbaa !21
  br label %34

34:                                               ; preds = %26, %24
  %35 = tail call i32 @is(ptr noundef nonnull %0, double noundef %1, i32 noundef 2) #2
  %.not33 = icmp ne i32 %35, 0
  %36 = fptosi double %1 to i32
  %37 = icmp eq i32 %36, 180
  %or.cond = select i1 %.not33, i1 true, i1 %37
  br i1 %or.cond, label %38, label %46

38:                                               ; preds = %34
  %39 = load double, ptr %11, align 8, !tbaa !22
  %40 = getelementptr inbounds i8, ptr %0, i64 32
  %41 = load double, ptr %40, align 8, !tbaa !23
  %42 = fsub double %39, %41
  %43 = load double, ptr %7, align 8, !tbaa !20
  %44 = fdiv double %42, %43
  %45 = fptosi double %44 to i32
  store i32 %45, ptr %3, align 4, !tbaa !21
  br label %46

46:                                               ; preds = %34, %38
  %47 = tail call i32 @is(ptr noundef nonnull %0, double noundef %1, i32 noundef 3) #2
  %.not34 = icmp ne i32 %47, 0
  %.not35 = icmp eq i32 %36, 0
  %or.cond37 = select i1 %.not34, i1 true, i1 %.not35
  br i1 %or.cond37, label %48, label %56

48:                                               ; preds = %46
  %49 = load double, ptr %11, align 8, !tbaa !22
  %50 = getelementptr inbounds i8, ptr %0, i64 32
  %51 = load double, ptr %50, align 8, !tbaa !23
  %52 = fadd double %49, %51
  %53 = load double, ptr %7, align 8, !tbaa !20
  %54 = fdiv double %52, %53
  %55 = fptosi double %54 to i32
  store i32 %55, ptr %3, align 4, !tbaa !21
  br label %56

56:                                               ; preds = %46, %48
  ret void
}

attributes #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 = { 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, !7, i64 456}
!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, !7, i64 16}
!21 = !{!10, !10, i64 0}
!22 = !{!6, !7, i64 464}
!23 = !{!6, !7, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass