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

; 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_LINE = type { i64, [16 x i8], i64, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }

@HBufferImage = external dso_local global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@HBufferImageNeedRefresh = external dso_local global i8, align 1
@HBufferImageOnlyLineNeedRefresh = external dso_local global i8, align 1

; 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
declare dso_local void @HBufferImageMovePosition(i64 noundef, i64 noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @HBufferImageScrollRight() #1 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i8 0, ptr @HBufferImageNeedRefresh, align 1, !tbaa !5
  store i8 0, ptr @HBufferImageOnlyLineNeedRefresh, align 1, !tbaa !5
  %6 = load ptr, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 3), align 8, !tbaa !8
  store ptr %6, ptr %2, align 8, !tbaa !14
  %7 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 6), align 8, !tbaa !15
  store i64 %7, ptr %3, align 8, !tbaa !16
  %8 = load i64, 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 !17
  store i64 %8, ptr %4, align 8, !tbaa !16
  %9 = load i64, ptr %4, align 8, !tbaa !16
  %10 = load ptr, ptr %2, align 8, !tbaa !14
  %11 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %10, i32 0, i32 2
  %12 = load i64, ptr %11, align 8, !tbaa !18
  %13 = icmp ugt i64 %9, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %0
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %36

15:                                               ; preds = %0
  %16 = load i64, ptr %4, align 8, !tbaa !16
  %17 = icmp eq i64 %16, 16
  br i1 %17, label %18, label %30

18:                                               ; preds = %15
  %19 = load ptr, ptr %2, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds %struct._LIST_ENTRY, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %23 = load ptr, ptr @HBufferImage, align 8, !tbaa !22
  %24 = icmp ne ptr %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %18
  %26 = load i64, ptr %3, align 8, !tbaa !16
  %27 = add i64 %26, 1
  store i64 %27, ptr %3, align 8, !tbaa !16
  store i64 1, ptr %4, align 8, !tbaa !16
  br label %29

28:                                               ; preds = %18
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %36

29:                                               ; preds = %25
  br label %33

30:                                               ; preds = %15
  %31 = load i64, ptr %4, align 8, !tbaa !16
  %32 = add i64 %31, 1
  store i64 %32, ptr %4, align 8, !tbaa !16
  br label %33

33:                                               ; preds = %30, %29
  %34 = load i64, ptr %3, align 8, !tbaa !16
  %35 = load i64, ptr %4, align 8, !tbaa !16
  call void @HBufferImageMovePosition(i64 noundef %34, i64 noundef %35, i8 noundef zeroext 1)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %36

36:                                               ; preds = %33, %28, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  %37 = load i64, ptr %1, align 8
  ret i64 %37
}

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

%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
@HBufferImageNeedRefresh = external dso_local local_unnamed_addr global i8, align 1
@HBufferImageOnlyLineNeedRefresh = external dso_local local_unnamed_addr global i8, align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @HBufferImageScrollRight() local_unnamed_addr #0 {
  store i8 0, ptr @HBufferImageNeedRefresh, align 1, !tbaa !5
  store i8 0, ptr @HBufferImageOnlyLineNeedRefresh, align 1, !tbaa !5
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 24), align 8, !tbaa !8
  %2 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 64), align 8, !tbaa !14
  %3 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 72), align 8, !tbaa !15
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !16
  %6 = icmp ugt i64 %3, %5
  br i1 %6, label %18, label %7

7:                                                ; preds = %0
  %8 = icmp eq i64 %3, 16
  br i1 %8, label %9, label %15

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %1, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !19
  %12 = load ptr, ptr @HBufferImage, align 8, !tbaa !20
  %.not = icmp eq ptr %11, %12
  br i1 %.not, label %18, label %13

13:                                               ; preds = %9
  %14 = add i64 %2, 1
  br label %17

15:                                               ; preds = %7
  %16 = add i64 %3, 1
  br label %17

17:                                               ; preds = %15, %13
  %.08 = phi i64 [ %14, %13 ], [ %2, %15 ]
  %.0 = phi i64 [ 1, %13 ], [ %16, %15 ]
  tail call void @HBufferImageMovePosition(i64 noundef %.08, i64 noundef %.0, i8 noundef zeroext 1)
  br label %18

18:                                               ; preds = %9, %0, %17
  ret i64 0
}

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass