; LLVM IR from leonmavr/gfx-v4 :: src (gfx)

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

%union._XEvent = type { [24 x i64] }

@gfx_display = external hidden global ptr, align 8

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @gfx_event_waiting() #1 {
  %1 = alloca i32, align 4
  %2 = alloca %union._XEvent, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 192, ptr %2) #3
  call void @gfx_flush()
  br label %4

4:                                                ; preds = %0
  br label %5

5:                                                ; preds = %4
  %6 = load ptr, ptr @gfx_display, align 8, !tbaa !5
  %7 = call i32 @XCheckMaskEvent(ptr noundef %6, i64 noundef -1, ptr noundef %2)
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %22

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  %13 = load ptr, ptr @gfx_display, align 8, !tbaa !5
  %14 = call i32 @XPutBackEvent(ptr noundef %13, ptr noundef %2)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %23

15:                                               ; preds = %9
  %16 = load i32, ptr %2, align 8, !tbaa !9
  %17 = icmp eq i32 %16, 4
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load ptr, ptr @gfx_display, align 8, !tbaa !5
  %20 = call i32 @XPutBackEvent(ptr noundef %19, ptr noundef %2)
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %23

21:                                               ; preds = %15
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %23

22:                                               ; preds = %5
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %23

23:                                               ; preds = %22, %21, %18, %12
  call void @llvm.lifetime.end.p0(i64 192, ptr %2) #3
  %24 = load i32, ptr %1, align 4
  ret i32 %24
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @gfx_flush() #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!7, !7, i64 0}


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

%union._XEvent = type { [24 x i64] }

@gfx_display = external hidden local_unnamed_addr global ptr, align 8

; 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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @gfx_event_waiting() local_unnamed_addr #1 {
  %1 = alloca %union._XEvent, align 8
  call void @llvm.lifetime.start.p0(i64 192, ptr nonnull %1) #3
  tail call void @gfx_flush()
  %2 = load ptr, ptr @gfx_display, align 8, !tbaa !5
  %3 = call i32 @XCheckMaskEvent(ptr noundef %2, i64 noundef -1, ptr noundef nonnull %1) #3
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %8, label %4

4:                                                ; preds = %0
  %5 = load i32, ptr %1, align 8, !tbaa !9
  switch i32 %5, label %8 [
    i32 2, label %.sink.split
    i32 4, label %.sink.split
  ]

.sink.split:                                      ; preds = %4, %4
  %6 = load ptr, ptr @gfx_display, align 8, !tbaa !5
  %7 = call i32 @XPutBackEvent(ptr noundef %6, ptr noundef nonnull %1) #3
  br label %8

8:                                                ; preds = %.sink.split, %0, %4
  %.0 = phi i32 [ 0, %4 ], [ 0, %0 ], [ 1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 192, ptr nonnull %1) #3
  ret i32 %.0
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @gfx_flush() local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass