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

; 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.HEFI_EDITOR_DISK_IMAGE = type { ptr, i64, i64, i64 }

@HDiskImage = external dso_local global %struct.HEFI_EDITOR_DISK_IMAGE, align 8
@HDiskImageBackupVar = external dso_local global %struct.HEFI_EDITOR_DISK_IMAGE, align 8
@.str = external hidden unnamed_addr constant [3 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @HDiskImageBackup() #0 {
  %1 = alloca i64, align 8
  br label %2

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

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

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

8:                                                ; preds = %7
  %9 = load ptr, ptr @HDiskImage, align 8, !tbaa !5
  %10 = call ptr (ptr, ptr, ...) @CatSPrint(ptr noundef null, ptr noundef @.str, ptr noundef %9)
  store ptr %10, ptr @HDiskImageBackupVar, align 8, !tbaa !5
  %11 = load ptr, ptr @HDiskImageBackupVar, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  store i64 -9223372036854775799, ptr %1, align 8
  br label %17

14:                                               ; preds = %8
  %15 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_DISK_IMAGE, ptr @HDiskImage, i32 0, i32 3), align 8, !tbaa !11
  store i64 %15, ptr getelementptr inbounds (%struct.HEFI_EDITOR_DISK_IMAGE, ptr @HDiskImageBackupVar, i32 0, i32 3), align 8, !tbaa !11
  %16 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_DISK_IMAGE, ptr @HDiskImage, i32 0, i32 2), align 8, !tbaa !12
  store i64 %16, ptr getelementptr inbounds (%struct.HEFI_EDITOR_DISK_IMAGE, ptr @HDiskImageBackupVar, i32 0, i32 2), align 8, !tbaa !12
  store i64 0, ptr %1, align 8
  br label %17

17:                                               ; preds = %14, %13
  %18 = load i64, ptr %1, align 8
  ret i64 %18
}

declare void @FreePool(ptr noundef) #1

declare ptr @CatSPrint(ptr noundef, ptr noundef, ...) #1

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 = { "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 = !{!6, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !10, 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.HEFI_EDITOR_DISK_IMAGE = type { ptr, i64, i64, i64 }

@HDiskImage = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_DISK_IMAGE, align 8
@HDiskImageBackupVar = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_DISK_IMAGE, align 8
@.str = external hidden unnamed_addr constant [3 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @HDiskImageBackup() local_unnamed_addr #0 {
  %1 = load ptr, ptr @HDiskImageBackupVar, 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 @HDiskImageBackupVar, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %0, %2
  %4 = load ptr, ptr @HDiskImage, align 8, !tbaa !5
  %5 = tail call ptr (ptr, ptr, ...) @CatSPrint(ptr noundef null, ptr noundef nonnull @.str, ptr noundef %4) #2
  store ptr %5, ptr @HDiskImageBackupVar, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %9, label %7

7:                                                ; preds = %3
  %8 = load <2 x i64>, ptr getelementptr inbounds (i8, ptr @HDiskImage, i64 16), align 8, !tbaa !11
  store <2 x i64> %8, ptr getelementptr inbounds (i8, ptr @HDiskImageBackupVar, i64 16), align 8, !tbaa !11
  br label %9

9:                                                ; preds = %3, %7
  %.0 = phi i64 [ 0, %7 ], [ -9223372036854775799, %3 ]
  ret i64 %.0
}

declare void @FreePool(ptr noundef) local_unnamed_addr #1

declare ptr @CatSPrint(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

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 = { "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, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass