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

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

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

5:                                                ; preds = %151, %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.s_data, ptr %6, i32 0, i32 19
  %8 = getelementptr inbounds %struct.s_map_result, ptr %7, i32 0, i32 7
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = sitofp i32 %10 to double
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.s_data, ptr %12, i32 0, i32 2
  %14 = load double, ptr %13, align 8, !tbaa !22
  %15 = fdiv double %11, %14
  %16 = fptosi double %15 to i32
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds ptr, ptr %9, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %154

22:                                               ; preds = %5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %148, %22
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.s_data, ptr %24, i32 0, i32 19
  %26 = getelementptr inbounds %struct.s_map_result, ptr %25, i32 0, i32 7
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sitofp i32 %28 to double
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.s_data, ptr %30, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !22
  %33 = fdiv double %29, %32
  %34 = fptosi double %33 to i32
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %27, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = sitofp i32 %38 to double
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_data, ptr %40, i32 0, i32 2
  %42 = load double, ptr %41, align 8, !tbaa !22
  %43 = fdiv double %39, %42
  %44 = fptosi double %43 to i32
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %37, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !23
  %48 = sext i8 %47 to i32
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %151

50:                                               ; preds = %23
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s_data, ptr %51, i32 0, i32 19
  %53 = getelementptr inbounds %struct.s_map_result, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = sitofp i32 %55 to double
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s_data, ptr %57, i32 0, i32 2
  %59 = load double, ptr %58, align 8, !tbaa !22
  %60 = fdiv double %56, %59
  %61 = fptosi double %60 to i32
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds ptr, ptr %54, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = sitofp i32 %65 to double
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.s_data, ptr %67, i32 0, i32 2
  %69 = load double, ptr %68, align 8, !tbaa !22
  %70 = fdiv double %66, %69
  %71 = fptosi double %70 to i32
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %64, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !23
  %75 = sext i8 %74 to i32
  %76 = icmp eq i32 %75, 49
  br i1 %76, label %77, label %82

77:                                               ; preds = %50
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = load i32, ptr %3, align 4, !tbaa !9
  %80 = load i32, ptr %4, align 4, !tbaa !9
  %81 = call i32 @my_pixel_put(ptr noundef %78, i32 noundef %79, i32 noundef %80, i32 noundef 0)
  br label %148

82:                                               ; preds = %50
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.s_data, ptr %83, i32 0, i32 19
  %85 = getelementptr inbounds %struct.s_map_result, ptr %84, i32 0, i32 7
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  %87 = load i32, ptr %4, align 4, !tbaa !9
  %88 = sitofp i32 %87 to double
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.s_data, ptr %89, i32 0, i32 2
  %91 = load double, ptr %90, align 8, !tbaa !22
  %92 = fdiv double %88, %91
  %93 = fptosi double %92 to i32
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds ptr, ptr %86, i64 %94
  %96 = load ptr, ptr %95, align 8, !tbaa !5
  %97 = load i32, ptr %3, align 4, !tbaa !9
  %98 = sitofp i32 %97 to double
  %99 = load ptr, ptr %2, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.s_data, ptr %99, i32 0, i32 2
  %101 = load double, ptr %100, align 8, !tbaa !22
  %102 = fdiv double %98, %101
  %103 = fptosi double %102 to i32
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds i8, ptr %96, i64 %104
  %106 = load i8, ptr %105, align 1, !tbaa !23
  %107 = sext i8 %106 to i32
  %108 = icmp eq i32 %107, 50
  br i1 %108, label %109, label %114

109:                                              ; preds = %82
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = load i32, ptr %3, align 4, !tbaa !9
  %112 = load i32, ptr %4, align 4, !tbaa !9
  %113 = call i32 @my_pixel_put(ptr noundef %110, i32 noundef %111, i32 noundef %112, i32 noundef 255)
  br label %147

114:                                              ; preds = %82
  %115 = load ptr, ptr %2, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.s_data, ptr %115, i32 0, i32 19
  %117 = getelementptr inbounds %struct.s_map_result, ptr %116, i32 0, i32 7
  %118 = load ptr, ptr %117, align 8, !tbaa !11
  %119 = load i32, ptr %4, align 4, !tbaa !9
  %120 = sitofp i32 %119 to double
  %121 = load ptr, ptr %2, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.s_data, ptr %121, i32 0, i32 2
  %123 = load double, ptr %122, align 8, !tbaa !22
  %124 = fdiv double %120, %123
  %125 = fptosi double %124 to i32
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds ptr, ptr %118, i64 %126
  %128 = load ptr, ptr %127, align 8, !tbaa !5
  %129 = load i32, ptr %3, align 4, !tbaa !9
  %130 = sitofp i32 %129 to double
  %131 = load ptr, ptr %2, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.s_data, ptr %131, i32 0, i32 2
  %133 = load double, ptr %132, align 8, !tbaa !22
  %134 = fdiv double %130, %133
  %135 = fptosi double %134 to i32
  %136 = sext i32 %135 to i64
  %137 = getelementptr inbounds i8, ptr %128, i64 %136
  %138 = load i8, ptr %137, align 1, !tbaa !23
  %139 = sext i8 %138 to i32
  %140 = icmp ne i32 %139, 32
  br i1 %140, label %141, label %146

141:                                              ; preds = %114
  %142 = load ptr, ptr %2, align 8, !tbaa !5
  %143 = load i32, ptr %3, align 4, !tbaa !9
  %144 = load i32, ptr %4, align 4, !tbaa !9
  %145 = call i32 @my_pixel_put(ptr noundef %142, i32 noundef %143, i32 noundef %144, i32 noundef 16777215)
  br label %146

146:                                              ; preds = %141, %114
  br label %147

147:                                              ; preds = %146, %109
  br label %148

148:                                              ; preds = %147, %77
  %149 = load i32, ptr %3, align 4, !tbaa !9
  %150 = add nsw i32 %149, 1
  store i32 %150, ptr %3, align 4, !tbaa !9
  br label %23, !llvm.loop !24

151:                                              ; preds = %23
  %152 = load i32, ptr %4, align 4, !tbaa !9
  %153 = add nsw i32 %152, 1
  store i32 %153, ptr %4, align 4, !tbaa !9
  br label %5, !llvm.loop !26

154:                                              ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

declare i32 @my_pixel_put(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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, !6, i64 424}
!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 16}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}


; 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
define dso_local void @maps2d(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 424
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = load double, ptr %3, align 8, !tbaa !20
  %6 = fdiv double 0.000000e+00, %5
  %7 = fptosi double %6 to i32
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds ptr, ptr %4, i64 %8
  %10 = load ptr, ptr %9, align 8, !tbaa !21
  %11 = ptrtoint ptr %10 to i64
  %12 = and i64 %11, 4294967295
  %.not37 = icmp eq i64 %12, 0
  br i1 %.not37, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %1, %35
  %13 = phi double [ %17, %35 ], [ %5, %1 ]
  %14 = phi ptr [ %18, %35 ], [ %4, %1 ]
  %15 = phi double [ %37, %35 ], [ 0.000000e+00, %1 ]
  %.038 = phi i32 [ %36, %35 ], [ 0, %1 ]
  br label %16

16:                                               ; preds = %.preheader, %33
  %17 = phi double [ %.pre39, %33 ], [ %13, %.preheader ]
  %18 = phi ptr [ %.pre, %33 ], [ %14, %.preheader ]
  %.033 = phi i32 [ %34, %33 ], [ 0, %.preheader ]
  %19 = fdiv double %15, %17
  %20 = fptosi double %19 to i32
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %18, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = uitofp nneg i32 %.033 to double
  %25 = fdiv double %24, %17
  %26 = fptosi double %25 to i32
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %23, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !22
  switch i8 %29, label %31 [
    i8 0, label %35
    i8 49, label %.sink.split
    i8 50, label %30
    i8 32, label %33
  ]

30:                                               ; preds = %16
  br label %.sink.split

31:                                               ; preds = %16
  br label %.sink.split

.sink.split:                                      ; preds = %16, %31, %30
  %.sink = phi i32 [ 255, %30 ], [ 16777215, %31 ], [ 0, %16 ]
  %32 = tail call i32 @my_pixel_put(ptr noundef nonnull %0, i32 noundef %.033, i32 noundef %.038, i32 noundef %.sink) #2
  br label %33

33:                                               ; preds = %.sink.split, %16
  %34 = add nuw nsw i32 %.033, 1
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  %.pre39 = load double, ptr %3, align 8, !tbaa !20
  br label %16, !llvm.loop !23

35:                                               ; preds = %16
  %36 = add nuw nsw i32 %.038, 1
  %37 = uitofp nneg i32 %36 to double
  %38 = fdiv double %37, %17
  %39 = fptosi double %38 to i32
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %18, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  %43 = ptrtoint ptr %42 to i64
  %44 = and i64 %43, 4294967295
  %.not = icmp eq i64 %44, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !25

._crit_edge:                                      ; preds = %35, %1
  ret void
}

declare i32 @my_pixel_put(ptr noundef, i32 noundef, i32 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, !11, i64 424}
!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 = !{!11, !11, i64 0}
!22 = !{!8, !8, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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