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

; 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.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }
%struct._EFI_EDITOR_LINE = type { i64, ptr, i64, i64, i32, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }

@FileBuffer = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = 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

declare zeroext i8 @DebugAssertEnabled() #1

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

; 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 @FileBufferMovePosition(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferScrollUp() #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
  %6 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !5
  store ptr %6, ptr %2, align 8, !tbaa !13
  %7 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !14
  store i64 %7, ptr %3, align 8, !tbaa !15
  %8 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), i32 0, i32 1), align 8, !tbaa !16
  store i64 %8, ptr %4, align 8, !tbaa !15
  %9 = load ptr, ptr %2, align 8, !tbaa !13
  %10 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %9, i32 0, i32 5
  %11 = getelementptr inbounds %struct._LIST_ENTRY, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  %13 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !20
  %14 = icmp ne ptr %12, %13
  br i1 %14, label %15, label %58

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

21:                                               ; preds = %15
  %22 = load ptr, ptr %2, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %22, i32 0, i32 5
  %24 = getelementptr inbounds %struct._LIST_ENTRY, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = ptrtoint ptr %25 to i64
  %27 = sub i64 %26, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %28 = inttoptr i64 %27 to ptr
  %29 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !21
  %31 = icmp ne i64 %30, 1819043173
  br i1 %31, label %32, label %37

32:                                               ; preds = %21
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 2276, ptr noundef @.str.2)
  %33 = load ptr, ptr %2, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %33, i32 0, i32 5
  %35 = getelementptr inbounds %struct._LIST_ENTRY, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  br label %45

37:                                               ; preds = %21, %15
  %38 = load ptr, ptr %2, align 8, !tbaa !13
  %39 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds %struct._LIST_ENTRY, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = ptrtoint ptr %41 to i64
  %43 = sub i64 %42, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %44 = inttoptr i64 %43 to ptr
  br label %45

45:                                               ; preds = %37, %32
  %46 = phi ptr [ %36, %32 ], [ %44, %37 ]
  store ptr %46, ptr %2, align 8, !tbaa !13
  %47 = load i64, ptr %4, align 8, !tbaa !15
  %48 = load ptr, ptr %2, align 8, !tbaa !13
  %49 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !22
  %51 = icmp ugt i64 %47, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %45
  %53 = load ptr, ptr %2, align 8, !tbaa !13
  %54 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %53, i32 0, i32 2
  %55 = load i64, ptr %54, align 8, !tbaa !22
  %56 = add i64 %55, 1
  store i64 %56, ptr %4, align 8, !tbaa !15
  br label %57

57:                                               ; preds = %52, %45
  br label %59

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

59:                                               ; preds = %57
  %60 = load i64, ptr %3, align 8, !tbaa !15
  %61 = load i64, ptr %4, align 8, !tbaa !15
  call void @FileBufferMovePosition(i64 noundef %60, i64 noundef %61)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %62

62:                                               ; preds = %59, %58
  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
  %63 = load i64, ptr %1, align 8
  ret i64 %63
}

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


; 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.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }

@FileBuffer = external dso_local local_unnamed_addr global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = 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 @FileBufferMovePosition(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @FileBufferScrollUp() local_unnamed_addr #1 {
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !5
  %2 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 64), align 8, !tbaa !13
  %3 = getelementptr inbounds i8, ptr %1, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !14
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !17
  %.not = icmp eq ptr %4, %5
  br i1 %.not, label %19, label %6

6:                                                ; preds = %0
  %7 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !18
  %8 = add i64 %7, -1
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not13 = icmp eq i8 %9, 0
  %.pre = load ptr, ptr %3, align 8, !tbaa !14
  %.pre15 = ptrtoint ptr %.pre to i64
  %.pre16 = add i64 %.pre15, -40
  %.pre18 = inttoptr i64 %.pre16 to ptr
  br i1 %.not13, label %._crit_edge, label %10

10:                                               ; preds = %6
  %11 = load i64, ptr %.pre18, align 8, !tbaa !19
  %.not14 = icmp eq i64 %11, 1819043173
  br i1 %.not14, label %._crit_edge, label %12

12:                                               ; preds = %10
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 2276, ptr noundef nonnull @.str.2) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !14
  br label %._crit_edge

._crit_edge:                                      ; preds = %6, %10, %12
  %14 = phi ptr [ %13, %12 ], [ %.pre18, %10 ], [ %.pre18, %6 ]
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !20
  %17 = icmp ugt i64 %2, %16
  %18 = add i64 %16, 1
  %spec.select = select i1 %17, i64 %18, i64 %2
  tail call void @FileBufferMovePosition(i64 noundef %8, i64 noundef %spec.select)
  br label %19

19:                                               ; preds = %0, %._crit_edge
  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, !7, i64 112}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !12, i64 56, !12, i64 72, !12, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!6, !11, i64 64}
!14 = !{!15, !7, i64 48}
!15 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !16, i64 40}
!16 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !11, i64 56}
!19 = !{!15, !11, i64 0}
!20 = !{!15, !11, i64 16}


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