; LLVM IR from jrouwe/JoltPhysics :: TestFramework/Input/Linux/KeyboardLinux.ll (ZN13KeyboardLinux4PollEv)

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

%class.KeyboardLinux = type <{ %class.Keyboard, ptr, [53 x i8], [3 x i8], %"class.JPH::StaticArray", %"class.JPH::StaticArray", i32, [4 x i8] }>
%class.Keyboard = type { ptr }
%"class.JPH::StaticArray" = type { i32, [128 x %"struct.JPH::StaticArray<EKey, 128>::Storage"] }
%"struct.JPH::StaticArray<EKey, 128>::Storage" = type { [4 x i8] }

; 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 @_ZN13KeyboardLinux4PollEv(ptr noundef nonnull align 8 dereferenceable(1108) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [32 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8
  %12 = getelementptr inbounds %class.KeyboardLinux, ptr %11, i32 0, i32 2
  %13 = getelementptr inbounds [53 x i8], ptr %12, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %13, i8 0, i64 53, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %14 = getelementptr inbounds %class.KeyboardLinux, ptr %11, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call noundef ptr @_ZNK22ApplicationWindowLinux10GetDisplayEv(ptr noundef nonnull align 8 dereferenceable(104) %15)
  store ptr %16, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #6
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 0
  %19 = call i32 @XQueryKeymap(ptr noundef %17, ptr noundef %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %63, %1
  %21 = load i32, ptr %5, align 4, !tbaa !14
  %22 = icmp slt i32 %21, 32
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %66

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %25 = load i32, ptr %5, align 4, !tbaa !14
  %26 = shl i32 %25, 3
  store i32 %26, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %27 = load i32, ptr %5, align 4, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !15
  %31 = zext i8 %30 to i32
  store i32 %31, ptr %7, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %55, %24
  %33 = load i32, ptr %7, align 4, !tbaa !14
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %62

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %36 = load i32, ptr %7, align 4, !tbaa !14
  %37 = call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %36)
  store i32 %37, ptr %8, align 4, !tbaa !14
  %38 = load i32, ptr %8, align 4, !tbaa !14
  %39 = load i32, ptr %6, align 4, !tbaa !14
  %40 = add i32 %39, %38
  store i32 %40, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !14
  %43 = trunc i32 %42 to i8
  %44 = call i64 @XkbKeycodeToKeysym(ptr noundef %41, i8 noundef zeroext %43, i32 noundef 0, i32 noundef 0)
  store i64 %44, ptr %9, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %45 = load i64, ptr %9, align 8, !tbaa !16
  %46 = trunc i64 %45 to i32
  %47 = call noundef i32 @_ZNK13KeyboardLinux5ToKeyEi(ptr noundef nonnull align 8 dereferenceable(1108) %11, i32 noundef %46)
  store i32 %47, ptr %10, align 4, !tbaa !18
  %48 = load i32, ptr %10, align 4, !tbaa !18
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %50, label %55

50:                                               ; preds = %35
  %51 = getelementptr inbounds %class.KeyboardLinux, ptr %11, i32 0, i32 2
  %52 = load i32, ptr %10, align 4, !tbaa !18
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [53 x i8], ptr %51, i64 0, i64 %53
  store i8 1, ptr %54, align 1, !tbaa !20
  br label %55

55:                                               ; preds = %50, %35
  %56 = load i32, ptr %6, align 4, !tbaa !14
  %57 = add i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !14
  %58 = load i32, ptr %8, align 4, !tbaa !14
  %59 = add i32 %58, 1
  %60 = load i32, ptr %7, align 4, !tbaa !14
  %61 = lshr i32 %60, %59
  store i32 %61, ptr %7, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %32, !llvm.loop !22

62:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %5, align 4, !tbaa !14
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !14
  br label %20, !llvm.loop !24

66:                                               ; preds = %23
  %67 = getelementptr inbounds %class.KeyboardLinux, ptr %11, i32 0, i32 4
  %68 = getelementptr inbounds %class.KeyboardLinux, ptr %11, i32 0, i32 5
  %69 = call noundef nonnull align 4 dereferenceable(516) ptr @_ZN3JPH11StaticArrayI4EKeyLj128EEaSERKS2_(ptr noundef nonnull align 4 dereferenceable(516) %68, ptr noundef nonnull align 4 dereferenceable(516) %67)
  %70 = getelementptr inbounds %class.KeyboardLinux, ptr %11, i32 0, i32 4
  call void @_ZN3JPH11StaticArrayI4EKeyLj128EE5clearEv(ptr noundef nonnull align 4 dereferenceable(516) %70)
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK22ApplicationWindowLinux10GetDisplayEv(ptr noundef nonnull align 8 dereferenceable(104)) #3 align 2

declare i32 @XQueryKeymap(ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef) #5

declare i64 @XkbKeycodeToKeysym(ptr noundef, i8 noundef zeroext, i32 noundef, i32 noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK13KeyboardLinux5ToKeyEi(ptr noundef nonnull align 8 dereferenceable(1108), i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(516) ptr @_ZN3JPH11StaticArrayI4EKeyLj128EEaSERKS2_(ptr noundef nonnull align 4 dereferenceable(516), ptr noundef nonnull align 4 dereferenceable(516)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH11StaticArrayI4EKeyLj128EE5clearEv(ptr noundef nonnull align 4 dereferenceable(516)) #3 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress 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 #4 = { "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 #5 = { inlinehint mustprogress 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 #6 = { 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 8}
!10 = !{!"_ZTS13KeyboardLinux", !11, i64 0, !6, i64 8, !7, i64 16, !12, i64 72, !12, i64 588, !13, i64 1104}
!11 = !{!"_ZTS8Keyboard"}
!12 = !{!"_ZTSN3JPH11StaticArrayI4EKeyLj128EEE", !13, i64 0, !7, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTS4EKey", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"bool", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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

; 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 @_ZN13KeyboardLinux4PollEv(ptr noundef nonnull align 8 dereferenceable(1108) %0) unnamed_addr #1 align 2 {
  %2 = alloca [32 x i8], align 16
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(53) %3, i8 0, i64 53, i1 false)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call noundef ptr @_ZNK22ApplicationWindowLinux10GetDisplayEv(ptr noundef nonnull align 8 dereferenceable(104) %5)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #6
  %7 = call i32 @XQueryKeymap(ptr noundef %6, ptr noundef nonnull %2)
  br label %12

8:                                                ; preds = %._crit_edge
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  %10 = getelementptr inbounds i8, ptr %0, i64 588
  %11 = call noundef nonnull align 4 dereferenceable(516) ptr @_ZN3JPH11StaticArrayI4EKeyLj128EEaSERKS2_(ptr noundef nonnull align 4 dereferenceable(516) %10, ptr noundef nonnull align 4 dereferenceable(516) %9)
  call void @_ZN3JPH11StaticArrayI4EKeyLj128EE5clearEv(ptr noundef nonnull align 4 dereferenceable(516) %9)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #6
  ret void

12:                                               ; preds = %1, %._crit_edge
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %._crit_edge ]
  %13 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 %indvars.iv
  %14 = load i8, ptr %13, align 1, !tbaa !13
  %.not21 = icmp eq i8 %14, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12
  %15 = zext i8 %14 to i32
  %indvars.iv.tr = trunc i64 %indvars.iv to i32
  %16 = shl i32 %indvars.iv.tr, 3
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %26
  %.01723 = phi i32 [ %27, %26 ], [ %16, %.lr.ph.preheader ]
  %.01822 = phi i32 [ %29, %26 ], [ %15, %.lr.ph.preheader ]
  %17 = call noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef %.01822)
  %18 = add i32 %17, %.01723
  %19 = trunc i32 %18 to i8
  %20 = call i64 @XkbKeycodeToKeysym(ptr noundef %6, i8 noundef zeroext %19, i32 noundef 0, i32 noundef 0)
  %21 = trunc i64 %20 to i32
  %22 = call noundef i32 @_ZNK13KeyboardLinux5ToKeyEi(ptr noundef nonnull align 8 dereferenceable(1108) %0, i32 noundef %21)
  %.not20 = icmp eq i32 %22, 1
  br i1 %.not20, label %26, label %23

23:                                               ; preds = %.lr.ph
  %24 = sext i32 %22 to i64
  %25 = getelementptr inbounds [53 x i8], ptr %3, i64 0, i64 %24
  store i8 1, ptr %25, align 1, !tbaa !14
  br label %26

26:                                               ; preds = %23, %.lr.ph
  %27 = add i32 %18, 1
  %28 = add i32 %17, 1
  %29 = lshr i32 %.01822, %28
  %.not = icmp eq i32 %29, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %26, %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 32
  br i1 %exitcond.not, label %8, label %12, !llvm.loop !18
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK22ApplicationWindowLinux10GetDisplayEv(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #3 align 2

declare i32 @XQueryKeymap(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3JPH18CountTrailingZerosEj(i32 noundef) local_unnamed_addr #5

declare i64 @XkbKeycodeToKeysym(ptr noundef, i8 noundef zeroext, i32 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK13KeyboardLinux5ToKeyEi(ptr noundef nonnull align 8 dereferenceable(1108), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(516) ptr @_ZN3JPH11StaticArrayI4EKeyLj128EEaSERKS2_(ptr noundef nonnull align 4 dereferenceable(516), ptr noundef nonnull align 4 dereferenceable(516)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH11StaticArrayI4EKeyLj128EE5clearEv(ptr noundef nonnull align 4 dereferenceable(516)) local_unnamed_addr #3 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress 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 #4 = { "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 #5 = { inlinehint mustprogress 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 #6 = { 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, !8, i64 8}
!6 = !{!"_ZTS13KeyboardLinux", !7, i64 0, !8, i64 8, !9, i64 16, !11, i64 72, !11, i64 588, !12, i64 1104}
!7 = !{!"_ZTS8Keyboard"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN3JPH11StaticArrayI4EKeyLj128EEE", !12, i64 0, !9, i64 4}
!12 = !{!"int", !9, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !9, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass