; LLVM IR from achilles288/robot-monitor-graphics :: src/window/window.ll (ZN3rmg28window_cursor_enter_callbackEP10GLFWwindowi)

; 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.rmg::MouseEvent" = type <{ %"class.rmg::KeyboardEvent.base", i8, i16, i16, i16, i16, i16, i16, i32, i8, i8, [2 x i8] }>
%"class.rmg::KeyboardEvent.base" = type <{ i16, i8 }>

@_ZN3rmg10mouseEventE = external global %"class.rmg::MouseEvent", align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg28window_cursor_enter_callbackEP10GLFWwindowi(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call ptr @glfwGetWindowUserPointer(ptr noundef %8)
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %22

12:                                               ; preds = %2
  %13 = load i8, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = or i32 %14, 8
  %16 = trunc i32 %15 to i8
  store i8 %16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  call void @glfwGetCursorPos(ptr noundef %17, ptr noundef %6, ptr noundef %7)
  %18 = load double, ptr %6, align 8, !tbaa !16
  %19 = fptosi double %18 to i16
  store i16 %19, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 2), align 4, !tbaa !18
  %20 = load double, ptr %7, align 8, !tbaa !16
  %21 = fptosi double %20 to i16
  store i16 %21, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 3), align 2, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %30

22:                                               ; preds = %2
  %23 = load i8, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = and i32 %24, 8
  %26 = load i8, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = xor i32 %27, %25
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !11
  br label %30

30:                                               ; preds = %22, %12
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = getelementptr inbounds ptr, ptr %32, i64 9
  %34 = load ptr, ptr %33, align 8
  call void %34(ptr noundef nonnull align 8 dereferenceable(1440) %31, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

declare ptr @glfwGetWindowUserPointer(ptr noundef) #2

declare void @glfwGetCursorPos(ptr noundef, ptr noundef, ptr noundef) #2

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !7, i64 20}
!12 = !{!"_ZTSN3rmg10MouseEventE", !13, i64 0, !14, i64 4, !14, i64 6, !14, i64 8, !14, i64 10, !14, i64 12, !14, i64 14, !15, i64 16, !7, i64 20, !7, i64 21}
!13 = !{!"_ZTSN3rmg13KeyboardEventE", !14, i64 0, !7, i64 2}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ZTSN3rmg11MouseButtonE", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!12, !14, i64 4}
!19 = !{!12, !14, i64 6}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !8, 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.rmg::MouseEvent" = type <{ %"class.rmg::KeyboardEvent.base", i8, i16, i16, i16, i16, i16, i16, i32, i8, i8, [2 x i8] }>
%"class.rmg::KeyboardEvent.base" = type <{ i16, i8 }>

@_ZN3rmg10mouseEventE = external global %"class.rmg::MouseEvent", align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg28window_cursor_enter_callbackEP10GLFWwindowi(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = tail call ptr @glfwGetWindowUserPointer(ptr noundef %0)
  %.not = icmp eq i32 %1, 0
  %6 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !5
  br i1 %.not, label %14, label %7

7:                                                ; preds = %2
  %8 = or i8 %6, 8
  store i8 %8, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @glfwGetCursorPos(ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %9 = load double, ptr %3, align 8, !tbaa !12
  %10 = load double, ptr %4, align 8, !tbaa !12
  %11 = insertelement <2 x double> poison, double %9, i64 0
  %12 = insertelement <2 x double> %11, double %10, i64 1
  %13 = fptosi <2 x double> %12 to <2 x i16>
  store <2 x i16> %13, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 4), align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %16

14:                                               ; preds = %2
  %15 = and i8 %6, -9
  store i8 %15, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !5
  br label %16

16:                                               ; preds = %14, %7
  %17 = load ptr, ptr %5, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %17, i64 72
  %19 = load ptr, ptr %18, align 8
  call void %19(ptr noundef nonnull align 8 dereferenceable(1440) %5, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  ret void
}

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

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

declare ptr @glfwGetWindowUserPointer(ptr noundef) local_unnamed_addr #2

declare void @glfwGetCursorPos(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !9, i64 20}
!6 = !{!"_ZTSN3rmg10MouseEventE", !7, i64 0, !8, i64 4, !8, i64 6, !8, i64 8, !8, i64 10, !8, i64 12, !8, i64 14, !11, i64 16, !9, i64 20, !9, i64 21}
!7 = !{!"_ZTSN3rmg13KeyboardEventE", !8, i64 0, !9, i64 2}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN3rmg11MouseButtonE", !9, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !9, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !10, i64 0}


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