; LLVM IR from l1mey112/yr11-physics-applied :: cimgui/imgui/imgui.ll (ZN5ImGui11SetKeyOwnerE8ImGuiKeyji)

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

%struct.ImGuiKeyOwnerData = type <{ i32, i32, i8, i8, [2 x i8] }>

@.str.4 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.180 = external hidden unnamed_addr constant [134 x i8], align 1
@__PRETTY_FUNCTION__._ZN5ImGui11SetKeyOwnerE8ImGuiKeyji = external hidden unnamed_addr constant [60 x i8], align 1
@.str.181 = external hidden unnamed_addr constant [55 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN5ImGui18IsNamedKeyOrModKeyE8ImGuiKey(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5ImGui11SetKeyOwnerE8ImGuiKeyji(i32 noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = call noundef zeroext i1 @_ZN5ImGui18IsNamedKeyOrModKeyE8ImGuiKey(i32 noundef %8)
  br i1 %9, label %10, label %19

10:                                               ; preds = %3
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %17, label %13

13:                                               ; preds = %10
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = and i32 %14, 192
  %16 = icmp ne i32 %15, 0
  br label %17

17:                                               ; preds = %13, %10
  %18 = phi i1 [ true, %10 ], [ %16, %13 ]
  br label %19

19:                                               ; preds = %17, %3
  %20 = phi i1 [ false, %3 ], [ %18, %17 ]
  br i1 %20, label %21, label %22

21:                                               ; preds = %19
  br label %24

22:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.180, ptr noundef @.str.4, i32 noundef 8745, ptr noundef @__PRETTY_FUNCTION__._ZN5ImGui11SetKeyOwnerE8ImGuiKeyji) #4
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = and i32 %25, -193
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  br label %31

29:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.181, ptr noundef @.str.4, i32 noundef 8746, ptr noundef @__PRETTY_FUNCTION__._ZN5ImGui11SetKeyOwnerE8ImGuiKeyji) #4
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = call noundef ptr @_ZN5ImGui15GetKeyOwnerDataE8ImGuiKey(i32 noundef %32)
  store ptr %33, ptr %7, align 8, !tbaa !11
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.ImGuiKeyOwnerData, ptr %35, i32 0, i32 1
  store i32 %34, ptr %36, align 4, !tbaa !13
  %37 = load ptr, ptr %7, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.ImGuiKeyOwnerData, ptr %37, i32 0, i32 0
  store i32 %34, ptr %38, align 4, !tbaa !16
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = and i32 %39, 128
  %41 = icmp ne i32 %40, 0
  %42 = load ptr, ptr %7, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.ImGuiKeyOwnerData, ptr %42, i32 0, i32 3
  %44 = zext i1 %41 to i8
  store i8 %44, ptr %43, align 1, !tbaa !17
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = and i32 %45, 64
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %53, label %48

48:                                               ; preds = %31
  %49 = load ptr, ptr %7, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.ImGuiKeyOwnerData, ptr %49, i32 0, i32 3
  %51 = load i8, ptr %50, align 1, !tbaa !17, !range !18, !noundef !19
  %52 = trunc i8 %51 to i1
  br label %53

53:                                               ; preds = %48, %31
  %54 = phi i1 [ true, %31 ], [ %52, %48 ]
  %55 = load ptr, ptr %7, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.ImGuiKeyOwnerData, ptr %55, i32 0, i32 2
  %57 = zext i1 %54 to i8
  store i8 %57, ptr %56, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5ImGui15GetKeyOwnerDataE8ImGuiKey(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #3 = { 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!"_ZTS8ImGuiKey", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 4}
!14 = !{!"_ZTS17ImGuiKeyOwnerData", !10, i64 0, !10, i64 4, !15, i64 8, !15, i64 9}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !10, i64 0}
!17 = !{!14, !15, i64 9}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!14, !15, i64 8}


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

@.str.4 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.180 = external hidden unnamed_addr constant [134 x i8], align 1
@__PRETTY_FUNCTION__._ZN5ImGui11SetKeyOwnerE8ImGuiKeyji = external hidden unnamed_addr constant [60 x i8], align 1
@.str.181 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN5ImGui18IsNamedKeyOrModKeyE8ImGuiKey(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5ImGui11SetKeyOwnerE8ImGuiKeyji(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = tail call noundef zeroext i1 @_ZN5ImGui18IsNamedKeyOrModKeyE8ImGuiKey(i32 noundef %0)
  br i1 %4, label %5, label %.critedge

5:                                                ; preds = %3
  %6 = and i32 %2, 192
  %7 = or i32 %6, %1
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.critedge, label %8

.critedge:                                        ; preds = %3, %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.180, ptr noundef nonnull @.str.4, i32 noundef 8745, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5ImGui11SetKeyOwnerE8ImGuiKeyji) #3
  unreachable

8:                                                ; preds = %5
  %9 = and i32 %2, -193
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  tail call void @__assert_fail(ptr noundef nonnull @.str.181, ptr noundef nonnull @.str.4, i32 noundef 8746, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5ImGui11SetKeyOwnerE8ImGuiKeyji) #3
  unreachable

12:                                               ; preds = %8
  %13 = tail call noundef ptr @_ZN5ImGui15GetKeyOwnerDataE8ImGuiKey(i32 noundef %0)
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  store i32 %1, ptr %14, align 4, !tbaa !5
  store i32 %1, ptr %13, align 4, !tbaa !11
  %15 = icmp ugt i32 %2, 127
  %16 = getelementptr inbounds i8, ptr %13, i64 9
  %17 = zext i1 %15 to i8
  store i8 %17, ptr %16, align 1, !tbaa !12
  %18 = and i32 %2, 64
  %.not12 = icmp eq i32 %18, 0
  %spec.select = select i1 %.not12, i8 %17, i8 1
  %19 = getelementptr inbounds i8, ptr %13, i64 8
  store i8 %spec.select, ptr %19, align 4, !tbaa !13
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5ImGui15GetKeyOwnerDataE8ImGuiKey(i32 noundef) local_unnamed_addr #1

attributes #0 = { noreturn 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 #1 = { 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 #2 = { 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 #3 = { noreturn 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, !7, i64 4}
!6 = !{!"_ZTS17ImGuiKeyOwnerData", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 9}
!13 = !{!6, !10, i64 8}


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