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

; 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 zeroext i8 @HBufferImageIsInSelectedArea(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %14 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 7), align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %2
  %17 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 8), align 8, !tbaa !14
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %2
  store i8 0, ptr %3, align 1
  store i32 1, ptr %13, align 4
  br label %90

20:                                               ; preds = %16
  %21 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 7), align 8, !tbaa !9
  %22 = sub i64 %21, 1
  %23 = udiv i64 %22, 16
  %24 = add i64 %23, 1
  store i64 %24, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 8), align 8, !tbaa !14
  %26 = sub i64 %25, 1
  %27 = udiv i64 %26, 16
  %28 = add i64 %27, 1
  store i64 %28, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 7), align 8, !tbaa !9
  %30 = sub i64 %29, 1
  %31 = urem i64 %30, 16
  %32 = add i64 %31, 1
  store i64 %32, ptr %9, align 8, !tbaa !5
  %33 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_GLOBAL_EDITOR, ptr @HMainEditor, i32 0, i32 8), align 8, !tbaa !14
  %34 = sub i64 %33, 1
  %35 = urem i64 %34, 16
  %36 = add i64 %35, 1
  store i64 %36, ptr %10, align 8, !tbaa !5
  %37 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 7), align 8, !tbaa !15
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = add i64 %37, %38
  %40 = sub i64 %39, 2
  store i64 %40, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !5
  %42 = load i64, ptr %7, align 8, !tbaa !5
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %48, label %44

44:                                               ; preds = %20
  %45 = load i64, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !5
  %47 = icmp ugt i64 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %44, %20
  store i8 0, ptr %3, align 1
  store i32 1, ptr %13, align 4
  br label %90

49:                                               ; preds = %44
  %50 = load i64, ptr %6, align 8, !tbaa !5
  %51 = load i64, ptr %7, align 8, !tbaa !5
  %52 = icmp ugt i64 %50, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %49
  store i64 1, ptr %9, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %53, %49
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = load i64, ptr %8, align 8, !tbaa !5
  %57 = icmp ult i64 %55, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %54
  store i64 16, ptr %10, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %58, %54
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = sub i64 %60, 1
  %62 = mul i64 %61, 3
  %63 = add i64 10, %62
  store i64 %63, ptr %11, align 8, !tbaa !5
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = icmp ugt i64 %64, 8
  br i1 %65, label %66, label %69

66:                                               ; preds = %59
  %67 = load i64, ptr %11, align 8, !tbaa !5
  %68 = add i64 %67, 1
  store i64 %68, ptr %11, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %66, %59
  %70 = load i64, ptr %10, align 8, !tbaa !5
  %71 = sub i64 %70, 1
  %72 = mul i64 %71, 3
  %73 = add i64 10, %72
  %74 = add i64 %73, 1
  store i64 %74, ptr %12, align 8, !tbaa !5
  %75 = load i64, ptr %10, align 8, !tbaa !5
  %76 = icmp ugt i64 %75, 8
  br i1 %76, label %77, label %80

77:                                               ; preds = %69
  %78 = load i64, ptr %12, align 8, !tbaa !5
  %79 = add i64 %78, 1
  store i64 %79, ptr %12, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %77, %69
  %81 = load i64, ptr %5, align 8, !tbaa !5
  %82 = load i64, ptr %11, align 8, !tbaa !5
  %83 = icmp ult i64 %81, %82
  br i1 %83, label %88, label %84

84:                                               ; preds = %80
  %85 = load i64, ptr %5, align 8, !tbaa !5
  %86 = load i64, ptr %12, align 8, !tbaa !5
  %87 = icmp ugt i64 %85, %86
  br i1 %87, label %88, label %89

88:                                               ; preds = %84, %80
  store i8 0, ptr %3, align 1
  store i32 1, ptr %13, align 4
  br label %90

89:                                               ; preds = %84
  store i8 1, ptr %3, align 1
  store i32 1, ptr %13, align 4
  br label %90

90:                                               ; preds = %89, %88, %48, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  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
  %91 = load i8, ptr %3, align 1
  ret i8 %91
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 56}
!10 = !{!"", !11, i64 0, !7, i64 8, !12, i64 16, !7, i64 32, !11, i64 40, !13, i64 48, !13, i64 52, !6, i64 56, !6, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 64}
!15 = !{!16, !6, i64 80}
!16 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !12, i64 32, !12, i64 48, !12, i64 64, !6, i64 80, !7, i64 88, !7, i64 89, !13, i64 92, !11, i64 96, !11, i64 104, !11, i64 112}


; 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(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @HBufferImageIsInSelectedArea(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 56), align 8, !tbaa !5
  %4 = icmp eq i64 %3, 0
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @HMainEditor, i64 64), align 8
  %6 = icmp eq i64 %5, 0
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %30, label %7

7:                                                ; preds = %2
  %8 = add i64 %3, -1
  %9 = lshr i64 %8, 4
  %10 = add i64 %5, -1
  %11 = lshr i64 %10, 4
  %12 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 80), align 8, !tbaa !13
  %13 = add i64 %0, -2
  %14 = add i64 %13, %12
  %.not = icmp ule i64 %14, %9
  %15 = add nuw nsw i64 %11, 1
  %16 = icmp ugt i64 %14, %15
  %or.cond33 = select i1 %.not, i1 true, i1 %16
  br i1 %or.cond33, label %30, label %17

17:                                               ; preds = %7
  %18 = and i64 %10, 15
  %19 = add nuw nsw i64 %18, 1
  %20 = and i64 %8, 15
  %21 = add nuw nsw i64 %20, 1
  %22 = add nuw nsw i64 %9, 1
  %23 = icmp ugt i64 %14, %22
  %spec.select = select i1 %23, i64 1, i64 %21
  %.not31 = icmp ugt i64 %14, %11
  %.022 = select i1 %.not31, i64 %19, i64 16
  %24 = mul nuw nsw i64 %spec.select, 3
  %25 = icmp ugt i64 %spec.select, 8
  %.021.v = select i1 %25, i64 8, i64 7
  %.021 = add nuw nsw i64 %.021.v, %24
  %26 = mul nuw nsw i64 %.022, 3
  %27 = icmp ugt i64 %.022, 8
  %.0.v = select i1 %27, i64 9, i64 8
  %.0 = add nuw nsw i64 %.0.v, %26
  %28 = icmp ule i64 %.021, %1
  %29 = icmp uge i64 %.0, %1
  %or.cond34.not = select i1 %28, i1 %29, i1 false
  %spec.select35 = zext i1 %or.cond34.not to i8
  br label %30

30:                                               ; preds = %17, %7, %2
  %.024 = phi i8 [ 0, %2 ], [ 0, %7 ], [ %spec.select35, %17 ]
  ret i8 %.024
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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" }

!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 56}
!6 = !{!"", !7, i64 0, !8, i64 8, !10, i64 16, !8, i64 32, !7, i64 40, !12, i64 48, !12, i64 52, !11, i64 56, !11, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !11, i64 80}
!14 = !{!"", !7, i64 0, !7, i64 8, !11, i64 16, !7, i64 24, !10, i64 32, !10, i64 48, !10, i64 64, !11, i64 80, !8, i64 88, !8, i64 89, !12, i64 92, !7, i64 96, !7, i64 104, !7, i64 112}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass