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

; 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_SYSTEM_TABLE = type { %struct.EFI_TABLE_HEADER, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct._EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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
@FileBufferBackupVar = 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
@gST = external global ptr, align 8
@EditorFirst = external global 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 ptr @MoveLine(i64 noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferRefresh() #2 {
  %1 = alloca i64, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, 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 i8, ptr @EditorFirst, align 1, !tbaa !5
  %7 = icmp ne i8 %6, 0
  br i1 %7, label %26, label %8

8:                                                ; preds = %0
  %9 = load i8, ptr @FileBufferNeedRefresh, align 1, !tbaa !5
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %25, label %11

11:                                               ; preds = %8
  %12 = load i8, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !5
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %25, label %14

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

18:                                               ; preds = %14
  %19 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 8), i32 0, i32 1), align 8, !tbaa !14
  %20 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 8), i32 0, i32 1), align 8, !tbaa !14
  %21 = icmp eq i64 %19, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %18
  %23 = call i64 @FileBufferRestoreMousePosition()
  %24 = call i64 @FileBufferRestorePosition()
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %154

25:                                               ; preds = %18, %14, %11, %8
  br label %26

26:                                               ; preds = %25, %0
  %27 = load ptr, ptr @gST, align 8, !tbaa !15
  %28 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %27, i32 0, i32 6
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = getelementptr inbounds %struct._EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL, ptr %29, i32 0, i32 8
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = load ptr, ptr @gST, align 8, !tbaa !15
  %33 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %32, i32 0, i32 6
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = call i64 %31(ptr noundef %34, i8 noundef zeroext 0)
  %36 = load i8, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !5
  %37 = zext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %54

39:                                               ; preds = %26
  %40 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 8), align 8, !tbaa !8
  %41 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 8), align 8, !tbaa !8
  %42 = icmp eq i64 %40, %41
  br i1 %42, label %43, label %54

43:                                               ; preds = %39
  %44 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 8), i32 0, i32 1), align 8, !tbaa !14
  %45 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 8), i32 0, i32 1), align 8, !tbaa !14
  %46 = icmp eq i64 %44, %45
  br i1 %46, label %47, label %54

47:                                               ; preds = %43
  %48 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 5), align 8, !tbaa !21
  %49 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !22
  %50 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !24
  call void @EditorClearLine(i64 noundef %48, i64 noundef %49, i64 noundef %50)
  %51 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 12), align 8, !tbaa !25
  %52 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 5), align 8, !tbaa !21
  %53 = call i64 @FileBufferPrintLine(ptr noundef %51, i64 noundef %52)
  br label %142

54:                                               ; preds = %43, %39, %26
  %55 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 3), align 8, !tbaa !26
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %69

57:                                               ; preds = %54
  %58 = call i64 @FileBufferRestoreMousePosition()
  %59 = call i64 @FileBufferRestorePosition()
  %60 = load ptr, ptr @gST, align 8, !tbaa !15
  %61 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %60, i32 0, i32 6
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = getelementptr inbounds %struct._EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL, ptr %62, i32 0, i32 8
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = load ptr, ptr @gST, align 8, !tbaa !15
  %66 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %65, i32 0, i32 6
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = call i64 %64(ptr noundef %67, i8 noundef zeroext 1)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %154

69:                                               ; preds = %54
  %70 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 8), align 8, !tbaa !8
  %71 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), align 8, !tbaa !27
  %72 = sub i64 %70, %71
  %73 = call ptr @MoveLine(i64 noundef %72)
  store ptr %73, ptr %3, align 8, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !15
  %75 = icmp eq ptr %74, null
  br i1 %75, label %76, label %86

76:                                               ; preds = %69
  %77 = load ptr, ptr @gST, align 8, !tbaa !15
  %78 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %77, i32 0, i32 6
  %79 = load ptr, ptr %78, align 8, !tbaa !16
  %80 = getelementptr inbounds %struct._EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL, ptr %79, i32 0, i32 8
  %81 = load ptr, ptr %80, align 8, !tbaa !19
  %82 = load ptr, ptr @gST, align 8, !tbaa !15
  %83 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %82, i32 0, i32 6
  %84 = load ptr, ptr %83, align 8, !tbaa !16
  %85 = call i64 %81(ptr noundef %84, i8 noundef zeroext 1)
  store i64 -9223372036854775807, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %154

86:                                               ; preds = %69
  %87 = load ptr, ptr %3, align 8, !tbaa !15
  %88 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %87, i32 0, i32 5
  store ptr %88, ptr %2, align 8, !tbaa !15
  store i64 2, ptr %4, align 8, !tbaa !28
  br label %89

89:                                               ; preds = %127, %86
  %90 = call zeroext i8 @DebugAssertEnabled()
  %91 = zext i8 %90 to i32
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %93, label %103

93:                                               ; preds = %89
  %94 = load ptr, ptr %2, align 8, !tbaa !15
  %95 = ptrtoint ptr %94 to i64
  %96 = sub i64 %95, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %97 = inttoptr i64 %96 to ptr
  %98 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %97, i32 0, i32 0
  %99 = load i64, ptr %98, align 8, !tbaa !29
  %100 = icmp ne i64 %99, 1819043173
  br i1 %100, label %101, label %103

101:                                              ; preds = %93
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 636, ptr noundef @.str.2)
  %102 = load ptr, ptr %2, align 8, !tbaa !15
  br label %108

103:                                              ; preds = %93, %89
  %104 = load ptr, ptr %2, align 8, !tbaa !15
  %105 = ptrtoint ptr %104 to i64
  %106 = sub i64 %105, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %107 = inttoptr i64 %106 to ptr
  br label %108

108:                                              ; preds = %103, %101
  %109 = phi ptr [ %102, %101 ], [ %107, %103 ]
  store ptr %109, ptr %3, align 8, !tbaa !15
  %110 = load ptr, ptr %3, align 8, !tbaa !15
  %111 = load i64, ptr %4, align 8, !tbaa !28
  %112 = call i64 @FileBufferPrintLine(ptr noundef %110, i64 noundef %111)
  %113 = load ptr, ptr %2, align 8, !tbaa !15
  %114 = getelementptr inbounds %struct._LIST_ENTRY, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !32
  store ptr %115, ptr %2, align 8, !tbaa !15
  %116 = load i64, ptr %4, align 8, !tbaa !28
  %117 = add i64 %116, 1
  store i64 %117, ptr %4, align 8, !tbaa !28
  br label %118

118:                                              ; preds = %108
  %119 = load ptr, ptr %2, align 8, !tbaa !15
  %120 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !33
  %121 = icmp ne ptr %119, %120
  br i1 %121, label %122, label %127

122:                                              ; preds = %118
  %123 = load i64, ptr %4, align 8, !tbaa !28
  %124 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !24
  %125 = sub i64 %124, 1
  %126 = icmp ule i64 %123, %125
  br label %127

127:                                              ; preds = %122, %118
  %128 = phi i1 [ false, %118 ], [ %126, %122 ]
  br i1 %128, label %89, label %129, !llvm.loop !34

129:                                              ; preds = %127
  br label %130

130:                                              ; preds = %135, %129
  %131 = load i64, ptr %4, align 8, !tbaa !28
  %132 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !24
  %133 = sub i64 %132, 1
  %134 = icmp ule i64 %131, %133
  br i1 %134, label %135, label %141

135:                                              ; preds = %130
  %136 = load i64, ptr %4, align 8, !tbaa !28
  %137 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_POSITION, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), i32 0, i32 1), align 8, !tbaa !22
  %138 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_GLOBAL_EDITOR, ptr @MainEditor, i32 0, i32 2), align 8, !tbaa !24
  call void @EditorClearLine(i64 noundef %136, i64 noundef %137, i64 noundef %138)
  %139 = load i64, ptr %4, align 8, !tbaa !28
  %140 = add i64 %139, 1
  store i64 %140, ptr %4, align 8, !tbaa !28
  br label %130, !llvm.loop !36

141:                                              ; preds = %130
  br label %142

142:                                              ; preds = %141, %47
  %143 = call i64 @FileBufferRestoreMousePosition()
  %144 = call i64 @FileBufferRestorePosition()
  store i8 0, ptr @FileBufferNeedRefresh, align 1, !tbaa !5
  store i8 0, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !5
  %145 = load ptr, ptr @gST, align 8, !tbaa !15
  %146 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %145, i32 0, i32 6
  %147 = load ptr, ptr %146, align 8, !tbaa !16
  %148 = getelementptr inbounds %struct._EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL, ptr %147, i32 0, i32 8
  %149 = load ptr, ptr %148, align 8, !tbaa !19
  %150 = load ptr, ptr @gST, align 8, !tbaa !15
  %151 = getelementptr inbounds %struct.EFI_SYSTEM_TABLE, ptr %150, i32 0, i32 6
  %152 = load ptr, ptr %151, align 8, !tbaa !16
  %153 = call i64 %149(ptr noundef %152, i8 noundef zeroext 1)
  store i64 0, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %154

154:                                              ; preds = %142, %76, %57, %22
  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
  %155 = load i64, ptr %1, align 8
  ret i64 %155
}

declare void @EditorClearLine(i64 noundef, i64 noundef, i64 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !12, i64 88}
!9 = !{!"", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !13, i64 40, !13, i64 56, !13, i64 72, !13, i64 88, !6, i64 104, !6, i64 105, !6, i64 106, !10, i64 112}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"long long", !6, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 8}
!14 = !{!9, !12, i64 96}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !10, i64 64}
!17 = !{!"", !18, i64 0, !10, i64 24, !11, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !12, i64 104, !10, i64 112}
!18 = !{!"", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!19 = !{!20, !10, i64 64}
!20 = !{!"_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!21 = !{!9, !12, i64 40}
!22 = !{!23, !12, i64 24}
!23 = !{!"", !10, i64 0, !6, i64 8, !13, i64 16, !10, i64 32, !6, i64 40, !10, i64 48, !11, i64 56, !11, i64 60}
!24 = !{!23, !12, i64 16}
!25 = !{!9, !10, i64 112}
!26 = !{!9, !10, i64 24}
!27 = !{!9, !12, i64 56}
!28 = !{!12, !12, i64 0}
!29 = !{!30, !12, i64 0}
!30 = !{!"_EFI_EDITOR_LINE", !12, i64 0, !10, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !31, i64 40}
!31 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!32 = !{!31, !10, i64 0}
!33 = !{!9, !10, i64 16}
!34 = distinct !{!34, !35}
!35 = !{!"llvm.loop.mustprogress"}
!36 = distinct !{!36, !35}


; 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
@FileBufferBackupVar = 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
@gST = external local_unnamed_addr global ptr, align 8
@EditorFirst = external local_unnamed_addr global 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 ptr @MoveLine(i64 noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775807, 1) i64 @FileBufferRefresh() local_unnamed_addr #1 {
  %1 = load i8, ptr @EditorFirst, align 1, !tbaa !5
  %.not = icmp eq i8 %1, 0
  br i1 %.not, label %2, label %18

2:                                                ; preds = %0
  %3 = load i8, ptr @FileBufferNeedRefresh, align 1, !tbaa !5
  %4 = icmp ne i8 %3, 0
  %5 = load i8, ptr @FileBufferOnlyLineNeedRefresh, align 1
  %6 = icmp ne i8 %5, 0
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %18, label %7

7:                                                ; preds = %2
  %8 = load i64, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 88), align 8, !tbaa !8
  %9 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 88), align 8, !tbaa !8
  %10 = icmp eq i64 %8, %9
  br i1 %10, label %11, label %18

11:                                               ; preds = %7
  %12 = load i64, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 96), align 8, !tbaa !14
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 96), align 8, !tbaa !14
  %14 = icmp eq i64 %12, %13
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = tail call i64 @FileBufferRestoreMousePosition()
  %17 = tail call i64 @FileBufferRestorePosition()
  br label %96

18:                                               ; preds = %2, %7, %11, %0
  %19 = load ptr, ptr @gST, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %19, i64 64
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %21, i64 64
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  %24 = tail call i64 %23(ptr noundef %21, i8 noundef zeroext 0) #2
  %25 = load i8, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !5
  %.not20 = icmp eq i8 %25, 0
  br i1 %.not20, label %41, label %26

26:                                               ; preds = %18
  %27 = load i64, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 88), align 8, !tbaa !8
  %28 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 88), align 8, !tbaa !8
  %29 = icmp eq i64 %27, %28
  br i1 %29, label %30, label %41

30:                                               ; preds = %26
  %31 = load i64, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 96), align 8, !tbaa !14
  %32 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 96), align 8, !tbaa !14
  %33 = icmp eq i64 %31, %32
  br i1 %33, label %34, label %41

34:                                               ; preds = %30
  %35 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 40), align 8, !tbaa !21
  %36 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 24), align 8, !tbaa !22
  %37 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 16), align 8, !tbaa !24
  tail call void @EditorClearLine(i64 noundef %35, i64 noundef %36, i64 noundef %37) #2
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 112), align 8, !tbaa !25
  %39 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 40), align 8, !tbaa !21
  %40 = tail call i64 @FileBufferPrintLine(ptr noundef %38, i64 noundef %39)
  br label %.loopexit

41:                                               ; preds = %30, %26, %18
  %42 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 24), align 8, !tbaa !26
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %53

44:                                               ; preds = %41
  %45 = tail call i64 @FileBufferRestoreMousePosition()
  %46 = tail call i64 @FileBufferRestorePosition()
  %47 = load ptr, ptr @gST, align 8, !tbaa !15
  %48 = getelementptr inbounds i8, ptr %47, i64 64
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds i8, ptr %49, i64 64
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  %52 = tail call i64 %51(ptr noundef %49, i8 noundef zeroext 1) #2
  br label %96

53:                                               ; preds = %41
  %54 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 88), align 8, !tbaa !8
  %55 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 56), align 8, !tbaa !27
  %56 = sub i64 %54, %55
  %57 = tail call ptr @MoveLine(i64 noundef %56)
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %66

59:                                               ; preds = %53
  %60 = load ptr, ptr @gST, align 8, !tbaa !15
  %61 = getelementptr inbounds i8, ptr %60, i64 64
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = getelementptr inbounds i8, ptr %62, i64 64
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = tail call i64 %64(ptr noundef %62, i8 noundef zeroext 1) #2
  br label %96

66:                                               ; preds = %53
  %67 = getelementptr inbounds i8, ptr %57, i64 40
  br label %68

68:                                               ; preds = %._crit_edge, %66
  %.015 = phi ptr [ %67, %66 ], [ %75, %._crit_edge ]
  %.0 = phi i64 [ 2, %66 ], [ %76, %._crit_edge ]
  %69 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not21 = icmp eq i8 %69, 0
  %.pre = ptrtoint ptr %.015 to i64
  %.pre26 = add i64 %.pre, -40
  %.pre28 = inttoptr i64 %.pre26 to ptr
  br i1 %.not21, label %._crit_edge, label %70

70:                                               ; preds = %68
  %71 = load i64, ptr %.pre28, align 8, !tbaa !28
  %.not22 = icmp eq i64 %71, 1819043173
  br i1 %.not22, label %._crit_edge, label %72

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

