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

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

@_ZL29g_PrevUserCallbackMousebutton = external hidden global ptr, align 8
@_ZL8g_Window = external hidden global ptr, align 8
@_ZL18g_MouseJustPressed = external hidden global [5 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z34ImGui_ImplGlfw_MouseButtonCallbackP10GLFWwindowiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %9 = load ptr, ptr @_ZL29g_PrevUserCallbackMousebutton, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %21

11:                                               ; preds = %4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr @_ZL8g_Window, align 8, !tbaa !5
  %14 = icmp eq ptr %12, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %11
  %16 = load ptr, ptr @_ZL29g_PrevUserCallbackMousebutton, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  call void %16(ptr noundef %17, i32 noundef %18, i32 noundef %19, i32 noundef %20)
  br label %21

21:                                               ; preds = %15, %11, %4
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %34

24:                                               ; preds = %21
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 5
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [5 x i8], ptr @_ZL18g_MouseJustPressed, i64 0, i64 %32
  store i8 1, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %30, %27, %24, %21
  ret void
}

attributes #0 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !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"

@_ZL29g_PrevUserCallbackMousebutton = external hidden local_unnamed_addr global ptr, align 8
@_ZL8g_Window = external hidden local_unnamed_addr global ptr, align 8
@_ZL18g_MouseJustPressed = external hidden local_unnamed_addr global [5 x i8], align 1

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

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

9:                                                ; preds = %8, %4
  %10 = icmp eq i32 %2, 1
  %11 = icmp ult i32 %1, 5
  %or.cond3 = and i1 %11, %10
  br i1 %or.cond3, label %12, label %15

12:                                               ; preds = %9
  %13 = zext nneg i32 %1 to i64
  %14 = getelementptr inbounds [5 x i8], ptr @_ZL18g_MouseJustPressed, i64 0, i64 %13
  store i8 1, ptr %14, align 1, !tbaa !9
  br label %15

15:                                               ; preds = %12, %9
  ret void
}

attributes #0 = { 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,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass