; LLVM IR from danginsburg/opengles3-book :: Common/Source/LinuxX11 (esUtil_X11)

; 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] }
%struct.ESContext = type { ptr, ptr, i32, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.XClientMessageEvent = type { i32, i64, i32, ptr, i64, i64, i32, %union.anon }
%union.anon = type { [5 x i64] }

@x_display = external hidden global ptr, align 8
@s_wmDeleteMessage = external hidden global i64, 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 zeroext i8 @userInterrupt(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %union._XEvent, align 8
  %4 = alloca i64, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 192, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  br label %7

7:                                                ; preds = %47, %1
  %8 = load ptr, ptr @x_display, align 8, !tbaa !5
  %9 = call i32 @XPending(ptr noundef %8)
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %48

11:                                               ; preds = %7
  %12 = load ptr, ptr @x_display, align 8, !tbaa !5
  %13 = call i32 @XNextEvent(ptr noundef %12, ptr noundef %3)
  %14 = load i32, ptr %3, align 8, !tbaa !9
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %16, label %32

16:                                               ; preds = %11
  %17 = call i32 @XLookupString(ptr noundef %3, ptr noundef %6, i32 noundef 1, ptr noundef %4, ptr noundef null)
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %31

19:                                               ; preds = %16
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ESContext, ptr %20, i32 0, i32 11
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %30

24:                                               ; preds = %19
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ESContext, ptr %25, i32 0, i32 11
  %27 = load ptr, ptr %26, align 8, !tbaa !10
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = load i8, ptr %6, align 1, !tbaa !9
  call void %27(ptr noundef %28, i8 noundef zeroext %29, i32 noundef 0, i32 noundef 0)
  br label %30

30:                                               ; preds = %24, %19
  br label %31

31:                                               ; preds = %30, %16
  br label %32

32:                                               ; preds = %31, %11
  %33 = load i32, ptr %3, align 8, !tbaa !9
  %34 = icmp eq i32 %33, 33
  br i1 %34, label %35, label %43

35:                                               ; preds = %32
  %36 = getelementptr inbounds %struct.XClientMessageEvent, ptr %3, i32 0, i32 7
  %37 = getelementptr inbounds [5 x i64], ptr %36, i64 0, i64 0
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load i64, ptr @s_wmDeleteMessage, align 8, !tbaa !14
  %40 = icmp eq i64 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store i8 1, ptr %5, align 1, !tbaa !9
  br label %42

42:                                               ; preds = %41, %35
  br label %43

43:                                               ; preds = %42, %32
  %44 = load i32, ptr %3, align 8, !tbaa !9
  %45 = icmp eq i32 %44, 17
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store i8 1, ptr %5, align 1, !tbaa !9
  br label %47

47:                                               ; preds = %46, %43
  br label %7, !llvm.loop !15

48:                                               ; preds = %7
  %49 = load i8, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 192, ptr %3) #3
  ret i8 %49
}

declare i32 @XPending(ptr noundef) #2

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

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

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}
!10 = !{!11, !6, i64 80}
!11 = !{!"ESContext", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !13, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@x_display = external hidden local_unnamed_addr global ptr, align 8
@s_wmDeleteMessage = external hidden local_unnamed_addr global i64, 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 zeroext range(i8 0, 2) i8 @userInterrupt(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %union._XEvent, align 8
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 192, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %5 = load ptr, ptr @x_display, align 8, !tbaa !5
  %6 = tail call i32 @XPending(ptr noundef %5) #3
  %.not6 = icmp eq i32 %6, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = getelementptr inbounds i8, ptr %2, i64 56
  br label %9

9:                                                ; preds = %.lr.ph, %21
  %.07 = phi i8 [ 0, %.lr.ph ], [ %spec.select5, %21 ]
  %10 = load ptr, ptr @x_display, align 8, !tbaa !5
  %11 = call i32 @XNextEvent(ptr noundef %10, ptr noundef nonnull %2) #3
  %12 = load i32, ptr %2, align 8, !tbaa !9
  %13 = icmp eq i32 %12, 2
  br i1 %13, label %14, label %21

14:                                               ; preds = %9
  %15 = call i32 @XLookupString(ptr noundef nonnull %2, ptr noundef nonnull %4, i32 noundef 1, ptr noundef nonnull %3, ptr noundef null) #3
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !10
  %.not4 = icmp eq ptr %18, null
  br i1 %.not4, label %21, label %19

19:                                               ; preds = %17
  %20 = load i8, ptr %4, align 1, !tbaa !9
  call void %18(ptr noundef nonnull %0, i8 noundef zeroext %20, i32 noundef 0, i32 noundef 0) #3
  br label %21

21:                                               ; preds = %14, %19, %17, %9
  %22 = load i32, ptr %2, align 8, !tbaa !9
  %23 = icmp eq i32 %22, 33
  %24 = load i64, ptr %8, align 8
  %25 = load i64, ptr @s_wmDeleteMessage, align 8
  %26 = icmp eq i64 %24, %25
  %27 = select i1 %23, i1 %26, i1 false
  %28 = icmp eq i32 %22, 17
  %29 = select i1 %28, i1 true, i1 %27
  %spec.select5 = select i1 %29, i8 1, i8 %.07
  %30 = load ptr, ptr @x_display, align 8, !tbaa !5
  %31 = call i32 @XPending(ptr noundef %30) #3
  %.not = icmp eq i32 %31, 0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !14

._crit_edge:                                      ; preds = %21, %1
  %.0.lcssa = phi i8 [ 0, %1 ], [ %spec.select5, %21 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 192, ptr nonnull %2) #3
  ret i8 %.0.lcssa
}

declare i32 @XPending(ptr noundef) local_unnamed_addr #2

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

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

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}
!10 = !{!11, !6, i64 80}
!11 = !{!"ESContext", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !13, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass