; LLVM IR from jrouwe/JoltPhysics :: TestFramework/Window (ApplicationWindowLinux)

; 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.XConfigureEvent = type { i32, i64, i32, ptr, i64, i64, i32, i32, i32, i32, i32, i64, i32 }
%class.ApplicationWindowLinux = type { %class.ApplicationWindow, ptr, i64, i64, %"class.std::function.0" }
%class.ApplicationWindow = type { ptr, i32, i32, %"class.std::function" }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }
%"class.std::function.0" = type { %"class.std::_Function_base", ptr }
%struct.XClientMessageEvent = type { i32, i64, i32, ptr, i64, i64, i32, %union.anon }
%union.anon = type { [5 x i64] }

; 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: mustprogress uwtable
define dso_local void @_ZN22ApplicationWindowLinux8MainLoopESt8functionIFbvEE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %union._XEvent, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.XConfigureEvent, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  br label %9

9:                                                ; preds = %60, %2
  br label %10

10:                                               ; preds = %56, %9
  %11 = getelementptr inbounds %class.ApplicationWindowLinux, ptr %8, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call i32 @XPending(ptr noundef %12)
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %57

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 192, ptr %5) #4
  %16 = getelementptr inbounds %class.ApplicationWindowLinux, ptr %8, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call i32 @XNextEvent(ptr noundef %17, ptr noundef %5)
  %19 = load i32, ptr %5, align 8, !tbaa !17
  %20 = icmp eq i32 %19, 33
  br i1 %20, label %21, label %29

21:                                               ; preds = %15
  %22 = getelementptr inbounds %struct.XClientMessageEvent, ptr %5, i32 0, i32 7
  %23 = getelementptr inbounds [5 x i64], ptr %22, i64 0, i64 0
  %24 = load i64, ptr %23, align 8, !tbaa !17
  %25 = getelementptr inbounds %class.ApplicationWindowLinux, ptr %8, i32 0, i32 3
  %26 = load i64, ptr %25, align 8, !tbaa !18
  %27 = icmp eq i64 %24, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %21
  store i32 1, ptr %6, align 4
  br label %54

29:                                               ; preds = %21, %15
  %30 = load i32, ptr %5, align 8, !tbaa !17
  %31 = icmp eq i32 %30, 22
  br i1 %31, label %32, label %50

32:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 88, ptr %7) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %5, i64 88, i1 false), !tbaa.struct !19
  %33 = getelementptr inbounds %struct.XConfigureEvent, ptr %7, i32 0, i32 8
  %34 = load i32, ptr %33, align 8, !tbaa !22
  %35 = getelementptr inbounds %class.ApplicationWindow, ptr %8, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !24
  %37 = icmp ne i32 %34, %36
  br i1 %37, label %44, label %38

38:                                               ; preds = %32
  %39 = getelementptr inbounds %struct.XConfigureEvent, ptr %7, i32 0, i32 9
  %40 = load i32, ptr %39, align 4, !tbaa !25
  %41 = getelementptr inbounds %class.ApplicationWindow, ptr %8, i32 0, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !26
  %43 = icmp ne i32 %40, %42
  br i1 %43, label %44, label %49

44:                                               ; preds = %38, %32
  %45 = getelementptr inbounds %struct.XConfigureEvent, ptr %7, i32 0, i32 8
  %46 = load i32, ptr %45, align 8, !tbaa !22
  %47 = getelementptr inbounds %struct.XConfigureEvent, ptr %7, i32 0, i32 9
  %48 = load i32, ptr %47, align 4, !tbaa !25
  call void @_ZN17ApplicationWindow15OnWindowResizedEii(ptr noundef nonnull align 8 dereferenceable(48) %8, i32 noundef %46, i32 noundef %48)
  br label %49

49:                                               ; preds = %44, %38
  call void @llvm.lifetime.end.p0(i64 88, ptr %7) #4
  br label %52

50:                                               ; preds = %29
  %51 = getelementptr inbounds %class.ApplicationWindowLinux, ptr %8, i32 0, i32 4
  call void @_ZNKSt8functionIFvRK7_XEventEEclES2_(ptr noundef nonnull align 8 dereferenceable(32) %51, ptr noundef nonnull align 8 dereferenceable(192) %5)
  br label %52

52:                                               ; preds = %50, %49
  br label %53

53:                                               ; preds = %52
  store i32 0, ptr %6, align 4
  br label %54

54:                                               ; preds = %53, %28
  call void @llvm.lifetime.end.p0(i64 192, ptr %5) #4
  %55 = load i32, ptr %6, align 4
  switch i32 %55, label %62 [
    i32 0, label %56
    i32 1, label %61
  ]

56:                                               ; preds = %54
  br label %10, !llvm.loop !27

57:                                               ; preds = %10
  %58 = call noundef zeroext i1 @_ZNKSt8functionIFbvEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  br i1 %58, label %60, label %59

59:                                               ; preds = %57
  br label %61

60:                                               ; preds = %57
  br label %9, !llvm.loop !29

61:                                               ; preds = %59, %54
  ret void

62:                                               ; preds = %54
  unreachable
}

declare i32 @XPending(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17ApplicationWindow15OnWindowResizedEii(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFvRK7_XEventEEclES2_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(192)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNKSt8functionIFbvEEclEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !6, i64 48}
!10 = !{!"_ZTS22ApplicationWindowLinux", !11, i64 0, !6, i64 48, !15, i64 56, !15, i64 64, !16, i64 72}
!11 = !{!"_ZTS17ApplicationWindow", !12, i64 8, !12, i64 12, !13, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSSt8functionIFvvEE", !14, i64 0, !6, i64 24}
!14 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSSt8functionIFvRK7_XEventEE", !14, i64 0, !6, i64 24}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !15, i64 64}
!19 = !{i64 0, i64 4, !20, i64 8, i64 8, !21, i64 16, i64 4, !20, i64 24, i64 8, !5, i64 32, i64 8, !21, i64 40, i64 8, !21, i64 48, i64 4, !20, i64 52, i64 4, !20, i64 56, i64 4, !20, i64 60, i64 4, !20, i64 64, i64 4, !20, i64 72, i64 8, !21, i64 80, i64 4, !20}
!20 = !{!12, !12, i64 0}
!21 = !{!15, !15, i64 0}
!22 = !{!23, !12, i64 56}
!23 = !{!"_ZTS15XConfigureEvent", !12, i64 0, !15, i64 8, !12, i64 16, !6, i64 24, !15, i64 32, !15, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !15, i64 72, !12, i64 80}
!24 = !{!11, !12, i64 8}
!25 = !{!23, !12, i64 60}
!26 = !{!11, !12, i64 12}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = distinct !{!29, !28}


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

; 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: mustprogress uwtable
define dso_local void @_ZN22ApplicationWindowLinux8MainLoopESt8functionIFbvEE(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca %union._XEvent, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 56
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 60
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  br label %9

9:                                                ; preds = %._crit_edge, %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i32 @XPending(ptr noundef %10)
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %24
  call void @llvm.lifetime.start.p0(i64 192, ptr nonnull %3) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @XNextEvent(ptr noundef %13, ptr noundef nonnull %3)
  %15 = load i32, ptr %3, align 8, !tbaa !16
  switch i32 %15, label %.thread [
    i32 33, label %16
    i32 22, label %20
  ]

16:                                               ; preds = %.lr.ph
  %17 = load i64, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !16
  %18 = load i64, ptr %7, align 8, !tbaa !17
  %19 = icmp eq i64 %17, %18
  br i1 %19, label %.thread5, label %.thread

.thread5:                                         ; preds = %16
  call void @llvm.lifetime.end.p0(i64 192, ptr nonnull %3) #3
  br label %.loopexit

20:                                               ; preds = %.lr.ph
  %.sroa.3.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !18
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !18
  %21 = load i32, ptr %5, align 8, !tbaa !19
  %.not = icmp eq i32 %.sroa.3.0.copyload, %21
  %22 = load i32, ptr %6, align 4
  %.not3 = icmp eq i32 %.sroa.5.0.copyload, %22
  %or.cond = select i1 %.not, i1 %.not3, i1 false
  br i1 %or.cond, label %24, label %23

23:                                               ; preds = %20
  call void @_ZN17ApplicationWindow15OnWindowResizedEii(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %.sroa.3.0.copyload, i32 noundef %.sroa.5.0.copyload)
  br label %24

.thread:                                          ; preds = %.lr.ph, %16
  call void @_ZNKSt8functionIFvRK7_XEventEEclES2_(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(192) %3)
  br label %24

24:                                               ; preds = %.thread, %20, %23
  call void @llvm.lifetime.end.p0(i64 192, ptr nonnull %3) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call i32 @XPending(ptr noundef %25)
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %24, %9
  %28 = call noundef zeroext i1 @_ZNKSt8functionIFbvEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  br i1 %28, label %9, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %._crit_edge, %.thread5
  ret void
}

declare i32 @XPending(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17ApplicationWindow15OnWindowResizedEii(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFvRK7_XEventEEclES2_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNKSt8functionIFbvEEclEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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, !13, i64 48}
!6 = !{!"_ZTS22ApplicationWindowLinux", !7, i64 0, !13, i64 48, !14, i64 56, !14, i64 64, !15, i64 72}
!7 = !{!"_ZTS17ApplicationWindow", !8, i64 8, !8, i64 12, !11, i64 16}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSSt8functionIFvvEE", !12, i64 0, !13, i64 24}
!12 = !{!"_ZTSSt14_Function_base", !9, i64 0, !13, i64 16}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"long", !9, i64 0}
!15 = !{!"_ZTSSt8functionIFvRK7_XEventEE", !12, i64 0, !13, i64 24}
!16 = !{!9, !9, i64 0}
!17 = !{!6, !14, i64 64}
!18 = !{!8, !8, i64 0}
!19 = !{!7, !8, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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