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

; 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.HEFI_EDITOR_BUFFER_IMAGE = type { ptr, ptr, i64, ptr, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, i64, i8, i8, i32, ptr, ptr, ptr }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }
%struct.HEFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.HEFI_EDITOR_COLOR_UNION, %struct.HEFI_EDITOR_POSITION, i8, ptr, i32, i32, i64, i64 }
%union.HEFI_EDITOR_COLOR_UNION = type { i64 }

@HBufferImage = external dso_local global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@HMainEditor = external global %struct.HEFI_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 @HBufferImageAdjustMousePosition(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 sge i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  store i64 %13, ptr %7, align 8, !tbaa !9
  br label %18

14:                                               ; preds = %2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sub nsw i32 0, %15
  %17 = sext i32 %16 to i64
  store i64 %17, ptr %7, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %14, %11
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp sge i32 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  store i64 %23, ptr %8, align 8, !tbaa !9
  br label %28

24:                                               ; preds = %18
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sub nsw i32 0, %25
  %27 = sext i32 %26 to i64
  store i64 %27, ptr %8, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %24, %21
  %29 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), i32 0, i32 1), align 8, !tbaa !11
  store i64 %29, ptr %5, align 8, !tbaa !9
  %30 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), 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 = %28
  %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 = %28
  %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, 10
  br i1 %68, label %69, label %74

69:                                               ; preds = %66
  %70 = load i64, ptr %5, align 8, !tbaa !9
  %71 = icmp ule i64 %70, 57
  br i1 %71, label %72, label %74

72:                                               ; preds = %69
  %73 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %73, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), i32 0, i32 1), align 8, !tbaa !11
  br label %84

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

77:                                               ; preds = %74
  store i64 10, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), i32 0, i32 1), align 8, !tbaa !11
  br label %83

78:                                               ; preds = %74
  %79 = load i64, ptr %5, align 8, !tbaa !9
  %80 = icmp ugt i64 %79, 57
  br i1 %80, label %81, label %82

81:                                               ; preds = %78
  store i64 57, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), i32 0, i32 1), align 8, !tbaa !11
  br label %82

82:                                               ; preds = %81, %78
  br label %83

83:                                               ; preds = %82, %77
  br label %84

84:                                               ; preds = %83, %72
  %85 = load i64, ptr %6, align 8, !tbaa !9
  %86 = icmp uge i64 %85, 2
  br i1 %86, label %87, label %94

87:                                               ; preds = %84
  %88 = load i64, ptr %6, align 8, !tbaa !9
  %89 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 2), align 8, !tbaa !16
  %90 = sub i64 %89, 1
  %91 = icmp ule i64 %88, %90
  br i1 %91, label %92, label %94

92:                                               ; preds = %87
  %93 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %93, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), align 8, !tbaa !15
  br label %108

94:                                               ; preds = %87, %84
  %95 = load i64, ptr %6, align 8, !tbaa !9
  %96 = icmp ult i64 %95, 2
  br i1 %96, label %97, label %98

97:                                               ; preds = %94
  store i64 2, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), align 8, !tbaa !15
  br label %107

98:                                               ; preds = %94
  %99 = load i64, ptr %6, align 8, !tbaa !9
  %100 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 2), align 8, !tbaa !16
  %101 = sub i64 %100, 1
  %102 = icmp ugt i64 %99, %101
  br i1 %102, label %103, label %106

103:                                              ; preds = %98
  %104 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 2), align 8, !tbaa !16
  %105 = sub i64 %104, 1
  store i64 %105, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 5), align 8, !tbaa !15
  br label %106

106:                                              ; preds = %103, %98
  br label %107

107:                                              ; preds = %106, %97
  br label %108

108:                                              ; preds = %107, %92
  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 56}
!12 = !{!"", !13, i64 0, !13, i64 8, !10, i64 16, !13, i64 24, !14, i64 32, !14, i64 48, !14, i64 64, !10, i64 80, !7, i64 88, !7, i64 89, !6, i64 92, !13, i64 96, !13, i64 104, !13, i64 112}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 8}
!15 = !{!12, !10, i64 48}
!16 = !{!17, !10, i64 16}
!17 = !{!"", !13, i64 0, !7, i64 8, !14, i64 16, !7, i64 32, !13, i64 40, !6, i64 48, !6, i64 52, !10, i64 56, !10, i64 64}


; 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.HEFI_EDITOR_BUFFER_IMAGE = type { ptr, ptr, i64, ptr, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, i64, i8, i8, i32, ptr, ptr, ptr }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }
%struct.HEFI_EDITOR_GLOBAL_EDITOR = type { ptr, %union.HEFI_EDITOR_COLOR_UNION, %struct.HEFI_EDITOR_POSITION, i8, ptr, i32, i32, i64, i64 }
%union.HEFI_EDITOR_COLOR_UNION = type { i64 }

@HBufferImage = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@HMainEditor = external local_unnamed_addr global %struct.HEFI_EDITOR_GLOBAL_EDITOR, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @HBufferImageAdjustMousePosition(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.031.in = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
  %.031 = zext nneg i32 %.031.in to i64
  %.0.in = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  %.0 = zext nneg i32 %.0.in to i64
  %3 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 56), align 8, !tbaa !5
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 48), align 8, !tbaa !13
  %5 = zext nneg i32 %0 to i64
  %6 = add i64 %3, %5
  %spec.select = tail call i64 @llvm.usub.sat.i64(i64 %3, i64 %.031)
  %7 = icmp slt i32 %0, 0
  %.033 = select i1 %7, i64 %spec.select, i64 %6
  %8 = zext nneg i32 %1 to i64
  %9 = add i64 %4, %8
  %spec.select43 = tail call i64 @llvm.usub.sat.i64(i64 %4, i64 %.0)
  %10 = icmp slt i32 %1, 0
  %.032 = select i1 %10, i64 %spec.select43, i64 %9
  %11 = add i64 %.033, -10
  %or.cond = icmp ult i64 %11, 48
  %12 = icmp ult i64 %.033, 10
  %. = select i1 %12, i64 10, i64 57
  %.sink = select i1 %or.cond, i64 %.033, i64 %.
  store i64 %.sink, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 56), align 8, !tbaa !5
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 16), align 8
  %14 = add i64 %13, -1
  %..032 = tail call i64 @llvm.umin.i64(i64 %.032, i64 %14)
  %.inv = icmp ult i64 %.032, 2
  %.sink44 = select i1 %.inv, i64 2, i64 %..032
  store i64 %.sink44, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 48), 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, !10, i64 56}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !11, i64 48, !11, i64 64, !10, i64 80, !8, i64 88, !8, i64 89, !12, i64 92, !7, i64 96, !7, i64 104, !7, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !10, i64 48}


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