._crit_edge:                                      ; preds = %68, %70, %72
  %73 = phi ptr [ %.015, %72 ], [ %.pre28, %70 ], [ %.pre28, %68 ]
  %74 = tail call i64 @FileBufferPrintLine(ptr noundef %73, i64 noundef %.0)
  %75 = load ptr, ptr %.015, align 8, !tbaa !31
  %76 = add i64 %.0, 1
  %77 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !32
  %78 = icmp ne ptr %75, %77
  %79 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 16), align 8
  %80 = add i64 %79, -1
  %81 = icmp ule i64 %76, %80
  %82 = select i1 %78, i1 %81, i1 false
  br i1 %82, label %68, label %.preheader, !llvm.loop !33

.preheader:                                       ; preds = %._crit_edge
  %.not2324 = icmp ugt i64 %76, %80
  br i1 %.not2324, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %83 = phi i64 [ %86, %.lr.ph ], [ %79, %.preheader ]
  %.125 = phi i64 [ %85, %.lr.ph ], [ %76, %.preheader ]
  %84 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 24), align 8, !tbaa !22
  tail call void @EditorClearLine(i64 noundef %.125, i64 noundef %84, i64 noundef %83) #2
  %85 = add i64 %.125, 1
  %86 = load i64, ptr getelementptr inbounds (i8, ptr @MainEditor, i64 16), align 8, !tbaa !24
  %87 = add i64 %86, -1
  %.not23 = icmp ugt i64 %85, %87
  br i1 %.not23, label %.loopexit, label %.lr.ph, !llvm.loop !35

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %34
  %88 = tail call i64 @FileBufferRestoreMousePosition()
  %89 = tail call i64 @FileBufferRestorePosition()
  store i8 0, ptr @FileBufferNeedRefresh, align 1, !tbaa !5
  store i8 0, ptr @FileBufferOnlyLineNeedRefresh, align 1, !tbaa !5
  %90 = load ptr, ptr @gST, align 8, !tbaa !15
  %91 = getelementptr inbounds i8, ptr %90, i64 64
  %92 = load ptr, ptr %91, align 8, !tbaa !16
  %93 = getelementptr inbounds i8, ptr %92, i64 64
  %94 = load ptr, ptr %93, align 8, !tbaa !19
  %95 = tail call i64 %94(ptr noundef %92, i8 noundef zeroext 1) #2
  br label %96

96:                                               ; preds = %.loopexit, %59, %44, %15
  %.016 = phi i64 [ 0, %.loopexit ], [ 0, %44 ], [ -9223372036854775807, %59 ], [ 0, %15 ]
  ret i64 %.016
}

declare void @EditorClearLine(i64 noundef, i64 noundef, i64 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !12, i64 88}
!9 = !{!"", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !13, i64 40, !13, i64 56, !13, i64 72, !13, i64 88, !6, i64 104, !6, i64 105, !6, i64 106, !10, i64 112}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"long long", !6, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 8}
!14 = !{!9, !12, i64 96}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !10, i64 64}
!17 = !{!"", !18, i64 0, !10, i64 24, !11, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !12, i64 104, !10, i64 112}
!18 = !{!"", !12, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!19 = !{!20, !10, i64 64}
!20 = !{!"_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!21 = !{!9, !12, i64 40}
!22 = !{!23, !12, i64 24}
!23 = !{!"", !10, i64 0, !6, i64 8, !13, i64 16, !10, i64 32, !6, i64 40, !10, i64 48, !11, i64 56, !11, i64 60}
!24 = !{!23, !12, i64 16}
!25 = !{!9, !10, i64 112}
!26 = !{!9, !10, i64 24}
!27 = !{!9, !12, i64 56}
!28 = !{!29, !12, i64 0}
!29 = !{!"_EFI_EDITOR_LINE", !12, i64 0, !10, i64 8, !12, i64 16, !12, i64 24, !11, i64 32, !30, i64 40}
!30 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!31 = !{!30, !10, i64 0}
!32 = !{!9, !10, i64 16}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}
!35 = distinct !{!35, !34}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass