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

; 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 }

@FileBuffer = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@FileBufferBackupVar = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferCleanup() #2 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  br label %2

2:                                                ; preds = %0
  %3 = load ptr, ptr @FileBuffer, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = load ptr, ptr @FileBuffer, align 8, !tbaa !5
  call void @FreePool(ptr noundef %6)
  store ptr null, ptr @FileBuffer, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %5, %2
  br label %8

8:                                                ; preds = %7
  br label %9

9:                                                ; preds = %8
  %10 = call i64 @FileBufferFreeLines()
  store i64 %10, ptr %1, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !14
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !14
  call void @FreePool(ptr noundef %15)
  store ptr null, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !14
  br label %16

16:                                               ; preds = %14, %11
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  store ptr null, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !14
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr @FileBufferBackupVar, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  %23 = load ptr, ptr @FileBufferBackupVar, align 8, !tbaa !5
  call void @FreePool(ptr noundef %23)
  store ptr null, ptr @FileBufferBackupVar, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %22, %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load i64, ptr %1, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret i64 %27
}

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 0}
!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 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
@FileBufferBackupVar = external dso_local local_unnamed_addr global %struct.EFI_EDITOR_FILE_BUFFER, align 8

declare void @FreePool(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferCleanup() local_unnamed_addr #1 {
  %1 = load ptr, ptr @FileBuffer, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %2

2:                                                ; preds = %0
  tail call void @FreePool(ptr noundef nonnull %1) #2
  store ptr null, ptr @FileBuffer, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %2, %0
  %4 = tail call i64 @FileBufferFreeLines()
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !13
  %.not3 = icmp eq ptr %5, null
  br i1 %.not3, label %7, label %6

6:                                                ; preds = %3
  tail call void @FreePool(ptr noundef nonnull %5) #2
  br label %7

7:                                                ; preds = %6, %3
  store ptr null, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !13
  %8 = load ptr, ptr @FileBufferBackupVar, align 8, !tbaa !5
  %.not4 = icmp eq ptr %8, null
  br i1 %.not4, label %10, label %9

9:                                                ; preds = %7
  tail call void @FreePool(ptr noundef nonnull %8) #2
  store ptr null, ptr @FileBufferBackupVar, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %9, %7
  ret i64 %4
}

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 0}
!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, !7, i64 16}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass