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

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

@.str.7 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare void @ft_error(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @parsing(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.s_data, ptr %10, i32 0, i32 19
  call void @init_map(ptr noundef %11)
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  call void @check_arg(i32 noundef %12, ptr noundef %13)
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call ptr @fill_array_map(ptr noundef %14)
  store ptr %15, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  call void @if_empty(ptr noundef %16)
  br label %17

17:                                               ; preds = %62, %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %63

24:                                               ; preds = %17
  br label %25

25:                                               ; preds = %52, %24
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %50

32:                                               ; preds = %25
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = call i64 @ft_strlen(ptr noundef %37)
  %39 = icmp eq i64 %38, 1
  br i1 %39, label %48, label %40

40:                                               ; preds = %32
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = call i32 @tab_spaces_checker(ptr noundef %45)
  %47 = icmp eq i32 %46, 1
  br label %48

48:                                               ; preds = %40, %32
  %49 = phi i1 [ true, %32 ], [ %47, %40 ]
  br label %50

50:                                               ; preds = %48, %25
  %51 = phi i1 [ false, %25 ], [ %49, %48 ]
  br i1 %51, label %52, label %55

52:                                               ; preds = %50
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %8, align 4, !tbaa !9
  br label %25, !llvm.loop !11

55:                                               ; preds = %50
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.s_data, ptr %57, i32 0, i32 19
  %59 = call i32 @up_and_down(ptr noundef %56, ptr noundef %8, ptr noundef %9, ptr noundef %58)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  br label %63

62:                                               ; preds = %55
  br label %17, !llvm.loop !13

63:                                               ; preds = %61, %17
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free_array(ptr noundef %64)
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s_data, ptr %65, i32 0, i32 19
  %67 = getelementptr inbounds %struct.s_map_result, ptr %66, i32 0, i32 6
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = icmp ne ptr %68, null
  br i1 %69, label %71, label %70

70:                                               ; preds = %63
  call void @ft_error(ptr noundef @.str.9, ptr noundef @.str.7)
  br label %71

71:                                               ; preds = %70, %63
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.s_data, ptr %72, i32 0, i32 19
  call void @check_null(ptr noundef %73)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.s_data, ptr %74, i32 0, i32 19
  call void @if_duplicate(ptr noundef %75)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.s_data, ptr %76, i32 0, i32 19
  %78 = call i32 @player_position(ptr noundef %77)
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.s_data, ptr %79, i32 0, i32 19
  %81 = getelementptr inbounds %struct.s_map_result, ptr %80, i32 0, i32 6
  %82 = load ptr, ptr %81, align 8, !tbaa !14
  call void @free_array(ptr noundef %82)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare void @init_map(ptr noundef) #1

declare void @check_arg(i32 noundef, ptr noundef) #1

declare ptr @fill_array_map(ptr noundef) #1

declare void @if_empty(ptr noundef) #1

declare i64 @ft_strlen(ptr noundef) #1

declare i32 @tab_spaces_checker(ptr noundef) #1

declare i32 @up_and_down(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @free_array(ptr noundef) #1

declare void @check_null(ptr noundef) #1

declare void @if_duplicate(ptr noundef) #1

declare i32 @player_position(ptr noundef) #1

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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !6, i64 416}
!15 = !{!"s_data", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64, !16, i64 72, !10, i64 80, !16, i64 88, !16, i64 96, !6, i64 104, !17, i64 112, !18, i64 144, !19, i64 184, !20, i64 208, !21, i64 336, !22, i64 376, !23, i64 456, !24, i64 528, !6, i64 584}
!16 = !{!"double", !7, i64 0}
!17 = !{!"s_sprites", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!18 = !{!"s_minimap", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32}
!19 = !{!"s_door", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!20 = !{!"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}
!21 = !{!"s_hook", !16, i64 0, !10, i64 8, !16, i64 16, !16, i64 24, !16, i64 32}
!22 = !{!"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}
!23 = !{!"s_rycast", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64}
!24 = !{!"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}


; 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.7 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [14 x i8], align 1

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

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

declare void @ft_error(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @parsing(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 376
  tail call void @init_map(ptr noundef nonnull %6) #3
  tail call void @check_arg(i32 noundef %1, ptr noundef %2) #3
  %7 = tail call ptr @fill_array_map(ptr noundef %2) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  tail call void @if_empty(ptr noundef %7) #3
  br label %8

8:                                                ; preds = %.critedge, %3
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds ptr, ptr %7, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %29, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.critedge2
  %13 = phi ptr [ %27, %.critedge2 ], [ %12, %8 ]
  %14 = call i64 @ft_strlen(ptr noundef nonnull %13) #3
  %15 = icmp eq i64 %14, 1
  br i1 %15, label %.critedge2, label %16

16:                                               ; preds = %.lr.ph
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds ptr, ptr %7, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = call i32 @tab_spaces_checker(ptr noundef %20) #3
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %.critedge2, label %.critedge

.critedge2:                                       ; preds = %.lr.ph, %16
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %7, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %.not18 = icmp eq ptr %27, null
  br i1 %.not18, label %.critedge, label %.lr.ph, !llvm.loop !11

.critedge:                                        ; preds = %16, %.critedge2
  %28 = call i32 @up_and_down(ptr noundef nonnull %7, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6) #3
  %.not19 = icmp eq i32 %28, 0
  br i1 %.not19, label %8, label %29, !llvm.loop !13

29:                                               ; preds = %.critedge, %8
  call void @free_array(ptr noundef nonnull %7) #3
  %30 = getelementptr inbounds i8, ptr %0, i64 416
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %.not20 = icmp eq ptr %31, null
  br i1 %.not20, label %32, label %33

32:                                               ; preds = %29
  call void @ft_error(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.7) #3
  br label %33

33:                                               ; preds = %32, %29
  call void @check_null(ptr noundef nonnull %6) #3
  call void @if_duplicate(ptr noundef nonnull %6) #3
  %34 = call i32 @player_position(ptr noundef nonnull %6) #3
  %35 = load ptr, ptr %30, align 8, !tbaa !14
  call void @free_array(ptr noundef %35) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret void
}

declare void @init_map(ptr noundef) local_unnamed_addr #1

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

declare ptr @fill_array_map(ptr noundef) local_unnamed_addr #1

declare void @if_empty(ptr noundef) local_unnamed_addr #1

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #1

declare i32 @tab_spaces_checker(ptr noundef) local_unnamed_addr #1

declare i32 @up_and_down(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @free_array(ptr noundef) local_unnamed_addr #1

declare void @check_null(ptr noundef) local_unnamed_addr #1

declare void @if_duplicate(ptr noundef) local_unnamed_addr #1

declare i32 @player_position(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !10, i64 416}
!15 = !{!"s_data", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64, !16, i64 72, !6, i64 80, !16, i64 88, !16, i64 96, !10, i64 104, !17, i64 112, !18, i64 144, !19, i64 184, !20, i64 208, !21, i64 336, !22, i64 376, !23, i64 456, !24, i64 528, !10, i64 584}
!16 = !{!"double", !7, i64 0}
!17 = !{!"s_sprites", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28}
!18 = !{!"s_minimap", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32}
!19 = !{!"s_door", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16}
!20 = !{!"s_textures", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !10, i64 32, !6, i64 40, !6, i64 44, !6, i64 48, !10, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !10, i64 80, !6, i64 88, !6, i64 92, !6, i64 96, !10, i64 104, !6, i64 112, !6, i64 116, !6, i64 120}
!21 = !{!"s_hook", !16, i64 0, !6, i64 8, !16, i64 16, !16, i64 24, !16, i64 32}
!22 = !{!"s_map_result", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !7, i64 72}
!23 = !{!"s_rycast", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64}
!24 = !{!"s_mlx", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !6, i64 44, !6, i64 48}


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