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

; 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
@.str.10 = external hidden unnamed_addr constant [167 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x 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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @HBufferImageScrollLeft() #2 {
  %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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  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 = icmp ule i64 %9, 1
  br i1 %10, label %11, label %55

11:                                               ; preds = %0
  %12 = load ptr, ptr %2, align 8, !tbaa !14
  %13 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %12, i32 0, i32 3
  %14 = getelementptr inbounds %struct._LIST_ENTRY, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !18
  %16 = load ptr, ptr @HBufferImage, align 8, !tbaa !21
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %18, label %53

18:                                               ; preds = %11
  %19 = load i64, ptr %3, align 8, !tbaa !16
  %20 = add i64 %19, -1
  store i64 %20, ptr %3, align 8, !tbaa !16
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %40

24:                                               ; preds = %18
  %25 = load ptr, ptr %2, align 8, !tbaa !14
  %26 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %25, i32 0, i32 3
  %27 = getelementptr inbounds %struct._LIST_ENTRY, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %31 = inttoptr i64 %30 to ptr
  %32 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !22
  %34 = icmp ne i64 %33, 1819043173
  br i1 %34, label %35, label %40

35:                                               ; preds = %24
  call void @DebugAssert(ptr noundef @.str.10, i64 noundef 1594, ptr noundef @.str.11)
  %36 = load ptr, ptr %2, align 8, !tbaa !14
  %37 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds %struct._LIST_ENTRY, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  br label %48

40:                                               ; preds = %24, %18
  %41 = load ptr, ptr %2, align 8, !tbaa !14
  %42 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %41, i32 0, i32 3
  %43 = getelementptr inbounds %struct._LIST_ENTRY, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = ptrtoint ptr %44 to i64
  %46 = sub i64 %45, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %47 = inttoptr i64 %46 to ptr
  br label %48

48:                                               ; preds = %40, %35
  %49 = phi ptr [ %39, %35 ], [ %47, %40 ]
  store ptr %49, ptr %2, align 8, !tbaa !14
  %50 = load ptr, ptr %2, align 8, !tbaa !14
  %51 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !23
  store i64 %52, ptr %4, align 8, !tbaa !16
  br label %54

53:                                               ; preds = %11
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %61

54:                                               ; preds = %48
  br label %58

55:                                               ; preds = %0
  %56 = load i64, ptr %4, align 8, !tbaa !16
  %57 = add i64 %56, -1
  store i64 %57, ptr %4, align 8, !tbaa !16
  br label %58

58:                                               ; preds = %55, %54
  %59 = load i64, ptr %3, align 8, !tbaa !16
  %60 = load i64, ptr %4, align 8, !tbaa !16
  call void @HBufferImageMovePosition(i64 noundef %59, i64 noundef %60, i8 noundef zeroext 1)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %61

61:                                               ; preds = %58, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %62 = load i64, ptr %1, align 8
  ret i64 %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"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, !10, i64 40}
!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 = !{!9, !10, i64 0}
!22 = !{!19, !11, i64 0}
!23 = !{!19, !11, 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
@HBufferImageNeedRefresh = external dso_local local_unnamed_addr global i8, align 1
@HBufferImageOnlyLineNeedRefresh = external dso_local local_unnamed_addr global i8, align 1
@.str.10 = external hidden unnamed_addr constant [167 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

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

4:                                                ; preds = %0
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 24), align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %5, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %8 = load ptr, ptr @HBufferImage, align 8, !tbaa !19
  %.not = icmp eq ptr %7, %8
  br i1 %.not, label %22, label %9

9:                                                ; preds = %4
  %10 = add i64 %1, -1
  %11 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not13 = icmp eq i8 %11, 0
  %.pre = load ptr, ptr %6, align 8, !tbaa !16
  %.pre15 = ptrtoint ptr %.pre to i64
  %.pre16 = add i64 %.pre15, -32
  %.pre18 = inttoptr i64 %.pre16 to ptr
  br i1 %.not13, label %._crit_edge, label %12

12:                                               ; preds = %9
  %13 = load i64, ptr %.pre18, align 8, !tbaa !20
  %.not14 = icmp eq i64 %13, 1819043173
  br i1 %.not14, label %._crit_edge, label %14

14:                                               ; preds = %12
  tail call void @DebugAssert(ptr noundef nonnull @.str.10, i64 noundef 1594, ptr noundef nonnull @.str.11) #2
  %15 = load ptr, ptr %6, align 8, !tbaa !16
  br label %._crit_edge

._crit_edge:                                      ; preds = %9, %12, %14
  %16 = phi ptr [ %15, %14 ], [ %.pre18, %12 ], [ %.pre18, %9 ]
  %17 = getelementptr inbounds i8, ptr %16, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !21
  br label %21

19:                                               ; preds = %0
  %20 = add i64 %2, -1
  br label %21

21:                                               ; preds = %19, %._crit_edge
  %.010 = phi i64 [ %10, %._crit_edge ], [ %1, %19 ]
  %.0 = phi i64 [ %18, %._crit_edge ], [ %20, %19 ]
  tail call void @HBufferImageMovePosition(i64 noundef %.010, i64 noundef %.0, i8 noundef zeroext 1)
  br label %22

22:                                               ; preds = %4, %21
  ret i64 0
}

attributes #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 = { 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, !11, i64 64}
!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 72}
!15 = !{!9, !10, i64 24}
!16 = !{!17, !10, i64 40}
!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 = !{!9, !10, i64 0}
!20 = !{!17, !11, i64 0}
!21 = !{!17, !11, i64 24}


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