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

; 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
@FileBufferNeedRefresh = external dso_local global i8, align 1
@FileBufferOnlyLineNeedRefresh = external dso_local global i8, align 1
@.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 void @FreePool(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare zeroext i8 @DebugAssertEnabled() #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare ptr @RemoveEntryList(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollLeft() #2

; Function Attrs: nounwind uwtable
declare dso_local void @LineDeleteAt(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @LineCat(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferDoBackspace() #2 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = 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 !5
  store i64 %7, ptr %5, align 8, !tbaa !13
  %8 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !14
  store ptr %8, ptr %2, align 8, !tbaa !15
  %9 = load i64, ptr %5, align 8, !tbaa !13
  %10 = icmp eq i64 %9, 1
  br i1 %10, label %11, label %56

11:                                               ; preds = %0
  %12 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !16
  %13 = icmp eq i64 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %66

15:                                               ; preds = %11
  %16 = call i64 @FileBufferScrollLeft()
  %17 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !14
  store ptr %17, ptr %2, align 8, !tbaa !15
  %18 = load ptr, ptr %2, align 8, !tbaa !15
  %19 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %18, i32 0, i32 5
  %20 = getelementptr inbounds %struct._LIST_ENTRY, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !17
  store ptr %21, ptr %4, align 8, !tbaa !15
  %22 = call zeroext i8 @DebugAssertEnabled()
  %23 = zext i8 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %35

25:                                               ; preds = %15
  %26 = load ptr, ptr %4, align 8, !tbaa !15
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %29 = inttoptr i64 %28 to ptr
  %30 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %29, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !20
  %32 = icmp ne i64 %31, 1819043173
  br i1 %32, label %33, label %35

33:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 1802, ptr noundef @.str.2)
  %34 = load ptr, ptr %4, align 8, !tbaa !15
  br label %40

35:                                               ; preds = %25, %15
  %36 = load ptr, ptr %4, align 8, !tbaa !15
  %37 = ptrtoint ptr %36 to i64
  %38 = sub i64 %37, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %39 = inttoptr i64 %38 to ptr
  br label %40

40:                                               ; preds = %35, %33
  %41 = phi ptr [ %34, %33 ], [ %39, %35 ]
  store ptr %41, ptr %3, align 8, !tbaa !15
  %42 = load ptr, ptr %2, align 8, !tbaa !15
  %43 = load ptr, ptr %3, align 8, !tbaa !15
  call void @LineCat(ptr noundef %42, ptr noundef %43)
  %44 = load ptr, ptr %2, align 8, !tbaa !15
  %45 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !21
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %40
  store i64 -9223372036854775799, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %66

49:                                               ; preds = %40
  %50 = load ptr, ptr %3, align 8, !tbaa !15
  %51 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %50, i32 0, i32 5
  %52 = call ptr @RemoveEntryList(ptr noundef %51)
  %53 = load ptr, ptr %3, align 8, !tbaa !15
  call void @FreePool(ptr noundef %53)
  %54 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !22
  %55 = add i64 %54, -1
  store i64 %55, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !22
  store i8 1, ptr @FileBufferNeedRefresh, align 1, !tbaa !23
  store i8 0, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !23
  br label %61

56:                                               ; preds = %0
  %57 = load ptr, ptr %2, align 8, !tbaa !15
  %58 = load i64, ptr %5, align 8, !tbaa !13
  %59 = sub i64 %58, 1
  call void @LineDeleteAt(ptr noundef %57, i64 noundef %59)
  %60 = call i64 @FileBufferScrollLeft()
  store i8 1, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !23
  br label %61

61:                                               ; preds = %56, %49
  %62 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 9), align 8, !tbaa !24
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i8 1, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 9), align 8, !tbaa !24
  br label %65

65:                                               ; preds = %64, %61
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %66

