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

; 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

; Function Attrs: nounwind uwtable
define dso_local i64 @FileBufferBackup() #0 {
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 7), ptr align 8 getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 7), i64 16, i1 false), !tbaa.struct !5
  br label %1

1:                                                ; preds = %0
  %2 = load ptr, ptr @FileBufferBackupVar, align 8, !tbaa !10
  %3 = icmp ne ptr %2, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %5 = load ptr, ptr @FileBufferBackupVar, align 8, !tbaa !10
  call void @FreePool(ptr noundef %5)
  store ptr null, ptr @FileBufferBackupVar, align 8, !tbaa !10
  br label %6

6:                                                ; preds = %4, %1
  br label %7

7:                                                ; preds = %6
  store ptr null, ptr @FileBufferBackupVar, align 8, !tbaa !10
  %8 = load ptr, ptr @FileBuffer, align 8, !tbaa !10
  %9 = call ptr @StrnCatGrow(ptr noundef @FileBufferBackupVar, ptr noundef null, ptr noundef %8, i64 noundef 0)
  store ptr %9, ptr @FileBufferBackupVar, align 8, !tbaa !10
  %10 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 10), align 1, !tbaa !15
  store i8 %10, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 10), align 1, !tbaa !15
  %11 = load i32, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 1), align 8, !tbaa !16
  store i32 %11, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 1), align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 6), ptr align 8 getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 6), i64 16, i1 false), !tbaa.struct !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 8), ptr align 8 getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 8), i64 16, i1 false), !tbaa.struct !5
  %12 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 9), align 8, !tbaa !17
  store i8 %12, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 9), align 8, !tbaa !17
  %13 = load i8, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 11), align 2, !tbaa !18
  store i8 %13, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBufferBackupVar, i32 0, i32 11), align 2, !tbaa !18
  ret i64 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @FreePool(ptr noundef) #2

declare ptr @StrnCatGrow(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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" }

!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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !13, i64 8, !12, i64 16, !12, i64 24, !7, i64 32, !14, i64 40, !14, i64 56, !14, i64 72, !14, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !12, i64 112}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 8}
!15 = !{!11, !8, i64 105}
!16 = !{!11, !13, i64 8}
!17 = !{!11, !8, i64 104}
!18 = !{!11, !8, i64 106}


; 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 global %struct.EFI_EDITOR_FILE_BUFFER, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @FileBufferBackup() local_unnamed_addr #0 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 72), ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @FileBuffer, i64 72), i64 16, i1 false), !tbaa.struct !5
  %1 = load ptr, ptr @FileBufferBackupVar, align 8, !tbaa !10
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %2

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

3:                                                ; preds = %0, %2
  store ptr null, ptr @FileBufferBackupVar, align 8, !tbaa !10
  %4 = load ptr, ptr @FileBuffer, align 8, !tbaa !10
  %5 = tail call ptr @StrnCatGrow(ptr noundef nonnull @FileBufferBackupVar, ptr noundef null, ptr noundef %4, i64 noundef 0) #3
  store ptr %5, ptr @FileBufferBackupVar, align 8, !tbaa !10
  %6 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 105), align 1, !tbaa !15
  store i8 %6, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 105), align 1, !tbaa !15
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 8), align 8, !tbaa !16
  store i32 %7, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 8), align 8, !tbaa !16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 56), ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @FileBuffer, i64 56), i64 16, i1 false), !tbaa.struct !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 88), ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @FileBuffer, i64 88), i64 16, i1 false), !tbaa.struct !5
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 104), align 8, !tbaa !17
  store i8 %8, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 104), align 8, !tbaa !17
  %9 = load i8, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 106), align 2, !tbaa !18
  store i8 %9, ptr getelementptr inbounds (i8, ptr @FileBufferBackupVar, i64 106), align 2, !tbaa !18
  ret i64 0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @FreePool(ptr noundef) local_unnamed_addr #2

declare ptr @StrnCatGrow(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !13, i64 8, !12, i64 16, !12, i64 24, !7, i64 32, !14, i64 40, !14, i64 56, !14, i64 72, !14, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !12, i64 112}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 8}
!15 = !{!11, !8, i64 105}
!16 = !{!11, !13, i64 8}
!17 = !{!11, !8, i64 104}
!18 = !{!11, !8, i64 106}


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