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

; 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.XSetWindowAttributes = type { i64, i64, i64, i64, i32, i32, i32, i64, i64, i32, i64, i64, i32, i64, i64 }
%struct.s_xvar = type { ptr, i64, i32, i32, ptr, i64, i32, ptr, ptr, ptr, i32, i32, i32, [6 x i32], i64, i64, i32 }
%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_int_set_win_event_mask(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.XSetWindowAttributes, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 112, ptr %7) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.s_xvar, ptr %8, i32 0, i32 7
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %32, %1
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %43

14:                                               ; preds = %11
  %15 = getelementptr inbounds %struct.XSetWindowAttributes, ptr %7, i32 0, i32 10
  store i64 0, ptr %15, align 8, !tbaa !13
  store i32 36, ptr %6, align 4, !tbaa !15
  br label %16

16:                                               ; preds = %20, %14
  %17 = load i32, ptr %6, align 4, !tbaa !15
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %6, align 4, !tbaa !15
  %19 = icmp ne i32 %17, 0
  br i1 %19, label %20, label %32

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.s_win_list, ptr %21, i32 0, i32 9
  %23 = load i32, ptr %6, align 4, !tbaa !15
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [36 x %struct.s_event_list], ptr %22, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.s_event_list, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !16
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.XSetWindowAttributes, ptr %7, i32 0, i32 10
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = or i64 %30, %28
  store i64 %31, ptr %29, align 8, !tbaa !13
  br label %16, !llvm.loop !18

32:                                               ; preds = %16
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.s_xvar, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.s_win_list, ptr %36, i32 0, i32 0
  %38 = load i64, ptr %37, align 8, !tbaa !21
  %39 = call i32 @XChangeWindowAttributes(ptr noundef %35, i64 noundef %38, i64 noundef 2048, ptr noundef %7)
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_win_list, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  store ptr %42, ptr %4, align 8, !tbaa !5
  br label %11, !llvm.loop !24

43:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 112, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %44 = load i32, ptr %2, align 4
  ret i32 %44
}

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

declare i32 @XChangeWindowAttributes(ptr noundef, i64 noundef, i64 noundef, 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 }

!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, !11, i64 72}
!14 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !11, i64 48, !11, i64 56, !12, i64 64, !11, i64 72, !11, i64 80, !12, i64 88, !11, i64 96, !11, i64 104}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 0}
!17 = !{!"s_event_list", !12, i64 0, !6, i64 8, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !6, i64 0}
!21 = !{!22, !11, i64 0}
!22 = !{!"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}
!23 = !{!22, !6, i64 16}
!24 = distinct !{!24, !19}


; 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.XSetWindowAttributes = type { i64, i64, i64, i64, i32, i32, i32, i64, i64, i32, i64, i64, i32, i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local i32 @mlx_int_set_win_event_mask(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca %struct.XSetWindowAttributes, align 8
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %.0812 = load ptr, ptr %3, align 8, !tbaa !5
  %.not13 = icmp eq ptr %.0812, null
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 72
  br label %5

5:                                                ; preds = %.lr.ph, %5
  %.0814 = phi ptr [ %.0812, %.lr.ph ], [ %.08, %5 ]
  %6 = getelementptr inbounds i8, ptr %.0814, i64 72
  %7 = getelementptr inbounds i8, ptr %.0814, i64 912
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %.0814, i64 888
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = or i32 %8, %10
  %12 = getelementptr inbounds i8, ptr %.0814, i64 864
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = or i32 %11, %13
  %15 = getelementptr inbounds i8, ptr %.0814, i64 840
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = or i32 %14, %16
  %18 = getelementptr inbounds i8, ptr %.0814, i64 816
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = or i32 %17, %19
  %21 = getelementptr inbounds i8, ptr %.0814, i64 792
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = or i32 %20, %22
  %24 = getelementptr inbounds i8, ptr %.0814, i64 768
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = or i32 %23, %25
  %27 = getelementptr inbounds i8, ptr %.0814, i64 744
  %28 = load i32, ptr %27, align 8, !tbaa !9
  %29 = or i32 %26, %28
  %30 = getelementptr inbounds i8, ptr %.0814, i64 720
  %31 = load i32, ptr %30, align 8, !tbaa !9
  %32 = or i32 %29, %31
  %33 = getelementptr inbounds i8, ptr %.0814, i64 696
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = or i32 %32, %34
  %36 = getelementptr inbounds i8, ptr %.0814, i64 672
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = or i32 %35, %37
  %39 = getelementptr inbounds i8, ptr %.0814, i64 648
  %40 = load i32, ptr %39, align 8, !tbaa !9
  %41 = or i32 %38, %40
  %42 = getelementptr inbounds i8, ptr %.0814, i64 624
  %43 = load i32, ptr %42, align 8, !tbaa !9
  %44 = or i32 %41, %43
  %45 = getelementptr inbounds i8, ptr %.0814, i64 600
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = or i32 %44, %46
  %48 = getelementptr inbounds i8, ptr %.0814, i64 576
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = or i32 %47, %49
  %51 = getelementptr inbounds i8, ptr %.0814, i64 552
  %52 = load i32, ptr %51, align 8, !tbaa !9
  %53 = or i32 %50, %52
  %54 = getelementptr inbounds i8, ptr %.0814, i64 528
  %55 = load i32, ptr %54, align 8, !tbaa !9
  %56 = or i32 %53, %55
  %57 = getelementptr inbounds i8, ptr %.0814, i64 504
  %58 = load i32, ptr %57, align 8, !tbaa !9
  %59 = or i32 %56, %58
  %60 = getelementptr inbounds i8, ptr %.0814, i64 480
  %61 = load i32, ptr %60, align 8, !tbaa !9
  %62 = or i32 %59, %61
  %63 = getelementptr inbounds i8, ptr %.0814, i64 456
  %64 = load i32, ptr %63, align 8, !tbaa !9
  %65 = or i32 %62, %64
  %66 = getelementptr inbounds i8, ptr %.0814, i64 432
  %67 = load i32, ptr %66, align 8, !tbaa !9
  %68 = or i32 %65, %67
  %69 = getelementptr inbounds i8, ptr %.0814, i64 408
  %70 = load i32, ptr %69, align 8, !tbaa !9
  %71 = or i32 %68, %70
  %72 = getelementptr inbounds i8, ptr %.0814, i64 384
  %73 = load i32, ptr %72, align 8, !tbaa !9
  %74 = or i32 %71, %73
  %75 = getelementptr inbounds i8, ptr %.0814, i64 360
  %76 = load i32, ptr %75, align 8, !tbaa !9
  %77 = or i32 %74, %76
  %78 = getelementptr inbounds i8, ptr %.0814, i64 336
  %79 = load i32, ptr %78, align 8, !tbaa !9
  %80 = or i32 %77, %79
  %81 = getelementptr inbounds i8, ptr %.0814, i64 312
  %82 = load i32, ptr %81, align 8, !tbaa !9
  %83 = or i32 %80, %82
  %84 = getelementptr inbounds i8, ptr %.0814, i64 288
  %85 = load i32, ptr %84, align 8, !tbaa !9
  %86 = or i32 %83, %85
  %87 = getelementptr inbounds i8, ptr %.0814, i64 264
  %88 = load i32, ptr %87, align 8, !tbaa !9
  %89 = or i32 %86, %88
  %90 = getelementptr inbounds i8, ptr %.0814, i64 240
  %91 = load i32, ptr %90, align 8, !tbaa !9
  %92 = or i32 %89, %91
  %93 = getelementptr inbounds i8, ptr %.0814, i64 216
  %94 = load i32, ptr %93, align 8, !tbaa !9
  %95 = or i32 %92, %94
  %96 = getelementptr inbounds i8, ptr %.0814, i64 192
  %97 = load i32, ptr %96, align 8, !tbaa !9
  %98 = or i32 %95, %97
  %99 = getelementptr inbounds i8, ptr %.0814, i64 168
  %100 = load i32, ptr %99, align 8, !tbaa !9
  %101 = or i32 %98, %100
  %102 = getelementptr inbounds i8, ptr %.0814, i64 144
  %103 = load i32, ptr %102, align 8, !tbaa !9
  %104 = or i32 %101, %103
  %105 = getelementptr inbounds i8, ptr %.0814, i64 120
  %106 = load i32, ptr %105, align 8, !tbaa !9
  %107 = or i32 %104, %106
  %108 = getelementptr inbounds i8, ptr %.0814, i64 96
  %109 = load i32, ptr %108, align 8, !tbaa !9
  %110 = or i32 %107, %109
  %111 = load i32, ptr %6, align 8, !tbaa !9
  %112 = or i32 %110, %111
  %113 = sext i32 %112 to i64
  store i64 %113, ptr %4, align 8, !tbaa !12
  %114 = load ptr, ptr %0, align 8, !tbaa !15
  %115 = load i64, ptr %.0814, align 8, !tbaa !17
  %116 = call i32 @XChangeWindowAttributes(ptr noundef %114, i64 noundef %115, i64 noundef 2048, ptr noundef nonnull %2) #3
  %117 = getelementptr inbounds i8, ptr %.0814, i64 16
  %.08 = load ptr, ptr %117, align 8, !tbaa !5
  %.not = icmp eq ptr %.08, null
  br i1 %.not, label %._crit_edge, label %5, !llvm.loop !19

._crit_edge:                                      ; preds = %5, %1
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %2) #3
  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 @XChangeWindowAttributes(ptr noundef, i64 noundef, i64 noundef, 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 = { 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, !11, i64 0}
!10 = !{!"s_event_list", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 72}
!13 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !14, i64 48, !14, i64 56, !11, i64 64, !14, i64 72, !14, i64 80, !11, i64 88, !14, i64 96, !14, i64 104}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"s_xvar", !6, i64 0, !14, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !14, i64 32, !11, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !7, i64 84, !14, i64 112, !14, i64 120, !11, i64 128}
!17 = !{!18, !14, i64 0}
!18 = !{!"s_win_list", !14, 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}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass