; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @my_pixel_put(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #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 void @old_dda(ptr noundef %0, double noundef %1, double noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %13 = load double, ptr %6, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s_data, ptr %14, i32 0, i32 8
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = fsub double %13, %16
  %18 = call double @llvm.fabs.f64(double %17)
  %19 = load double, ptr %7, align 8, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.s_data, ptr %20, i32 0, i32 9
  %22 = load double, ptr %21, align 8, !tbaa !23
  %23 = fsub double %19, %22
  %24 = call double @llvm.fabs.f64(double %23)
  %25 = call double @llvm.maxnum.f64(double %18, double %24)
  store double %25, ptr %12, align 8, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.s_data, ptr %26, i32 0, i32 8
  %28 = load double, ptr %27, align 8, !tbaa !13
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = fsub double %28, %29
  %31 = load double, ptr %12, align 8, !tbaa !9
  %32 = fdiv double %30, %31
  store double %32, ptr %10, align 8, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.s_data, ptr %33, i32 0, i32 9
  %35 = load double, ptr %34, align 8, !tbaa !23
  %36 = load double, ptr %7, align 8, !tbaa !9
  %37 = fsub double %35, %36
  %38 = load double, ptr %12, align 8, !tbaa !9
  %39 = fdiv double %37, %38
  store double %39, ptr %11, align 8, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %49, %4
  %41 = load i32, ptr %9, align 4, !tbaa !11
  %42 = sitofp i32 %41 to double
  %43 = load double, ptr %12, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.s_data, ptr %44, i32 0, i32 4
  %46 = load double, ptr %45, align 8, !tbaa !24
  %47 = fadd double %43, %46
  %48 = fcmp ole double %42, %47
  br i1 %48, label %49, label %67

49:                                               ; preds = %40
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load double, ptr %6, align 8, !tbaa !9
  %52 = call double @llvm.round.f64(double %51)
  %53 = fptosi double %52 to i32
  %54 = load double, ptr %7, align 8, !tbaa !9
  %55 = call double @llvm.round.f64(double %54)
  %56 = fptosi double %55 to i32
  %57 = load i32, ptr %8, align 4, !tbaa !11
  %58 = call i32 @my_pixel_put(ptr noundef %50, i32 noundef %53, i32 noundef %56, i32 noundef %57)
  %59 = load double, ptr %6, align 8, !tbaa !9
  %60 = load double, ptr %10, align 8, !tbaa !9
  %61 = fadd double %59, %60
  store double %61, ptr %6, align 8, !tbaa !9
  %62 = load double, ptr %7, align 8, !tbaa !9
  %63 = load double, ptr %11, align 8, !tbaa !9
  %64 = fadd double %62, %63
  store double %64, ptr %7, align 8, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !11
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !11
  br label %40, !llvm.loop !25

67:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.maxnum.f64(double, double) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 64}
!14 = !{!"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, !12, i64 80, !10, i64 88, !10, 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, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!16 = !{!"s_minimap", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!17 = !{!"s_door", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!18 = !{!"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}
!19 = !{!"s_hook", !10, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!20 = !{!"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}
!21 = !{!"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}
!22 = !{!"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}
!23 = !{!14, !10, i64 72}
!24 = !{!14, !10, i64 32}
!25 = distinct !{!25, !26}
!26 = !{!"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"

declare i32 @my_pixel_put(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @old_dda(ptr noundef %0, double noundef %1, double noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load <2 x double>, ptr %5, align 8, !tbaa !5
  %7 = extractelement <2 x double> %6, i64 0
  %8 = fsub double %1, %7
  %9 = tail call double @llvm.fabs.f64(double %8)
  %10 = extractelement <2 x double> %6, i64 1
  %11 = fsub double %2, %10
  %12 = tail call double @llvm.fabs.f64(double %11)
  %13 = tail call double @llvm.maxnum.f64(double %9, double %12)
  %14 = insertelement <2 x double> poison, double %1, i64 0
  %15 = insertelement <2 x double> %14, double %2, i64 1
  %16 = fsub <2 x double> %6, %15
  %17 = insertelement <2 x double> poison, double %13, i64 0
  %18 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> zeroinitializer
  %19 = fdiv <2 x double> %16, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fadd double %13, %21
  %23 = fcmp ult double %22, 0.000000e+00
  br i1 %23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.02223 = phi i32 [ %33, %.lr.ph ], [ 0, %4 ]
  %24 = phi <2 x double> [ %32, %.lr.ph ], [ %15, %4 ]
  %25 = extractelement <2 x double> %24, i64 0
  %26 = tail call double @llvm.round.f64(double %25)
  %27 = fptosi double %26 to i32
  %28 = extractelement <2 x double> %24, i64 1
  %29 = tail call double @llvm.round.f64(double %28)
  %30 = fptosi double %29 to i32
  %31 = tail call i32 @my_pixel_put(ptr noundef nonnull %0, i32 noundef %27, i32 noundef %30, i32 noundef %3) #3
  %32 = fadd <2 x double> %19, %24
  %33 = add nuw nsw i32 %.02223, 1
  %34 = uitofp nneg i32 %33 to double
  %35 = load double, ptr %20, align 8, !tbaa !9
  %36 = fadd double %13, %35
  %37 = fcmp ult double %36, %34
  br i1 %37, label %._crit_edge, label %.lr.ph, !llvm.loop !21

._crit_edge:                                      ; preds = %.lr.ph, %4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.maxnum.f64(double, double) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #2

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


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