; LLVM IR from chiraqL/Engine3D :: src/imgui/imgui_impl_glfw.ll (Z26ImGui_ImplGlfw_KeyCallbackP10GLFWwindowiiii)

; 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.ImGuiIO = type { i32, i32, %struct.ImVec2, float, float, ptr, ptr, float, float, float, [22 x i32], float, float, ptr, ptr, float, i8, ptr, %struct.ImVec2, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.ImVec2, [5 x i8], float, float, i32, i8, i8, i8, i8, [512 x i8], [21 x float], i8, i8, i8, i8, i8, i8, i8, float, i32, i32, i32, i32, i32, %struct.ImVec2, i32, %struct.ImVec2, [5 x %struct.ImVec2], [5 x double], [5 x i8], [5 x i8], [5 x i8], [5 x i8], [5 x i8], [5 x float], [5 x float], [5 x %struct.ImVec2], [5 x float], [512 x float], [512 x float], [21 x float], [21 x float], float, i16, %struct.ImVector }
%struct.ImVec2 = type { float, float }
%struct.ImVector = type { i32, i32, ptr }

@_ZL8g_Window = external hidden global ptr, align 8
@_ZL21g_PrevUserCallbackKey = external hidden global ptr, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare noundef nonnull align 8 dereferenceable(5456) ptr @_ZN5ImGui5GetIOEv() #1

; 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 @_Z26ImGui_ImplGlfw_KeyCallbackP10GLFWwindowiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr @_ZL21g_PrevUserCallbackKey, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %25

14:                                               ; preds = %5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr @_ZL8g_Window, align 8, !tbaa !5
  %17 = icmp eq ptr %15, %16
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = load ptr, ptr @_ZL21g_PrevUserCallbackKey, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  call void %19(ptr noundef %20, i32 noundef %21, i32 noundef %22, i32 noundef %23, i32 noundef %24)
  br label %25

25:                                               ; preds = %18, %14, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %26 = call noundef nonnull align 8 dereferenceable(5456) ptr @_ZN5ImGui5GetIOEv()
  store ptr %26, ptr %11, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %35

29:                                               ; preds = %25
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ImGuiIO, ptr %30, i32 0, i32 51
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [512 x i8], ptr %31, i64 0, i64 %33
  store i8 1, ptr %34, align 1, !tbaa !11
  br label %35

35:                                               ; preds = %29, %25
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %35
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ImGuiIO, ptr %39, i32 0, i32 51
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [512 x i8], ptr %40, i64 0, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !11
  br label %44

44:                                               ; preds = %38, %35
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ImGuiIO, ptr %45, i32 0, i32 51
  %47 = getelementptr inbounds [512 x i8], ptr %46, i64 0, i64 341
  %48 = load i8, ptr %47, align 1, !tbaa !11, !range !13, !noundef !14
  %49 = trunc i8 %48 to i1
  br i1 %49, label %56, label %50

50:                                               ; preds = %44
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ImGuiIO, ptr %51, i32 0, i32 51
  %53 = getelementptr inbounds [512 x i8], ptr %52, i64 0, i64 345
  %54 = load i8, ptr %53, align 1, !tbaa !11, !range !13, !noundef !14
  %55 = trunc i8 %54 to i1
  br label %56

56:                                               ; preds = %50, %44
  %57 = phi i1 [ true, %44 ], [ %55, %50 ]
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ImGuiIO, ptr %58, i32 0, i32 47
  %60 = zext i1 %57 to i8
  store i8 %60, ptr %59, align 4, !tbaa !15
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.ImGuiIO, ptr %61, i32 0, i32 51
  %63 = getelementptr inbounds [512 x i8], ptr %62, i64 0, i64 340
  %64 = load i8, ptr %63, align 4, !tbaa !11, !range !13, !noundef !14
  %65 = trunc i8 %64 to i1
  br i1 %65, label %72, label %66

66:                                               ; preds = %56
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ImGuiIO, ptr %67, i32 0, i32 51
  %69 = getelementptr inbounds [512 x i8], ptr %68, i64 0, i64 344
  %70 = load i8, ptr %69, align 8, !tbaa !11, !range !13, !noundef !14
  %71 = trunc i8 %70 to i1
  br label %72

72:                                               ; preds = %66, %56
  %73 = phi i1 [ true, %56 ], [ %71, %66 ]
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ImGuiIO, ptr %74, i32 0, i32 48
  %76 = zext i1 %73 to i8
  store i8 %76, ptr %75, align 1, !tbaa !21
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ImGuiIO, ptr %77, i32 0, i32 51
  %79 = getelementptr inbounds [512 x i8], ptr %78, i64 0, i64 342
  %80 = load i8, ptr %79, align 2, !tbaa !11, !range !13, !noundef !14
  %81 = trunc i8 %80 to i1
  br i1 %81, label %88, label %82

82:                                               ; preds = %72
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.ImGuiIO, ptr %83, i32 0, i32 51
  %85 = getelementptr inbounds [512 x i8], ptr %84, i64 0, i64 346
  %86 = load i8, ptr %85, align 2, !tbaa !11, !range !13, !noundef !14
  %87 = trunc i8 %86 to i1
  br label %88

88:                                               ; preds = %82, %72
  %89 = phi i1 [ true, %72 ], [ %87, %82 ]
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.ImGuiIO, ptr %90, i32 0, i32 49
  %92 = zext i1 %89 to i8
  store i8 %92, ptr %91, align 2, !tbaa !22
  %93 = load ptr, ptr %11, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ImGuiIO, ptr %93, i32 0, i32 51
  %95 = getelementptr inbounds [512 x i8], ptr %94, i64 0, i64 343
  %96 = load i8, ptr %95, align 1, !tbaa !11, !range !13, !noundef !14
  %97 = trunc i8 %96 to i1
  br i1 %97, label %104, label %98

98:                                               ; preds = %88
  %99 = load ptr, ptr %11, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.ImGuiIO, ptr %99, i32 0, i32 51
  %101 = getelementptr inbounds [512 x i8], ptr %100, i64 0, i64 347
  %102 = load i8, ptr %101, align 1, !tbaa !11, !range !13, !noundef !14
  %103 = trunc i8 %102 to i1
  br label %104

104:                                              ; preds = %98, %88
  %105 = phi i1 [ true, %88 ], [ %103, %98 ]
  %106 = load ptr, ptr %11, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.ImGuiIO, ptr %106, i32 0, i32 50
  %108 = zext i1 %105 to i8
  store i8 %108, ptr %107, align 1, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !12, i64 308}
!16 = !{!"_ZTS7ImGuiIO", !10, i64 0, !10, i64 4, !17, i64 8, !18, i64 16, !18, i64 20, !6, i64 24, !6, i64 32, !18, i64 40, !18, i64 44, !18, i64 48, !7, i64 52, !18, i64 140, !18, i64 144, !6, i64 152, !6, i64 160, !18, i64 168, !12, i64 172, !6, i64 176, !17, i64 184, !12, i64 192, !12, i64 193, !12, i64 194, !12, i64 195, !12, i64 196, !12, i64 197, !12, i64 198, !12, i64 199, !12, i64 200, !12, i64 201, !12, i64 202, !12, i64 203, !12, i64 204, !12, i64 205, !18, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !17, i64 280, !7, i64 288, !18, i64 296, !18, i64 300, !10, i64 304, !12, i64 308, !12, i64 309, !12, i64 310, !12, i64 311, !7, i64 312, !7, i64 824, !12, i64 908, !12, i64 909, !12, i64 910, !12, i64 911, !12, i64 912, !12, i64 913, !12, i64 914, !18, i64 916, !10, i64 920, !10, i64 924, !10, i64 928, !10, i64 932, !10, i64 936, !17, i64 940, !10, i64 948, !17, i64 952, !7, i64 960, !7, i64 1000, !7, i64 1040, !7, i64 1045, !7, i64 1050, !7, i64 1055, !7, i64 1060, !7, i64 1068, !7, i64 1088, !7, i64 1108, !7, i64 1148, !7, i64 1168, !7, i64 3216, !7, i64 5264, !7, i64 5348, !18, i64 5432, !19, i64 5436, !20, i64 5440}
!17 = !{!"_ZTS6ImVec2", !18, i64 0, !18, i64 4}
!18 = !{!"float", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!"_ZTS8ImVectorItE", !10, i64 0, !10, i64 4, !6, i64 8}
!21 = !{!16, !12, i64 309}
!22 = !{!16, !12, i64 310}
!23 = !{!16, !12, i64 311}


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

@_ZL8g_Window = external hidden local_unnamed_addr global ptr, align 8
@_ZL21g_PrevUserCallbackKey = external hidden local_unnamed_addr global ptr, align 8

declare noundef nonnull align 8 dereferenceable(5456) ptr @_ZN5ImGui5GetIOEv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z26ImGui_ImplGlfw_KeyCallbackP10GLFWwindowiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = load ptr, ptr @_ZL21g_PrevUserCallbackKey, align 8, !tbaa !5
  %.not = icmp ne ptr %6, null
  %7 = load ptr, ptr @_ZL8g_Window, align 8
  %8 = icmp eq ptr %7, %0
  %or.cond = select i1 %.not, i1 %8, i1 false
  br i1 %or.cond, label %9, label %10

9:                                                ; preds = %5
  tail call void %6(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %10

10:                                               ; preds = %9, %5
  %11 = tail call noundef nonnull align 8 dereferenceable(5456) ptr @_ZN5ImGui5GetIOEv()
  switch i32 %3, label %16 [
    i32 1, label %.sink.split
    i32 0, label %12
  ]

12:                                               ; preds = %10
  br label %.sink.split

.sink.split:                                      ; preds = %10, %12
  %.sink = phi i8 [ 0, %12 ], [ 1, %10 ]
  %13 = getelementptr inbounds i8, ptr %11, i64 312
  %14 = sext i32 %1 to i64
  %15 = getelementptr inbounds [512 x i8], ptr %13, i64 0, i64 %14
  store i8 %.sink, ptr %15, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %.sink.split, %10
  %17 = getelementptr inbounds i8, ptr %11, i64 308
  %18 = getelementptr inbounds i8, ptr %11, i64 652
  %19 = getelementptr inbounds i8, ptr %11, i64 656
  %20 = load <4 x i8>, ptr %18, align 4, !tbaa !9
  %21 = trunc <4 x i8> %20 to <4 x i1>
  %22 = load <4 x i8>, ptr %19, align 8
  %23 = select <4 x i1> %21, <4 x i8> <i8 1, i8 1, i8 1, i8 1>, <4 x i8> %22
  %24 = shufflevector <4 x i8> %23, <4 x i8> poison, <4 x i32> <i32 1, i32 0, i32 2, i32 3>
  store <4 x i8> %24, ptr %17, align 4, !tbaa !9
  ret void
}

attributes #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 #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" }

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


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