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

; 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 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 @FileBufferDoDelete() #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 ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !5
  store ptr %7, ptr %2, align 8, !tbaa !13
  %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 !14
  store i64 %8, ptr %5, align 8, !tbaa !15
  %9 = load i64, ptr %5, align 8, !tbaa !15
  %10 = load ptr, ptr %2, align 8, !tbaa !13
  %11 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %10, i32 0, i32 2
  %12 = load i64, ptr %11, align 8, !tbaa !16
  %13 = add i64 %12, 1
  %14 = icmp uge i64 %9, %13
  br i1 %14, label %15, label %62

15:                                               ; preds = %0
  %16 = load ptr, ptr %2, align 8, !tbaa !13
  %17 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %16, i32 0, i32 5
  %18 = getelementptr inbounds %struct._LIST_ENTRY, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !20
  %21 = icmp eq ptr %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %15
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %70

23:                                               ; preds = %15
  %24 = load ptr, ptr %2, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds %struct._LIST_ENTRY, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  store ptr %27, ptr %4, align 8, !tbaa !13
  %28 = call zeroext i8 @DebugAssertEnabled()
  %29 = zext i8 %28 to i32
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %41

31:                                               ; preds = %23
  %32 = load ptr, ptr %4, align 8, !tbaa !13
  %33 = ptrtoint ptr %32 to i64
  %34 = sub i64 %33, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %35 = inttoptr i64 %34 to ptr
  %36 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !21
  %38 = icmp ne i64 %37, 1819043173
  br i1 %38, label %39, label %41

39:                                               ; preds = %31
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 1970, ptr noundef @.str.2)
  %40 = load ptr, ptr %4, align 8, !tbaa !13
  br label %46

41:                                               ; preds = %31, %23
  %42 = load ptr, ptr %4, align 8, !tbaa !13
  %43 = ptrtoint ptr %42 to i64
  %44 = sub i64 %43, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %45 = inttoptr i64 %44 to ptr
  br label %46

46:                                               ; preds = %41, %39
  %47 = phi ptr [ %40, %39 ], [ %45, %41 ]
  store ptr %47, ptr %3, align 8, !tbaa !13
  %48 = load ptr, ptr %2, align 8, !tbaa !13
  %49 = load ptr, ptr %3, align 8, !tbaa !13
  call void @LineCat(ptr noundef %48, ptr noundef %49)
  %50 = load ptr, ptr %2, align 8, !tbaa !13
  %51 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !22
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %46
  store i64 -9223372036854775799, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %70

55:                                               ; preds = %46
  %56 = load ptr, ptr %3, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %56, i32 0, i32 5
  %58 = call ptr @RemoveEntryList(ptr noundef %57)
  %59 = load ptr, ptr %3, align 8, !tbaa !13
  call void @FreePool(ptr noundef %59)
  %60 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !23
  %61 = add i64 %60, -1
  store i64 %61, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !23
  store i8 1, ptr @FileBufferNeedRefresh, align 1, !tbaa !24
  store i8 0, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !24
  br label %65

62:                                               ; preds = %0
  %63 = load ptr, ptr %2, align 8, !tbaa !13
  %64 = load i64, ptr %5, align 8, !tbaa !15
  call void @LineDeleteAt(ptr noundef %63, i64 noundef %64)
  store i8 1, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !24
  br label %65

65:                                               ; preds = %62, %55
  %66 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 9), align 8, !tbaa !25
  %67 = icmp ne i8 %66, 0
  br i1 %67, label %69, label %68

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

69:                                               ; preds = %68, %65
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %70

70:                                               ; preds = %69, %54, %22
  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
  %71 = load i64, ptr %1, align 8
  ret i64 %71
}

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, !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 64}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 16}
!17 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !18, i64 40}
!18 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!19 = !{!17, !7, i64 40}
!20 = !{!6, !7, i64 16}
!21 = !{!17, !11, i64 0}
!22 = !{!17, !7, i64 8}
!23 = !{!6, !11, i64 32}
!24 = !{!8, !8, i64 0}
!25 = !{!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 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 @FileBufferDoDelete() 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 16
  %4 = load i64, ptr %3, align 8, !tbaa !14
  %5 = add i64 %4, 1
  %.not = icmp ult i64 %2, %5
  br i1 %.not, label %25, label %6

6:                                                ; preds = %0
  %7 = getelementptr inbounds i8, ptr %1, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !18
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %29, label %11

11:                                               ; preds = %6
  %12 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not16 = icmp eq i8 %12, 0
  %.pre = ptrtoint ptr %8 to i64
  %.pre19 = add i64 %.pre, -40
  %.pre21 = inttoptr i64 %.pre19 to ptr
  br i1 %.not16, label %._crit_edge, label %13

13:                                               ; preds = %11
  %14 = load i64, ptr %.pre21, align 8, !tbaa !19
  %.not17 = icmp eq i64 %14, 1819043173
  br i1 %.not17, label %._crit_edge, label %15

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

._crit_edge:                                      ; preds = %11, %13, %15
  %16 = phi ptr [ %8, %15 ], [ %.pre21, %13 ], [ %.pre21, %11 ]
  tail call void @LineCat(ptr noundef nonnull %1, ptr noundef %16)
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %19 = icmp eq ptr %18, null
  br i1 %19, label %29, label %20

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

25:                                               ; preds = %0
  tail call void @LineDeleteAt(ptr noundef nonnull %1, i64 noundef %2)
  br label %26

26:                                               ; preds = %25, %20
  %storemerge = phi i8 [ 1, %25 ], [ 0, %20 ]
  store i8 %storemerge, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !22
  %27 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 104), align 8, !tbaa !23
  %.not18 = icmp eq i8 %27, 0
  br i1 %.not18, label %28, label %29

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

29:                                               ; preds = %26, %28, %._crit_edge, %6
  %.0 = phi i64 [ 0, %6 ], [ -9223372036854775799, %._crit_edge ], [ 0, %28 ], [ 0, %26 ]
  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, !11, i64 16}
!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 = !{!15, !7, i64 40}
!18 = !{!6, !7, i64 16}
!19 = !{!15, !11, i64 0}
!20 = !{!15, !7, i64 8}
!21 = !{!6, !11, i64 32}
!22 = !{!8, !8, i64 0}
!23 = !{!6, !8, i64 104}


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