; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode/juce_gui_basics.ll (ZN4juce8KeyPress18isKeyCurrentlyDownEi)

; 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.juce::ScopedXLock" = type { i8 }

@_ZN4juce7displayE = external global ptr, align 8
@_ZN4juce4KeysL9keyStatesE = external hidden global [32 x i8], align 16

declare i32 @__gxx_personality_v0(...)

; 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 noundef zeroext i1 @_ZN4juce8KeyPress18isKeyCurrentlyDownEi(i32 noundef %0) #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %"class.juce::ScopedXLock", align 1
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %11 = load ptr, ptr @_ZN4juce7displayE, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %63

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = and i32 %15, 268435456
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %14
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = and i32 %19, 255
  %21 = or i32 65280, %20
  store i32 %21, ptr %4, align 4, !tbaa !5
  br label %39

22:                                               ; preds = %14
  %23 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %23, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 9
  br i1 %25, label %35, label %26

26:                                               ; preds = %22
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 13
  br i1 %28, label %35, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 27
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp eq i32 %33, 8
  br i1 %34, label %35, label %38

35:                                               ; preds = %32, %29, %26, %22
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = or i32 %36, 65280
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %35, %32
  br label %39

39:                                               ; preds = %38, %18
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  call void @_ZN4juce11ScopedXLockC1Ev(ptr noundef nonnull align 1 dereferenceable(1) %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %40 = load ptr, ptr @_ZN4juce7displayE, align 8, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = invoke zeroext i8 @XKeysymToKeycode(ptr noundef %40, i64 noundef %42)
          to label %44 unwind label %59

44:                                               ; preds = %39
  %45 = zext i8 %43 to i32
  store i32 %45, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = ashr i32 %46, 3
  store i32 %47, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = and i32 %48, 7
  %50 = shl i32 1, %49
  store i32 %50, ptr %10, align 4, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [32 x i8], ptr @_ZN4juce4KeysL9keyStatesE, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = and i32 %55, %56
  %58 = icmp ne i32 %57, 0
  store i1 %58, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @_ZN4juce11ScopedXLockD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %63

59:                                               ; preds = %39
  %60 = landingpad { ptr, i32 }
          cleanup
  %61 = extractvalue { ptr, i32 } %60, 0
  store ptr %61, ptr %7, align 8
  %62 = extractvalue { ptr, i32 } %60, 1
  store i32 %62, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @_ZN4juce11ScopedXLockD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %65

63:                                               ; preds = %44, %13
  %64 = load i1, ptr %2, align 1
  ret i1 %64

65:                                               ; preds = %59
  %66 = load ptr, ptr %7, align 8
  %67 = load i32, ptr %8, align 4
  %68 = insertvalue { ptr, i32 } poison, ptr %66, 0
  %69 = insertvalue { ptr, i32 } %68, i32 %67, 1
  resume { ptr, i32 } %69
}

declare void @_ZN4juce11ScopedXLockC1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #2

declare zeroext i8 @XKeysymToKeycode(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind
declare void @_ZN4juce11ScopedXLockD1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3

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 = { nounwind "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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!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"

%"class.juce::ScopedXLock" = type { i8 }

@_ZN4juce7displayE = external local_unnamed_addr global ptr, align 8
@_ZN4juce4KeysL9keyStatesE = external hidden local_unnamed_addr global [32 x i8], align 16

declare i32 @__gxx_personality_v0(...)

; 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 noundef zeroext i1 @_ZN4juce8KeyPress18isKeyCurrentlyDownEi(i32 noundef %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.juce::ScopedXLock", align 1
  %3 = load ptr, ptr @_ZN4juce7displayE, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %32, label %5

5:                                                ; preds = %1
  %6 = and i32 %0, 268435456
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %10, label %7

7:                                                ; preds = %5
  %8 = and i32 %0, 255
  %9 = or disjoint i32 %8, 65280
  br label %15

10:                                               ; preds = %5
  %11 = and i32 %0, -268435461
  %or.cond = icmp eq i32 %11, 9
  %12 = icmp eq i32 %0, 27
  %or.cond3 = or i1 %12, %or.cond
  %13 = icmp eq i32 %0, 8
  %or.cond5 = or i1 %13, %or.cond3
  %14 = or disjoint i32 %0, 65280
  %spec.select = select i1 %or.cond5, i32 %14, i32 %0
  br label %15

15:                                               ; preds = %10, %7
  %.020 = phi i32 [ %9, %7 ], [ %spec.select, %10 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #4
  call void @_ZN4juce11ScopedXLockC1Ev(ptr noundef nonnull align 1 dereferenceable(1) %2)
  %16 = load ptr, ptr @_ZN4juce7displayE, align 8, !tbaa !5
  %17 = sext i32 %.020 to i64
  %18 = invoke zeroext i8 @XKeysymToKeycode(ptr noundef %16, i64 noundef %17)
          to label %19 unwind label %30

19:                                               ; preds = %15
  %20 = zext i8 %18 to i32
  %21 = lshr i32 %20, 3
  %22 = and i32 %20, 7
  %23 = shl nuw nsw i32 1, %22
  %24 = zext nneg i32 %21 to i64
  %25 = getelementptr inbounds [32 x i8], ptr @_ZN4juce4KeysL9keyStatesE, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = and i32 %23, %27
  %29 = icmp ne i32 %28, 0
  call void @_ZN4juce11ScopedXLockD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %2) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  br label %32

30:                                               ; preds = %15
  %31 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN4juce11ScopedXLockD1Ev(ptr noundef nonnull align 1 dereferenceable(1) %2) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  resume { ptr, i32 } %31

32:                                               ; preds = %1, %19
  %.0 = phi i1 [ %29, %19 ], [ false, %1 ]
  ret i1 %.0
}

declare void @_ZN4juce11ScopedXLockC1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #2

declare zeroext i8 @XKeysymToKeycode(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare void @_ZN4juce11ScopedXLockD1Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #3

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 "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 = { 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 = !{!7, !7, i64 0}


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