; LLVM IR from yettabaa/cub3D :: mlx-linux (mlx_destroy_window)

; 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_win_list = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [36 x %struct.s_event_list] }
%struct.s_event_list = type { i32, ptr, ptr }
%struct.s_xvar = type { ptr, i64, i32, i32, ptr, i64, i32, ptr, ptr, ptr, i32, i32, i32, [6 x i32], i64, i64, i32 }

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

16:                                               ; preds = %31, %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %35

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = icmp eq ptr %20, %21
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.s_win_list, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s_win_list, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !13
  br label %31

29:                                               ; preds = %19
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %30, ptr %7, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %29, %23
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_win_list, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  store ptr %34, ptr %6, align 8, !tbaa !5
  br label %16, !llvm.loop !15

35:                                               ; preds = %16
  %36 = getelementptr inbounds %struct.s_win_list, ptr %8, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.s_xvar, ptr %38, i32 0, i32 7
  store ptr %37, ptr %39, align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_xvar, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_win_list, ptr %43, i32 0, i32 0
  %45 = load i64, ptr %44, align 8, !tbaa !18
  %46 = call i32 @XDestroyWindow(ptr noundef %42, i64 noundef %45)
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.s_xvar, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s_win_list, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  %53 = call i32 @XFreeGC(ptr noundef %49, ptr noundef %52)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %54) #4
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.s_xvar, ptr %55, i32 0, i32 12
  %57 = load i32, ptr %56, align 8, !tbaa !20
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %64

59:                                               ; preds = %35
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s_xvar, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = call i32 @XFlush(ptr noundef %62)
  br label %64

64:                                               ; preds = %59, %35
  call void @llvm.lifetime.end.p0(i64 936, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %65 = load i32, ptr %3, align 4
  ret i32 %65
}

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

declare i32 @XDestroyWindow(ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare i32 @XFlush(ptr 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 "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 }

!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, !6, i64 48}
!10 = !{!"s_xvar", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !11, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !7, i64 84, !11, i64 112, !11, i64 120, !12, i64 128}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"s_win_list", !11, 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, !7, i64 72}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 0}
!18 = !{!14, !11, i64 0}
!19 = !{!14, !6, i64 8}
!20 = !{!10, !12, i64 80}


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

%struct.s_win_list = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [36 x %struct.s_event_list] }
%struct.s_event_list = type { i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @mlx_destroy_window(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.s_win_list, align 8
  call void @llvm.lifetime.start.p0(i64 936, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %5, ptr %6, align 8, !tbaa !12
  %.not19 = icmp eq ptr %5, null
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph._crit_edge
  %.021 = phi ptr [ %.1, %.lr.ph._crit_edge ], [ %3, %2 ]
  %.01720 = phi ptr [ %9, %.lr.ph._crit_edge ], [ %5, %2 ]
  %7 = icmp eq ptr %.01720, %1
  %8 = getelementptr inbounds i8, ptr %.01720, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  br i1 %7, label %10, label %.lr.ph._crit_edge

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.021, i64 16
  store ptr %9, ptr %11, align 8, !tbaa !12
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %10
  %.1 = phi ptr [ %.021, %10 ], [ %.01720, %.lr.ph ]
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit:                             ; preds = %.lr.ph._crit_edge
  %.pre22 = load ptr, ptr %6, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %12 = phi ptr [ %.pre22, %._crit_edge.loopexit ], [ null, %2 ]
  store ptr %12, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = load i64, ptr %1, align 8, !tbaa !17
  %15 = tail call i32 @XDestroyWindow(ptr noundef %13, i64 noundef %14) #4
  %16 = load ptr, ptr %0, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = tail call i32 @XFreeGC(ptr noundef %16, ptr noundef %18) #4
  tail call void @free(ptr noundef %1) #4
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %.not18 = icmp eq i32 %21, 0
  br i1 %.not18, label %25, label %22

22:                                               ; preds = %._crit_edge
  %23 = load ptr, ptr %0, align 8, !tbaa !16
  %24 = tail call i32 @XFlush(ptr noundef %23) #4
  br label %25

25:                                               ; preds = %22, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 936, ptr nonnull %3) #4
  ret i32 undef
}

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

declare i32 @XDestroyWindow(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @XFreeGC(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

declare i32 @XFlush(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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, !7, i64 48}
!6 = !{!"s_xvar", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !7, i64 24, !10, i64 32, !11, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !8, i64 84, !10, i64 112, !10, i64 120, !11, i64 128}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 16}
!13 = !{!"s_win_list", !10, 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, !8, i64 72}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 0}
!17 = !{!13, !10, i64 0}
!18 = !{!13, !7, i64 8}
!19 = !{!6, !11, i64 80}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass