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

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

@HBufferImage = external dso_local global %struct.HEFI_EDITOR_BUFFER_IMAGE, 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 @HBufferImageMovePosition(i64 noundef %0, i64 noundef %1, i8 noundef zeroext %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !10
  %14 = sub i64 %12, %13
  store i64 %14, ptr %7, align 8, !tbaa !5
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = call zeroext i8 @HUnderCurrentScreen(i64 noundef %15)
  store i8 %16, ptr %10, align 1, !tbaa !9
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = call zeroext i8 @HAboveCurrentScreen(i64 noundef %17)
  store i8 %18, ptr %9, align 1, !tbaa !9
  %19 = load i8, ptr %6, align 1, !tbaa !9
  store i8 %19, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 8), align 8, !tbaa !15
  %20 = load i8, ptr %10, align 1, !tbaa !9
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %3
  %23 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %23, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !10
  br label %62

24:                                               ; preds = %3
  %25 = load i8, ptr %9, align 1, !tbaa !9
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %39

27:                                               ; preds = %24
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  %30 = sub i64 %29, 2
  %31 = add i64 %30, 1
  %32 = icmp ult i64 %28, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %27
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = add i64 %34, 2
  %36 = sub i64 %35, 1
  store i64 %36, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  br label %37

37:                                               ; preds = %33, %27
  %38 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %38, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !10
  br label %61

39:                                               ; preds = %24
  %40 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %40, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !10
  %41 = load i64, ptr %7, align 8, !tbaa !5
  %42 = icmp sle i64 %41, 0
  br i1 %42, label %43, label %56

43:                                               ; preds = %39
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = icmp slt i64 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %43
  %47 = load i64, ptr %7, align 8, !tbaa !5
  %48 = sub nsw i64 0, %47
  br label %51

49:                                               ; preds = %43
  %50 = load i64, ptr %7, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %49, %46
  %52 = phi i64 [ %48, %46 ], [ %50, %49 ]
  store i64 %52, ptr %8, align 8, !tbaa !5
  %53 = load i64, ptr %8, align 8, !tbaa !5
  %54 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  %55 = sub i64 %54, %53
  store i64 %55, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  br label %60

56:                                               ; preds = %39
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  %59 = add i64 %58, %57
  store i64 %59, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  br label %60

60:                                               ; preds = %56, %51
  br label %61

61:                                               ; preds = %60, %37
  br label %62

62:                                               ; preds = %61, %22
  %63 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !10
  %64 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), align 8, !tbaa !16
  %65 = sub i64 %64, 2
  %66 = sub i64 %63, %65
  store i64 %66, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 7), align 8, !tbaa !17
  %67 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %67, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), i32 0, i32 1), align 8, !tbaa !18
  %68 = load i64, ptr %5, align 8, !tbaa !5
  %69 = sub i64 %68, 1
  %70 = mul i64 %69, 3
  %71 = add i64 10, %70
  store i64 %71, ptr %11, align 8, !tbaa !5
  %72 = load i64, ptr %5, align 8, !tbaa !5
  %73 = icmp ugt i64 %72, 8
  br i1 %73, label %74, label %77

74:                                               ; preds = %62
  %75 = load i64, ptr %11, align 8, !tbaa !5
  %76 = add i64 %75, 1
  store i64 %76, ptr %11, align 8, !tbaa !5
  br label %77

77:                                               ; preds = %74, %62
  %78 = load i8, ptr %6, align 1, !tbaa !9
  %79 = icmp ne i8 %78, 0
  br i1 %79, label %83, label %80

80:                                               ; preds = %77
  %81 = load i64, ptr %11, align 8, !tbaa !5
  %82 = add i64 %81, 1
  store i64 %82, ptr %11, align 8, !tbaa !5
  br label %83

83:                                               ; preds = %80, %77
  %84 = load i64, ptr %11, align 8, !tbaa !5
  store i64 %84, ptr getelementptr inbounds (%struct.HEFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 4), i32 0, i32 1), align 8, !tbaa !19
  %85 = load i64, ptr %7, align 8, !tbaa !5
  %86 = call ptr @HMoveCurrentLine(i64 noundef %85)
  store ptr %86, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 3), align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @HAboveCurrentScreen(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @HUnderCurrentScreen(i64 noundef) #1

declare ptr @HMoveCurrentLine(i64 noundef) #2

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


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

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

; Function Attrs: nounwind uwtable
define dso_local void @HBufferImageMovePosition(i64 noundef %0, i64 noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !5
  %5 = sub i64 %0, %4
  %6 = tail call zeroext i8 @HUnderCurrentScreen(i64 noundef %0)
  %7 = tail call zeroext i8 @HAboveCurrentScreen(i64 noundef %0)
  store i8 %2, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 88), align 8, !tbaa !13
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %3
  store i64 %0, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !5
  %.pre = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 32), align 8, !tbaa !14
  br label %21

9:                                                ; preds = %3
  %.not28 = icmp eq i8 %7, 0
  br i1 %.not28, label %18, label %10

10:                                               ; preds = %9
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 32), align 8, !tbaa !14
  %12 = add i64 %11, -1
  %13 = icmp ugt i64 %12, %0
  br i1 %13, label %14, label %16

14:                                               ; preds = %10
  %15 = add nuw i64 %0, 1
  store i64 %15, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 32), align 8, !tbaa !14
  br label %16

16:                                               ; preds = %14, %10
  %17 = phi i64 [ %15, %14 ], [ %11, %10 ]
  store i64 %0, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !5
  br label %21

18:                                               ; preds = %9
  store i64 %0, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !5
  %19 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 32), align 8, !tbaa !14
  %20 = add i64 %19, %5
  store i64 %20, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 32), align 8, !tbaa !14
  br label %21

21:                                               ; preds = %18, %16, %8
  %22 = phi i64 [ %17, %16 ], [ %.pre, %8 ], [ %20, %18 ]
  %.neg31 = add i64 %0, 2
  %23 = sub i64 %.neg31, %22
  store i64 %23, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 80), align 8, !tbaa !15
  store i64 %1, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 72), align 8, !tbaa !16
  %24 = mul i64 %1, 3
  %25 = icmp ugt i64 %1, 8
  %spec.select.v = select i1 %25, i64 8, i64 7
  %spec.select = add i64 %spec.select.v, %24
  %.not30 = icmp eq i8 %2, 0
  %26 = zext i1 %.not30 to i64
  %.1 = add i64 %spec.select, %26
  store i64 %.1, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 40), align 8, !tbaa !17
  %27 = tail call ptr @HMoveCurrentLine(i64 noundef %5) #2
  store ptr %27, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 24), align 8, !tbaa !18
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @HAboveCurrentScreen(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @HUnderCurrentScreen(i64 noundef) local_unnamed_addr #0

declare ptr @HMoveCurrentLine(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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, !10, i64 64}
!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, !8, i64 88}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !10, i64 80}
!16 = !{!6, !10, i64 72}
!17 = !{!6, !10, i64 40}
!18 = !{!6, !7, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass