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

; 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_GLOBAL_EDITOR = type { ptr, %union.EFI_EDITOR_COLOR_UNION, %struct.EFI_EDITOR_POSITION, ptr, i8, ptr, i32, i32 }
%union.EFI_EDITOR_COLOR_UNION = type { 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
@MainEditor = external global %struct.EFI_EDITOR_GLOBAL_EDITOR, align 8
@.str.25 = external hidden unnamed_addr constant [35 x i32], align 4

; 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

declare i64 @StatusBarSetStatusString(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferPasteLine() #2 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, 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_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 3), align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %0
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %79

10:                                               ; preds = %0
  %11 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 11), align 2, !tbaa !13
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = call i64 @StatusBarSetStatusString(ptr noundef @.str.25)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %79

15:                                               ; preds = %10
  %16 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 3), align 8, !tbaa !5
  %17 = call ptr @LineDup(ptr noundef %16)
  store ptr %17, ptr %3, align 8, !tbaa !15
  %18 = load ptr, ptr %3, align 8, !tbaa !15
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i64 -9223372036854775799, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %79

21:                                               ; preds = %15
  %22 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !16
  store ptr %22, ptr %2, align 8, !tbaa !15
  %23 = load ptr, ptr %2, align 8, !tbaa !15
  %24 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %23, i32 0, i32 5
  %25 = getelementptr inbounds %struct._LIST_ENTRY, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load ptr, ptr %3, align 8, !tbaa !15
  %28 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds %struct._LIST_ENTRY, ptr %28, i32 0, i32 1
  store ptr %26, ptr %29, align 8, !tbaa !17
  %30 = load ptr, ptr %2, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %3, align 8, !tbaa !15
  %33 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %32, i32 0, i32 5
  %34 = getelementptr inbounds %struct._LIST_ENTRY, ptr %33, i32 0, i32 0
  store ptr %31, ptr %34, align 8, !tbaa !20
  %35 = load ptr, ptr %3, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %2, align 8, !tbaa !15
  %38 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %37, i32 0, i32 5
  %39 = getelementptr inbounds %struct._LIST_ENTRY, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = getelementptr inbounds %struct._LIST_ENTRY, ptr %40, i32 0, i32 0
  store ptr %36, ptr %41, align 8, !tbaa !21
  %42 = load ptr, ptr %3, align 8, !tbaa !15
  %43 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %2, align 8, !tbaa !15
  %45 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %44, i32 0, i32 5
  %46 = getelementptr inbounds %struct._LIST_ENTRY, ptr %45, i32 0, i32 1
  store ptr %43, ptr %46, align 8, !tbaa !17
  %47 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !22
  %48 = add i64 %47, 1
  store i64 %48, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !22
  %49 = load ptr, ptr %3, align 8, !tbaa !15
  store ptr %49, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !16
  %50 = call zeroext i8 @DebugAssertEnabled()
  %51 = zext i8 %50 to i32
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %67

53:                                               ; preds = %21
  %54 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !23
  %55 = getelementptr inbounds %struct._LIST_ENTRY, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !21
  %57 = ptrtoint ptr %56 to i64
  %58 = sub i64 %57, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %59 = inttoptr i64 %58 to ptr
  %60 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %60, align 8, !tbaa !24
  %62 = icmp ne i64 %61, 1819043173
  br i1 %62, label %63, label %67

63:                                               ; preds = %53
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 2928, ptr noundef @.str.2)
  %64 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !23
  %65 = getelementptr inbounds %struct._LIST_ENTRY, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !21
  br label %74

67:                                               ; preds = %53, %21
  %68 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !23
  %69 = getelementptr inbounds %struct._LIST_ENTRY, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = ptrtoint ptr %70 to i64
  %72 = sub i64 %71, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %73 = inttoptr i64 %72 to ptr
  br label %74

74:                                               ; preds = %67, %63
  %75 = phi ptr [ %66, %63 ], [ %73, %67 ]
  store ptr %75, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 3), align 8, !tbaa !25
  store i64 1, ptr %5, align 8, !tbaa !26
  %76 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !27
  store i64 %76, ptr %4, align 8, !tbaa !26
  %77 = load i64, ptr %4, align 8, !tbaa !26
  %78 = load i64, ptr %5, align 8, !tbaa !26
  call void @FileBufferMovePosition(i64 noundef %77, i64 noundef %78)
  store i8 1, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 9), align 8, !tbaa !28
  store i8 1, ptr @FileBufferNeedRefresh, align 1, !tbaa !29
  store i8 0, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !29
  store i64 0, ptr %1, align 8
  store i32 1, ptr %6, align 4
  br label %79

79:                                               ; preds = %74, %20, %13, %9
  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
  %80 = load i64, ptr %1, align 8
  ret i64 %80
}

declare ptr @LineDup(ptr noundef) #1

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 32}
!6 = !{!"", !7, i64 0, !8, i64 8, !10, i64 16, !7, i64 32, !8, i64 40, !7, i64 48, !12, i64 56, !12, i64 60}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !8, i64 106}
!14 = !{!"", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !10, i64 40, !10, i64 56, !10, i64 72, !10, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!15 = !{!7, !7, i64 0}
!16 = !{!14, !7, i64 112}
!17 = !{!18, !7, i64 48}
!18 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !19, i64 40}
!19 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!20 = !{!18, !7, i64 40}
!21 = !{!19, !7, i64 0}
!22 = !{!14, !11, i64 32}
!23 = !{!14, !7, i64 16}
!24 = !{!18, !11, i64 0}
!25 = !{!14, !7, i64 24}
!26 = !{!11, !11, i64 0}
!27 = !{!14, !11, i64 56}
!28 = !{!14, !8, i64 104}
!29 = !{!8, !8, 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.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_GLOBAL_EDITOR = type { ptr, %union.EFI_EDITOR_COLOR_UNION, %struct.EFI_EDITOR_POSITION, ptr, i8, ptr, i32, i32 }
%union.EFI_EDITOR_COLOR_UNION = type { 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
@MainEditor = external local_unnamed_addr global %struct.EFI_EDITOR_GLOBAL_EDITOR, align 8
@.str.25 = external hidden unnamed_addr constant [35 x i32], align 4

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare i64 @StatusBarSetStatusString(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 range(i64 -9223372036854775799, 1) i64 @FileBufferPasteLine() local_unnamed_addr #1 {
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 32), align 8, !tbaa !5
  %2 = icmp eq ptr %1, null
  br i1 %2, label %27, label %3

3:                                                ; preds = %0
  %4 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 106), align 2, !tbaa !13
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %7, label %5

5:                                                ; preds = %3
  %6 = tail call i64 @StatusBarSetStatusString(ptr noundef nonnull @.str.25) #2
  br label %27

7:                                                ; preds = %3
  %8 = tail call ptr @LineDup(ptr noundef nonnull %1) #2
  %9 = icmp eq ptr %8, null
  br i1 %9, label %27, label %10

10:                                               ; preds = %7
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %11, i64 40
  %13 = getelementptr inbounds i8, ptr %11, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %8, i64 40
  %16 = getelementptr inbounds i8, ptr %8, i64 48
  store ptr %14, ptr %16, align 8, !tbaa !16
  store ptr %12, ptr %15, align 8, !tbaa !19
  store ptr %15, ptr %14, align 8, !tbaa !20
  store ptr %15, ptr %13, align 8, !tbaa !16
  %17 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 32), align 8, !tbaa !21
  %18 = add i64 %17, 1
  store i64 %18, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 32), align 8, !tbaa !21
  store ptr %8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !15
  %19 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not14 = icmp eq i8 %19, 0
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !22
  %.pre16 = load ptr, ptr %.pre, align 8, !tbaa !20
  %.pre17 = ptrtoint ptr %.pre16 to i64
  %.pre18 = add i64 %.pre17, -40
  %.pre20 = inttoptr i64 %.pre18 to ptr
  br i1 %.not14, label %._crit_edge, label %20

20:                                               ; preds = %10
  %21 = load i64, ptr %.pre20, align 8, !tbaa !23
  %.not15 = icmp eq i64 %21, 1819043173
  br i1 %.not15, label %._crit_edge, label %22

22:                                               ; preds = %20
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 2928, ptr noundef nonnull @.str.2) #2
  %23 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !22
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  br label %._crit_edge

._crit_edge:                                      ; preds = %10, %20, %22
  %25 = phi ptr [ %24, %22 ], [ %.pre20, %20 ], [ %.pre20, %10 ]
  store ptr %25, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 24), align 8, !tbaa !24
  %26 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !25
  tail call void @FileBufferMovePosition(i64 noundef %26, i64 noundef 1)
  store i8 1, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 104), align 8, !tbaa !26
  store i8 1, ptr @FileBufferNeedRefresh, align 1, !tbaa !27
  store i8 0, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !27
  br label %27

27:                                               ; preds = %7, %0, %._crit_edge, %5
  %.0 = phi i64 [ 0, %5 ], [ 0, %._crit_edge ], [ 0, %0 ], [ -9223372036854775799, %7 ]
  ret i64 %.0
}

declare ptr @LineDup(ptr noundef) local_unnamed_addr #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 32}
!6 = !{!"", !7, i64 0, !8, i64 8, !10, i64 16, !7, i64 32, !8, i64 40, !7, i64 48, !12, i64 56, !12, i64 60}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !8, i64 106}
!14 = !{!"", !7, i64 0, !12, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !10, i64 40, !10, i64 56, !10, i64 72, !10, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !7, i64 112}
!15 = !{!14, !7, i64 112}
!16 = !{!17, !7, i64 48}
!17 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !18, i64 40}
!18 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!19 = !{!17, !7, i64 40}
!20 = !{!18, !7, i64 0}
!21 = !{!14, !11, i64 32}
!22 = !{!14, !7, i64 16}
!23 = !{!17, !11, i64 0}
!24 = !{!14, !7, i64 24}
!25 = !{!14, !11, i64 56}
!26 = !{!14, !8, i64 104}
!27 = !{!8, !8, i64 0}


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