; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library/UefiLib_ (GetVariable2)

; 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_RUNTIME_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [134 x i8], align 1
@gRT = external global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

; 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 zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

declare void @FreePool(ptr noundef) #1

declare ptr @AllocatePool(i64 noundef) #1

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

13:                                               ; preds = %4
  %14 = call zeroext i8 @DebugAssertEnabled()
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %27

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %22, %19, %16
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1340, ptr noundef @.str.16)
  br label %26

26:                                               ; preds = %25, %22
  br label %27

27:                                               ; preds = %26, %13
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  store i64 0, ptr %11, align 8, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %30, align 8, !tbaa !5
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %29
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %34, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %33, %29
  %36 = load ptr, ptr @gRT, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %36, i32 0, i32 7
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = call i64 %38(ptr noundef %39, ptr noundef %40, ptr noundef null, ptr noundef %11, ptr noundef %42)
  store i64 %43, ptr %10, align 8, !tbaa !9
  %44 = load i64, ptr %10, align 8, !tbaa !9
  %45 = icmp ne i64 %44, -9223372036854775803
  br i1 %45, label %46, label %48

46:                                               ; preds = %35
  %47 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %47, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %91

48:                                               ; preds = %35
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = call ptr @AllocatePool(i64 noundef %49)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %50, ptr %51, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %48
  %53 = call zeroext i8 @DebugAssertEnabled()
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %61

55:                                               ; preds = %52
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1360, ptr noundef @.str.17)
  br label %60

60:                                               ; preds = %59, %55
  br label %61

61:                                               ; preds = %60, %52
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = icmp eq ptr %65, null
  br i1 %66, label %67, label %68

67:                                               ; preds = %63
  store i64 -9223372036854775799, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %91

68:                                               ; preds = %63
  %69 = load ptr, ptr @gRT, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %69, i32 0, i32 7
  %71 = load ptr, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = call i64 %71(ptr noundef %72, ptr noundef %73, ptr noundef null, ptr noundef %11, ptr noundef %75)
  store i64 %76, ptr %10, align 8, !tbaa !9
  %77 = load i64, ptr %10, align 8, !tbaa !9
  %78 = icmp slt i64 %77, 0
  br i1 %78, label %79, label %83

79:                                               ; preds = %68
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  call void @FreePool(ptr noundef %81)
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %82, align 8, !tbaa !5
  br label %83

83:                                               ; preds = %79, %68
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %89

86:                                               ; preds = %83
  %87 = load i64, ptr %11, align 8, !tbaa !9
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %87, ptr %88, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %86, %83
  %90 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %90, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %91

91:                                               ; preds = %89, %67, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %92 = load i64, ptr %5, align 8
  ret i64 %92
}

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 72}
!12 = !{!"", !13, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!13 = !{!"", !10, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}


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

@.str = external hidden unnamed_addr constant [134 x i8], align 1
@gRT = external local_unnamed_addr global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

; 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 zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #1

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @GetVariable2(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3) local_unnamed_addr #2 {
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %12, label %7

7:                                                ; preds = %4
  %8 = icmp ne ptr %0, null
  %9 = icmp ne ptr %1, null
  %or.cond = and i1 %8, %9
  %10 = icmp ne ptr %2, null
  %or.cond3 = and i1 %or.cond, %10
  br i1 %or.cond3, label %12, label %11

11:                                               ; preds = %7
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1340, ptr noundef nonnull @.str.16) #3
  br label %12

12:                                               ; preds = %11, %7, %4
  store i64 0, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %2, align 8, !tbaa !9
  %.not29 = icmp eq ptr %3, null
  br i1 %.not29, label %14, label %13

13:                                               ; preds = %12
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %12
  %15 = load ptr, ptr @gRT, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 72
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = call i64 %17(ptr noundef %0, ptr noundef %1, ptr noundef null, ptr noundef nonnull %5, ptr noundef null) #3
  %.not30 = icmp eq i64 %18, -9223372036854775803
  br i1 %.not30, label %19, label %39

19:                                               ; preds = %14
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = call ptr @AllocatePool(i64 noundef %20) #3
  store ptr %21, ptr %2, align 8, !tbaa !9
  %22 = call zeroext i8 @DebugAssertEnabled() #3
  %.not31 = icmp eq i8 %22, 0
  br i1 %.not31, label %26, label %23

23:                                               ; preds = %19
  %24 = load ptr, ptr %2, align 8, !tbaa !9
  %.not32 = icmp eq ptr %24, null
  br i1 %.not32, label %25, label %.thread

25:                                               ; preds = %23
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1360, ptr noundef nonnull @.str.17) #3
  br label %26

26:                                               ; preds = %25, %19
  %.pr = load ptr, ptr %2, align 8, !tbaa !9
  %27 = icmp eq ptr %.pr, null
  br i1 %27, label %39, label %.thread

.thread:                                          ; preds = %23, %26
  %28 = phi ptr [ %.pr, %26 ], [ %24, %23 ]
  %29 = load ptr, ptr @gRT, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %29, i64 72
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = call i64 %31(ptr noundef %0, ptr noundef %1, ptr noundef null, ptr noundef nonnull %5, ptr noundef nonnull %28) #3
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %.thread
  %35 = load ptr, ptr %2, align 8, !tbaa !9
  call void @FreePool(ptr noundef %35) #3
  store ptr null, ptr %2, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %34, %.thread
  br i1 %.not29, label %39, label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %38, ptr %3, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %36, %37, %26, %14
  %.0 = phi i64 [ %18, %14 ], [ -9223372036854775799, %26 ], [ %32, %37 ], [ %32, %36 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.0
}

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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 72}
!12 = !{!"", !13, i64 0, !10, i64 24, !10, 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, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}


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