66:                                               ; preds = %65, %48, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  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
  %67 = load i64, ptr %1, align 8
  ret i64 %67
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 64}
!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 = !{!11, !11, i64 0}
!14 = !{!6, !7, i64 112}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !11, i64 56}
!17 = !{!18, !7, i64 40}
!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 = !{!18, !11, i64 0}
!21 = !{!18, !7, i64 8}
!22 = !{!6, !11, i64 32}
!23 = !{!8, !8, i64 0}
!24 = !{!6, !8, i64 104}


; 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
@FileBufferNeedRefresh = external dso_local local_unnamed_addr global i8, align 1
@FileBufferOnlyLineNeedRefresh = external dso_local local_unnamed_addr global i8, align 1
@.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 void @FreePool(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @FileBufferScrollLeft() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @LineDeleteAt(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @LineCat(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @FileBufferDoBackspace() local_unnamed_addr #1 {
  %1 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 64), align 8, !tbaa !5
  %2 = icmp eq i64 %1, 1
  br i1 %2, label %3, label %24

3:                                                ; preds = %0
  %4 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !13
  %5 = icmp eq i64 %4, 1
  br i1 %5, label %31, label %6

6:                                                ; preds = %3
  %7 = tail call i64 @FileBufferScrollLeft()
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %8, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %11, 0
  %.pre = ptrtoint ptr %10 to i64
  %.pre15 = add i64 %.pre, -40
  %.pre17 = inttoptr i64 %.pre15 to ptr
  br i1 %.not, label %._crit_edge, label %12

12:                                               ; preds = %6
  %13 = load i64, ptr %.pre17, align 8, !tbaa !18
  %.not13 = icmp eq i64 %13, 1819043173
  br i1 %.not13, label %._crit_edge, label %14

14:                                               ; preds = %12
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 1802, ptr noundef nonnull @.str.2) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %6, %12, %14
  %15 = phi ptr [ %10, %14 ], [ %.pre17, %12 ], [ %.pre17, %6 ]
  tail call void @LineCat(ptr noundef nonnull %8, ptr noundef %15)
  %16 = getelementptr inbounds i8, ptr %8, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !19
  %18 = icmp eq ptr %17, null
  br i1 %18, label %31, label %19

19:                                               ; preds = %._crit_edge
  %20 = getelementptr inbounds i8, ptr %15, i64 40
  %21 = tail call ptr @RemoveEntryList(ptr noundef nonnull %20) #2
  tail call void @FreePool(ptr noundef %15) #2
  %22 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 32), align 8, !tbaa !20
  %23 = add i64 %22, -1
  store i64 %23, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 32), align 8, !tbaa !20
  store i8 1, ptr @FileBufferNeedRefresh, align 1, !tbaa !21
  br label %28

24:                                               ; preds = %0
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !14
  %26 = add i64 %1, -1
  tail call void @LineDeleteAt(ptr noundef %25, i64 noundef %26)
  %27 = tail call i64 @FileBufferScrollLeft()
  br label %28

28:                                               ; preds = %24, %19
  %storemerge = phi i8 [ 1, %24 ], [ 0, %19 ]
  store i8 %storemerge, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !21
  %29 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 104), align 8, !tbaa !22
  %.not14 = icmp eq i8 %29, 0
  br i1 %.not14, label %30, label %31

30:                                               ; preds = %28
  store i8 1, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 104), align 8, !tbaa !22
  br label %31

31:                                               ; preds = %28, %30, %._crit_edge, %3
  %.0 = phi i64 [ 0, %3 ], [ -9223372036854775799, %._crit_edge ], [ 0, %30 ], [ 0, %28 ]
  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, !11, i64 64}
!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 56}
!14 = !{!6, !7, i64 112}
!15 = !{!16, !7, i64 40}
!16 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !17, i64 40}
!17 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!18 = !{!16, !11, i64 0}
!19 = !{!16, !7, i64 8}
!20 = !{!6, !11, i64 32}
!21 = !{!8, !8, i64 0}
!22 = !{!6, !8, i64 104}


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