; LLVM IR from yettabaa/cub3D :: bonus (door)

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

@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

declare void @my_exit(ptr noundef, ptr noundef, i32 noundef) #2

; 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 @newdoor(ptr noundef %0, double noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %8 = call noalias ptr @malloc(i64 noundef 96) #7
  store ptr %8, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %7, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %13, label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @my_exit(ptr noundef %12, ptr noundef @.str.4, i32 noundef 1)
  br label %13

13:                                               ; preds = %11, %3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s_object, ptr %14, i32 0, i32 0
  store i32 23, ptr %15, align 8, !tbaa !13
  %16 = load i32, ptr %6, align 4, !tbaa !11
  %17 = icmp eq i32 %16, 22
  br i1 %17, label %18, label %21

18:                                               ; preds = %13
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s_object, ptr %19, i32 0, i32 0
  store i32 22, ptr %20, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %18, %13
  %22 = phi i1 [ false, %13 ], [ true, %18 ]
  %23 = zext i1 %22 to i32
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s_object, ptr %25, i32 0, i32 3
  store double %24, ptr %26, align 8, !tbaa !15
  %27 = load double, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.s_data, ptr %28, i32 0, i32 3
  %30 = load double, ptr %29, align 8, !tbaa !16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s_data, ptr %31, i32 0, i32 20
  %33 = getelementptr inbounds %struct.s_rycast, ptr %32, i32 0, i32 2
  %34 = load double, ptr %33, align 8, !tbaa !26
  %35 = fsub double %30, %34
  %36 = call double @rad(double noundef %35)
  %37 = call double @cos(double noundef %36) #6
  %38 = fmul double %27, %37
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.s_object, ptr %39, i32 0, i32 4
  store double %38, ptr %40, align 8, !tbaa !27
  %41 = load i32, ptr %6, align 4, !tbaa !11
  %42 = icmp eq i32 %41, 7
  br i1 %42, label %46, label %43

43:                                               ; preds = %21
  %44 = load i32, ptr %6, align 4, !tbaa !11
  %45 = icmp eq i32 %44, 8
  br i1 %45, label %46, label %51

46:                                               ; preds = %43, %21
  %47 = load i32, ptr %6, align 4, !tbaa !11
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s_object, ptr %48, i32 0, i32 5
  store i32 %47, ptr %49, align 8, !tbaa !28
  %50 = icmp ne i32 %47, 0
  br label %51

51:                                               ; preds = %46, %43
  %52 = phi i1 [ false, %43 ], [ %50, %46 ]
  %53 = zext i1 %52 to i32
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.s_data, ptr %54, i32 0, i32 0
  %56 = load double, ptr %55, align 8, !tbaa !29
  %57 = load double, ptr %5, align 8, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s_data, ptr %58, i32 0, i32 20
  %60 = getelementptr inbounds %struct.s_rycast, ptr %59, i32 0, i32 2
  %61 = load double, ptr %60, align 8, !tbaa !26
  %62 = call double @rad(double noundef %61)
  %63 = call double @cos(double noundef %62) #6
  %64 = call double @llvm.fmuladd.f64(double %57, double %63, double %56)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s_object, ptr %65, i32 0, i32 1
  store double %64, ptr %66, align 8, !tbaa !30
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.s_data, ptr %67, i32 0, i32 1
  %69 = load double, ptr %68, align 8, !tbaa !31
  %70 = load double, ptr %5, align 8, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.s_data, ptr %71, i32 0, i32 20
  %73 = getelementptr inbounds %struct.s_rycast, ptr %72, i32 0, i32 2
  %74 = load double, ptr %73, align 8, !tbaa !26
  %75 = call double @rad(double noundef %74)
  %76 = call double @sin(double noundef %75) #6
  %77 = call double @llvm.fmuladd.f64(double %70, double %76, double %69)
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.s_object, ptr %78, i32 0, i32 2
  store double %77, ptr %79, align 8, !tbaa !32
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.s_object, ptr %80, i32 0, i32 11
  store ptr null, ptr %81, align 8, !tbaa !33
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret ptr %82
}

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

declare double @rad(double noundef) #2

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { "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 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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, !12, i64 0}
!14 = !{!"s_object", !12, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !12, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !6, i64 88}
!15 = !{!14, !10, i64 24}
!16 = !{!17, !10, i64 24}
!17 = !{!"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, !18, i64 112, !19, i64 144, !20, i64 184, !21, i64 208, !22, i64 336, !23, i64 376, !24, i64 456, !25, i64 528, !6, i64 584}
!18 = !{!"s_sprites", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!19 = !{!"s_minimap", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!20 = !{!"s_door", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!21 = !{!"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}
!22 = !{!"s_hook", !10, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!23 = !{!"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}
!24 = !{!"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}
!25 = !{!"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}
!26 = !{!17, !10, i64 472}
!27 = !{!14, !10, i64 32}
!28 = !{!14, !12, i64 40}
!29 = !{!17, !10, i64 0}
!30 = !{!14, !10, i64 8}
!31 = !{!17, !10, i64 8}
!32 = !{!14, !10, i64 16}
!33 = !{!14, !6, i64 88}


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

@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

declare void @my_exit(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @newdoor(ptr noundef %0, double noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = tail call noalias dereferenceable_or_null(96) ptr @malloc(i64 noundef 96) #5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %3
  tail call void @my_exit(ptr noundef %0, ptr noundef nonnull @.str.4, i32 noundef 1) #6
  br label %6

6:                                                ; preds = %5, %3
  %7 = icmp eq i32 %2, 22
  %spec.select = select i1 %7, i32 22, i32 23
  store i32 %spec.select, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 24
  store double %1, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 472
  %12 = load double, ptr %11, align 8, !tbaa !23
  %13 = fsub double %10, %12
  %14 = tail call double @rad(double noundef %13) #6
  %15 = tail call double @cos(double noundef %14) #6
  %16 = fmul double %15, %1
  %17 = getelementptr inbounds i8, ptr %4, i64 32
  store double %16, ptr %17, align 8, !tbaa !24
  %18 = add i32 %2, -7
  %or.cond = icmp ult i32 %18, 2
  br i1 %or.cond, label %19, label %21

19:                                               ; preds = %6
  %20 = getelementptr inbounds i8, ptr %4, i64 40
  store i32 %2, ptr %20, align 8, !tbaa !25
  br label %21

21:                                               ; preds = %6, %19
  %22 = load double, ptr %11, align 8, !tbaa !23
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load double, ptr %0, align 8, !tbaa !26
  %26 = tail call double @rad(double noundef %22) #6
  %27 = tail call double @cos(double noundef %26) #6
  %28 = load double, ptr %24, align 8, !tbaa !27
  %29 = load double, ptr %11, align 8, !tbaa !23
  %30 = tail call double @rad(double noundef %29) #6
  %31 = tail call double @sin(double noundef %30) #6
  %32 = insertelement <2 x double> poison, double %1, i64 0
  %33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> zeroinitializer
  %34 = insertelement <2 x double> poison, double %27, i64 0
  %35 = insertelement <2 x double> %34, double %31, i64 1
  %36 = insertelement <2 x double> poison, double %25, i64 0
  %37 = insertelement <2 x double> %36, double %28, i64 1
  %38 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %35, <2 x double> %37)
  store <2 x double> %38, ptr %23, align 8, !tbaa !28
  %39 = getelementptr inbounds i8, ptr %4, i64 88
  store ptr null, ptr %39, align 8, !tbaa !29
  ret ptr %4
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #3

declare double @rad(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #4

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { 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 0}
!6 = !{!"s_object", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !11, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!14, !10, i64 24}
!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, !7, i64 80, !10, i64 88, !10, i64 96, !11, 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, !11, i64 584}
!15 = !{!"s_sprites", !11, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!16 = !{!"s_minimap", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!17 = !{!"s_door", !11, i64 0, !7, i64 8, !7, i64 12, !7, i64 16}
!18 = !{!"s_textures", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 20, !7, i64 24, !11, i64 32, !7, i64 40, !7, i64 44, !7, i64 48, !11, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !11, i64 80, !7, i64 88, !7, i64 92, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 116, !7, i64 120}
!19 = !{!"s_hook", !10, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!20 = !{!"s_map_result", !7, i64 0, !7, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !8, 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", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !7, i64 44, !7, i64 48}
!23 = !{!14, !10, i64 472}
!24 = !{!6, !10, i64 32}
!25 = !{!6, !7, i64 40}
!26 = !{!14, !10, i64 0}
!27 = !{!14, !10, i64 8}
!28 = !{!10, !10, i64 0}
!29 = !{!6, !11, i64 88}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass