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

; 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_mouse_button_callbackEP10GLFWwindowiii(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
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call ptr @glfwGetWindowUserPointer(ptr noundef %13)
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  store i8 0, ptr %10, align 1, !tbaa !11
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store i32 1, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 8), align 4, !tbaa !12
  store i8 4, ptr %10, align 1, !tbaa !11
  br label %28

18:                                               ; preds = %4
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 2
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 2, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 8), align 4, !tbaa !12
  store i8 2, ptr %10, align 1, !tbaa !11
  br label %27

22:                                               ; preds = %18
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 3, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 8), align 4, !tbaa !12
  store i8 1, ptr %10, align 1, !tbaa !11
  br label %26

26:                                               ; preds = %25, %22
  br label %27

27:                                               ; preds = %26, %21
  br label %28

28:                                               ; preds = %27, %17
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %44

31:                                               ; preds = %28
  %32 = load i8, ptr %10, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = load i8, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !17
  %35 = zext i8 %34 to i32
  %36 = or i32 %35, %33
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !17
  %38 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 2), align 4, !tbaa !18
  store i16 %38, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 6), align 4, !tbaa !19
  %39 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 3), align 2, !tbaa !20
  store i16 %39, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 7), align 2, !tbaa !21
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !22
  %42 = getelementptr inbounds ptr, ptr %41, i64 6
  %43 = load ptr, ptr %42, align 8
  call void %43(ptr noundef nonnull align 8 dereferenceable(1440) %40, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  br label %85

44:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  %45 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 2), align 4, !tbaa !18
  %46 = sext i16 %45 to i32
  %47 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 6), align 4, !tbaa !19
  %48 = sext i16 %47 to i32
  %49 = sub nsw i32 %46, %48
  %50 = trunc i32 %49 to i16
  store i16 %50, ptr %11, align 2, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  %51 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 3), align 2, !tbaa !20
  %52 = sext i16 %51 to i32
  %53 = load i16, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 7), align 2, !tbaa !21
  %54 = sext i16 %53 to i32
  %55 = sub nsw i32 %52, %54
  %56 = trunc i32 %55 to i16
  store i16 %56, ptr %12, align 2, !tbaa !24
  %57 = load i16, ptr %11, align 2, !tbaa !24
  %58 = sext i16 %57 to i32
  %59 = call i32 @llvm.abs.i32(i32 %58, i1 true)
  %60 = icmp slt i32 %59, 5
  br i1 %60, label %61, label %71

61:                                               ; preds = %44
  %62 = load i16, ptr %12, align 2, !tbaa !24
  %63 = sext i16 %62 to i32
  %64 = call i32 @llvm.abs.i32(i32 %63, i1 true)
  %65 = icmp slt i32 %64, 5
  br i1 %65, label %66, label %71

66:                                               ; preds = %61
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !22
  %69 = getelementptr inbounds ptr, ptr %68, i64 5
  %70 = load ptr, ptr %69, align 8
  call void %70(ptr noundef nonnull align 8 dereferenceable(1440) %67, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  br label %71

71:                                               ; preds = %66, %61, %44
  %72 = load i8, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !17
  %73 = zext i8 %72 to i32
  %74 = load i8, ptr %10, align 1, !tbaa !11
  %75 = zext i8 %74 to i32
  %76 = and i32 %73, %75
  %77 = load i8, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !17
  %78 = zext i8 %77 to i32
  %79 = xor i32 %78, %76
  %80 = trunc i32 %79 to i8
  store i8 %80, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 9), align 4, !tbaa !17
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = load ptr, ptr %81, align 8, !tbaa !22
  %83 = getelementptr inbounds ptr, ptr %82, i64 7
  %84 = load ptr, ptr %83, align 8
  call void %84(ptr noundef nonnull align 8 dereferenceable(1440) %81, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  br label %85

85:                                               ; preds = %71, %31
  store i32 0, ptr getelementptr inbounds (%"class.rmg::MouseEvent", ptr @_ZN3rmg10mouseEventE, i32 0, i32 8), align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !16, i64 16}
!13 = !{!"_ZTSN3rmg10MouseEventE", !14, i64 0, !15, i64 4, !15, i64 6, !15, i64 8, !15, i64 10, !15, i64 12, !15, i64 14, !16, i64 16, !7, i64 20, !7, i64 21}
!14 = !{!"_ZTSN3rmg13KeyboardEventE", !15, i64 0, !7, i64 2}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_ZTSN3rmg11MouseButtonE", !7, i64 0}
!17 = !{!13, !7, i64 20}
!18 = !{!13, !15, i64 4}
!19 = !{!13, !15, i64 12}
!20 = !{!13, !15, i64 6}
!21 = !{!13, !15, i64 14}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = !{!15, !15, 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
@switch.table._ZN3rmg28window_mouse_button_callbackEP10GLFWwindowiii = private unnamed_addr constant [3 x i32] [i32 1, i32 3, i32 2], align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg28window_mouse_button_callbackEP10GLFWwindowiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call ptr @glfwGetWindowUserPointer(ptr noundef %0)
  %6 = icmp ult i32 %1, 3
  br i1 %6, label %switch.lookup, label %8

switch.lookup:                                    ; preds = %4
  %7 = zext nneg i32 %1 to i64
  %switch.gep = getelementptr inbounds [3 x i32], ptr @switch.table._ZN3rmg28window_mouse_button_callbackEP10GLFWwindowiii, i64 0, i64 %7
  %switch.load = load i32, ptr %switch.gep, align 4
  %switch.cast = trunc nuw i32 %1 to i24
  %switch.shiftamt = shl nuw nsw i24 %switch.cast, 3
  %switch.downshift = lshr i24 131332, %switch.shiftamt
  %switch.masked = trunc i24 %switch.downshift to i8
  store i32 %switch.load, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 16), align 4, !tbaa !5
  br label %8

8:                                                ; preds = %4, %switch.lookup
  %.0 = phi i8 [ 0, %4 ], [ %switch.masked, %switch.lookup ]
  %9 = icmp eq i32 %2, 1
  br i1 %9, label %10, label %14

10:                                               ; preds = %8
  %11 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !12
  %12 = or i8 %11, %.0
  store i8 %12, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !12
  %13 = load <2 x i16>, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 4), align 4, !tbaa !13
  store <2 x i16> %13, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 12), align 4, !tbaa !13
  br label %34

14:                                               ; preds = %8
  %15 = load i16, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 4), align 4, !tbaa !14
  %16 = load i16, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 12), align 4, !tbaa !15
  %17 = sub i16 %15, %16
  %18 = tail call i16 @llvm.abs.i16(i16 %17, i1 false)
  %19 = icmp ult i16 %18, 5
  br i1 %19, label %20, label %30

20:                                               ; preds = %14
  %21 = load i16, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 14), align 2, !tbaa !16
  %22 = load i16, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 6), align 2, !tbaa !17
  %23 = sub i16 %22, %21
  %24 = tail call i16 @llvm.abs.i16(i16 %23, i1 false)
  %25 = icmp ult i16 %24, 5
  br i1 %25, label %26, label %30

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %27, i64 40
  %29 = load ptr, ptr %28, align 8
  tail call void %29(ptr noundef nonnull align 8 dereferenceable(1440) %5, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  br label %30

30:                                               ; preds = %26, %20, %14
  %31 = load i8, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !12
  %32 = xor i8 %.0, -1
  %33 = and i8 %31, %32
  store i8 %33, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 20), align 4, !tbaa !12
  br label %34

34:                                               ; preds = %30, %10
  %.sink15 = phi i64 [ 56, %30 ], [ 48, %10 ]
  %35 = load ptr, ptr %5, align 8, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %35, i64 %.sink15
  %37 = load ptr, ptr %36, align 8
  tail call void %37(ptr noundef nonnull align 8 dereferenceable(1440) %5, ptr noundef nonnull align 4 dereferenceable(22) @_ZN3rmg10mouseEventE)
  store i32 0, ptr getelementptr inbounds (i8, ptr @_ZN3rmg10mouseEventE, i64 16), align 4, !tbaa !5
  ret void
}

declare ptr @glfwGetWindowUserPointer(ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.abs.i16(i16, i1 immarg) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !11, i64 16}
!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 = !{!6, !9, i64 20}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !8, i64 4}
!15 = !{!6, !8, i64 12}
!16 = !{!6, !8, i64 14}
!17 = !{!6, !8, i64 6}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !10, i64 0}


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