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

; 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 @_ZN3rmg31window_cursor_position_callbackEP10GLFWwindowdd(ptr noundef %0, double noundef %1, double noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call ptr @glfwGetWindowUserPointer(ptr noundef %8)
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load double, ptr %5, align 8, !tbaa !9
  %11 = fptosi double %10 to i16
  %12 = sext i16 %11 to i32
  %13 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 2), align 4, !tbaa !11
  %14 = sext i16 %13 to i32
  %15 = sub nsw i32 %12, %14
  %16 = trunc i32 %15 to i16
  store i16 %16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 4), align 4, !tbaa !16
  %17 = load double, ptr %6, align 8, !tbaa !9
  %18 = fptosi double %17 to i16
  %19 = sext i16 %18 to i32
  %20 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 3), align 2, !tbaa !17
  %21 = sext i16 %20 to i32
  %22 = sub nsw i32 %19, %21
  %23 = trunc i32 %22 to i16
  store i16 %23, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 5), align 2, !tbaa !18
  %24 = load double, ptr %5, align 8, !tbaa !9
  %25 = fptosi double %24 to i16
  store i16 %25, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 2), align 4, !tbaa !11
  %26 = load double, ptr %6, align 8, !tbaa !9
  %27 = fptosi double %26 to i16
  store i16 %27, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 3), align 2, !tbaa !17
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = getelementptr inbounds ptr, ptr %29, i64 8
  %31 = load ptr, ptr %30, align 8
  call void %31(ptr noundef nonnull align 8 dereferenceable(1440) %28, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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

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 = !{!"double", !7, i64 0}
!11 = !{!12, !14, i64 4}
!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 = !{!12, !14, i64 8}
!17 = !{!12, !14, i64 6}
!18 = !{!12, !14, i64 10}
!19 = !{!20, !20, i64 0}
!20 = !{!"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 @_ZN3rmg31window_cursor_position_callbackEP10GLFWwindowdd(ptr noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @glfwGetWindowUserPointer(ptr noundef %0)
  %5 = insertelement <2 x double> poison, double %1, i64 0
  %6 = insertelement <2 x double> %5, double %2, i64 1
  %7 = fptosi <2 x double> %6 to <2 x i16>
  %8 = load <2 x i16>, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 4), align 4, !tbaa !5
  %9 = sub <2 x i16> %7, %8
  store <2 x i16> %9, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 8), align 4, !tbaa !5
  store <2 x i16> %7, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 4), align 4, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 64
  %12 = load ptr, ptr %11, align 8
  tail call void %12(ptr noundef nonnull align 8 dereferenceable(1440) %4, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  ret void
}

declare ptr @glfwGetWindowUserPointer(ptr noundef) local_unnamed_addr #1

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


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