; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (GetFormPackageData)

; 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._HII_DATABASE_PRIVATE_DATA = type { i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._EFI_HII_FONT_PROTOCOL, %struct._EFI_HII_IMAGE_PROTOCOL, %struct._EFI_HII_STRING_PROTOCOL, %struct._EFI_HII_DATABASE_PROTOCOL, %struct._EFI_HII_CONFIG_ROUTING_PROTOCOL, %struct._LIST_ENTRY, i64, %struct._LIST_ENTRY, i64, %struct.GUID, ptr }
%struct._EFI_HII_FONT_PROTOCOL = type { ptr, ptr, ptr, ptr }
%struct._EFI_HII_IMAGE_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct._EFI_HII_STRING_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct._EFI_HII_DATABASE_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_HII_CONFIG_ROUTING_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct._HII_DATABASE_RECORD = type { i64, ptr, ptr, ptr, %struct._LIST_ENTRY }

@mPrivate = external global %struct._HII_DATABASE_PRIVATE_DATA, align 8

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

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

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @GetFormPackageData(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %20, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %14, %3
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %65

21:                                               ; preds = %17
  store i64 0, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %10, align 8, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._HII_DATABASE_RECORD, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._HII_DATABASE_RECORD, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i64 @ExportFormPackages(ptr noundef @mPrivate, ptr noundef %24, ptr noundef %27, i64 noundef 0, i64 noundef %28, ptr noundef %29, ptr noundef %10)
  store i64 %30, ptr %8, align 8, !tbaa !9
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %21
  %34 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %34, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %65

35:                                               ; preds = %21
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = call ptr @AllocatePool(i64 noundef %36)
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %37, ptr %38, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %44

42:                                               ; preds = %35
  store i64 -9223372036854775799, ptr %8, align 8, !tbaa !9
  %43 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %43, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %65

44:                                               ; preds = %35
  %45 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %45, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %10, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._HII_DATABASE_RECORD, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._HII_DATABASE_RECORD, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i64, ptr %9, align 8, !tbaa !9
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = call i64 @ExportFormPackages(ptr noundef @mPrivate, ptr noundef %48, ptr noundef %51, i64 noundef 0, i64 noundef %52, ptr noundef %54, ptr noundef %10)
  store i64 %55, ptr %8, align 8, !tbaa !9
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = icmp slt i64 %56, 0
  br i1 %57, label %58, label %61

58:                                               ; preds = %44
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  call void @FreePool(ptr noundef %60)
  br label %61

61:                                               ; preds = %58, %44
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %62, ptr %63, align 8, !tbaa !9
  %64 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %64, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %65

65:                                               ; preds = %61, %42, %33, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %66 = load i64, ptr %4, align 8
  ret i64 %66
}

declare i64 @ExportFormPackages(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #1

declare ptr @AllocatePool(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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_HII_DATABASE_RECORD", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!12, !6, i64 8}


; 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._HII_DATABASE_PRIVATE_DATA = type { i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._EFI_HII_FONT_PROTOCOL, %struct._EFI_HII_IMAGE_PROTOCOL, %struct._EFI_HII_STRING_PROTOCOL, %struct._EFI_HII_DATABASE_PROTOCOL, %struct._EFI_HII_CONFIG_ROUTING_PROTOCOL, %struct._LIST_ENTRY, i64, %struct._LIST_ENTRY, i64, %struct.GUID, ptr }
%struct._EFI_HII_FONT_PROTOCOL = type { ptr, ptr, ptr, ptr }
%struct._EFI_HII_IMAGE_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct._EFI_HII_STRING_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }
%struct._EFI_HII_DATABASE_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._EFI_HII_CONFIG_ROUTING_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }

@mPrivate = external global %struct._HII_DATABASE_PRIVATE_DATA, align 8

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

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

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @GetFormPackageData(ptr noundef readonly %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  %7 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %7
  br i1 %or.cond3, label %28, label %8

8:                                                ; preds = %3
  store i64 0, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = call i64 @ExportFormPackages(ptr noundef nonnull @mPrivate, ptr noundef %10, ptr noundef %12, i64 noundef 0, i64 noundef 0, ptr noundef nonnull %1, ptr noundef nonnull %4) #3
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %28, label %15

15:                                               ; preds = %8
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = call ptr @AllocatePool(i64 noundef %16) #3
  store ptr %17, ptr %1, align 8, !tbaa !14
  %18 = icmp eq ptr %17, null
  br i1 %18, label %28, label %19

19:                                               ; preds = %15
  %20 = load i64, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %9, align 8, !tbaa !9
  %22 = load ptr, ptr %11, align 8, !tbaa !13
  %23 = call i64 @ExportFormPackages(ptr noundef nonnull @mPrivate, ptr noundef %21, ptr noundef %22, i64 noundef 0, i64 noundef %20, ptr noundef nonnull %17, ptr noundef nonnull %4) #3
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = load ptr, ptr %1, align 8, !tbaa !14
  call void @FreePool(ptr noundef %26) #3
  br label %27

27:                                               ; preds = %25, %19
  store i64 %20, ptr %2, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %15, %8, %3, %27
  %.0 = phi i64 [ %23, %27 ], [ -9223372036854775806, %3 ], [ %13, %8 ], [ -9223372036854775799, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i64 %.0
}

declare i64 @ExportFormPackages(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"_HII_DATABASE_RECORD", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!13 = !{!10, !11, i64 8}
!14 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass