; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/ShellPkg/Library (FileBufferAdjustMousePosition)

; 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.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }
%struct.EFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.EFI_EDITOR_COLOR_UNION, %struct.EFI_EDITOR_POSITION, ptr, i8, ptr, i32, i32 }
%union.EFI_EDITOR_COLOR_UNION = type { i64 }

@FileBuffer = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@MainEditor = external global %struct.EFI_EDITOR_GLOBAL_EDITOR, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @FileBufferAdjustMousePosition(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sub nsw i32 0, %12
  br label %16

14:                                               ; preds = %2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %14, %11
  %17 = phi i32 [ %13, %11 ], [ %15, %14 ]
  %18 = sext i32 %17 to i64
  store i64 %18, ptr %7, align 8, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sub nsw i32 0, %22
  br label %26

24:                                               ; preds = %16
  %25 = load i32, ptr %4, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %24, %21
  %27 = phi i32 [ %23, %21 ], [ %25, %24 ]
  %28 = sext i32 %27 to i64
  store i64 %28, ptr %8, align 8, !tbaa !9
  %29 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), i32 0, i32 1), align 8, !tbaa !11
  store i64 %29, ptr %5, align 8, !tbaa !9
  %30 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), align 8, !tbaa !15
  store i64 %30, ptr %6, align 8, !tbaa !9
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %26
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = add i64 %36, %35
  store i64 %37, ptr %5, align 8, !tbaa !9
  br label %48

38:                                               ; preds = %26
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = icmp uge i64 %39, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %38
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = sub i64 %44, %43
  store i64 %45, ptr %5, align 8, !tbaa !9
  br label %47

46:                                               ; preds = %38
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %46, %42
  br label %48

48:                                               ; preds = %47, %33
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp sge i32 %49, 0
  br i1 %50, label %51, label %56

51:                                               ; preds = %48
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = add i64 %54, %53
  store i64 %55, ptr %6, align 8, !tbaa !9
  br label %66

56:                                               ; preds = %48
  %57 = load i64, ptr %6, align 8, !tbaa !9
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = icmp uge i64 %57, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %56
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = sub i64 %62, %61
  store i64 %63, ptr %6, align 8, !tbaa !9
  br label %65

64:                                               ; preds = %56
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %64, %60
  br label %66

66:                                               ; preds = %65, %51
  %67 = load i64, ptr %5, align 8, !tbaa !9
  %68 = icmp uge i64 %67, 1
  br i1 %68, label %69, label %75

69:                                               ; preds = %66
  %70 = load i64, ptr %5, align 8, !tbaa !9
  %71 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !16
  %72 = icmp ule i64 %70, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %69
  %74 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %74, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), i32 0, i32 1), align 8, !tbaa !11
  br label %87

75:                                               ; preds = %69, %66
  %76 = load i64, ptr %5, align 8, !tbaa !9
  %77 = icmp ult i64 %76, 1
  br i1 %77, label %78, label %79

78:                                               ; preds = %75
  store i64 1, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), i32 0, i32 1), align 8, !tbaa !11
  br label %86

79:                                               ; preds = %75
  %80 = load i64, ptr %5, align 8, !tbaa !9
  %81 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !16
  %82 = icmp ugt i64 %80, %81
  br i1 %82, label %83, label %85

83:                                               ; preds = %79
  %84 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !16
  store i64 %84, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), i32 0, i32 1), align 8, !tbaa !11
  br label %85

85:                                               ; preds = %83, %79
  br label %86

86:                                               ; preds = %85, %78
  br label %87

87:                                               ; preds = %86, %73
  %88 = load i64, ptr %6, align 8, !tbaa !9
  %89 = icmp uge i64 %88, 2
  br i1 %89, label %90, label %97

90:                                               ; preds = %87
  %91 = load i64, ptr %6, align 8, !tbaa !9
  %92 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !18
  %93 = sub i64 %92, 1
  %94 = icmp ule i64 %91, %93
  br i1 %94, label %95, label %97

95:                                               ; preds = %90
  %96 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %96, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), align 8, !tbaa !15
  br label %111

97:                                               ; preds = %90, %87
  %98 = load i64, ptr %6, align 8, !tbaa !9
  %99 = icmp ult i64 %98, 2
  br i1 %99, label %100, label %101

100:                                              ; preds = %97
  store i64 2, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), align 8, !tbaa !15
  br label %110

101:                                              ; preds = %97
  %102 = load i64, ptr %6, align 8, !tbaa !9
  %103 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !18
  %104 = sub i64 %103, 1
  %105 = icmp ugt i64 %102, %104
  br i1 %105, label %106, label %109

106:                                              ; preds = %101
  %107 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !18
  %108 = sub i64 %107, 1
  store i64 %108, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), align 8, !tbaa !15
  br label %109

109:                                              ; preds = %106, %101
  br label %110

110:                                              ; preds = %109, %100
  br label %111

111:                                              ; preds = %110, %95
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 #2 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 80}
!12 = !{!"", !13, i64 0, !6, i64 8, !13, i64 16, !13, i64 24, !10, i64 32, !14, i64 40, !14, i64 56, !14, i64 72, !14, i64 88, !7, i64 104, !7, i64 105, !7, i64 106, !13, i64 112}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 8}
!15 = !{!12, !10, i64 72}
!16 = !{!17, !10, i64 24}
!17 = !{!"", !13, i64 0, !7, i64 8, !14, i64 16, !13, i64 32, !7, i64 40, !13, i64 48, !6, i64 56, !6, i64 60}
!18 = !{!17, !10, i64 16}


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

%struct.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }
%struct.EFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.EFI_EDITOR_COLOR_UNION, %struct.EFI_EDITOR_POSITION, ptr, i8, ptr, i32, i32 }
%union.EFI_EDITOR_COLOR_UNION = type { i64 }

@FileBuffer = external dso_local local_unnamed_addr global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@MainEditor = external local_unnamed_addr global %struct.EFI_EDITOR_GLOBAL_EDITOR, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @FileBufferAdjustMousePosition(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
  %4 = zext nneg i32 %3 to i64
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 80), align 8, !tbaa !5
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 72), align 8, !tbaa !13
  %7 = zext nneg i32 %0 to i64
  %8 = add i64 %5, %7
  %spec.select = tail call i64 @llvm.usub.sat.i64(i64 %5, i64 %4)
  %9 = icmp slt i32 %0, 0
  %.0 = select i1 %9, i64 %spec.select, i64 %8
  %.not40 = icmp eq i64 %.0, 0
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 24), align 8
  %.not41 = icmp ugt i64 %.0, %10
  %or.cond = select i1 %.not40, i1 true, i1 %.not41
  %or.cond.not = xor i1 %or.cond, true
  %brmerge = or i1 %.not40, %or.cond.not
  %brmerge45 = select i1 %brmerge, i1 true, i1 %.not41
  br i1 %brmerge45, label %.sink.split, label %11

.sink.split:                                      ; preds = %2
  %.0.mux = tail call i64 @llvm.umin.i64(i64 %.0, i64 %10)
  %.0.mux.mux = select i1 %.not40, i64 1, i64 %.0.mux
  store i64 %.0.mux.mux, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 80), align 8, !tbaa !5
  br label %11

11:                                               ; preds = %2, %.sink.split
  %12 = icmp slt i32 %1, 0
  %13 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  %14 = zext nneg i32 %13 to i64
  %spec.select43 = tail call i64 @llvm.usub.sat.i64(i64 %6, i64 %14)
  %15 = zext nneg i32 %1 to i64
  %16 = add i64 %6, %15
  %.030 = select i1 %12, i64 %spec.select43, i64 %16
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 16), align 8
  %18 = add i64 %17, -1
  %..030 = tail call i64 @llvm.umin.i64(i64 %.030, i64 %18)
  %.inv = icmp ult i64 %.030, 2
  %.sink44 = select i1 %.inv, i64 2, i64 %..030
  store i64 %.sink44, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 72), align 8, !tbaa !13
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.usub.sat.i64(i64, i64) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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 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 80}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !12, i64 56, !12, i64 72, !12, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!6, !11, i64 72}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass