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

; 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_IFR_VARSTORE_EFI = type <{ %struct._EFI_IFR_OP_HEADER, i16, %struct.GUID, i32, i16, [1 x i8] }>
%struct._EFI_IFR_OP_HEADER = type { i8, i8 }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%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 [155 x i8], align 1
@gRT = external global ptr, align 8
@.str.35 = external hidden unnamed_addr constant [25 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

declare zeroext i8 @DebugAssertEnabled() #1

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

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

declare ptr @AllocateZeroPool(i64 noundef) #1

declare void @FreePool(ptr noundef) #1

declare i64 @AsciiStrSize(ptr noundef) #1

declare ptr @AsciiStrToUnicodeStr(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @GetConfigRespFromEfiVarStore(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  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
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  store i64 0, ptr %14, align 8, !tbaa !9
  store ptr null, ptr %13, align 8, !tbaa !5
  store ptr null, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %15, ptr %16, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._EFI_IFR_VARSTORE_EFI, ptr %17, i32 0, i32 5
  %19 = getelementptr inbounds [1 x i8], ptr %18, i64 0, i64 0
  %20 = call i64 @AsciiStrSize(ptr noundef %19)
  %21 = mul i64 %20, 2
  %22 = call ptr @AllocateZeroPool(i64 noundef %21)
  store ptr %22, ptr %12, align 8, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %5
  store i64 -9223372036854775799, ptr %11, align 8, !tbaa !9
  br label %79

26:                                               ; preds = %5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._EFI_IFR_VARSTORE_EFI, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds [1 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = call ptr @AsciiStrToUnicodeStr(ptr noundef %29, ptr noundef %30)
  %32 = load ptr, ptr @gRT, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %32, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._EFI_IFR_VARSTORE_EFI, ptr %36, i32 0, i32 2
  %38 = call i64 %34(ptr noundef %35, ptr noundef %37, ptr noundef null, ptr noundef %14, ptr noundef null)
  store i64 %38, ptr %11, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = icmp ne i64 %39, -9223372036854775803
  br i1 %40, label %41, label %42

41:                                               ; preds = %26
  br label %79

42:                                               ; preds = %26
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = call ptr @AllocateZeroPool(i64 noundef %43)
  store ptr %44, ptr %13, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42
  %46 = call zeroext i8 @DebugAssertEnabled()
  %47 = icmp ne i8 %46, 0
  br i1 %47, label %48, label %53

48:                                               ; preds = %45
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  call void @DebugAssert(ptr noundef @.str, i64 noundef 3369, ptr noundef @.str.35)
  br label %52

52:                                               ; preds = %51, %48
  br label %53

53:                                               ; preds = %52, %45
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr @gRT, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %56, i32 0, i32 7
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._EFI_IFR_VARSTORE_EFI, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = call i64 %58(ptr noundef %59, ptr noundef %61, ptr noundef null, ptr noundef %14, ptr noundef %62)
  store i64 %63, ptr %11, align 8, !tbaa !9
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = icmp slt i64 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %55
  br label %79

67:                                               ; preds = %55
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = load i64, ptr %14, align 8, !tbaa !9
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = call i64 @HiiBlockToConfig(ptr noundef %68, ptr noundef %69, ptr noundef %70, i64 noundef %71, ptr noundef %72, ptr noundef %73)
  store i64 %74, ptr %11, align 8, !tbaa !9
  %75 = load i64, ptr %11, align 8, !tbaa !9
  %76 = icmp slt i64 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %67
  br label %79

78:                                               ; preds = %67
  br label %79

79:                                               ; preds = %78, %77, %66, %41, %25
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  call void @FreePool(ptr noundef %83)
  br label %84

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

87:                                               ; preds = %84
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  call void @FreePool(ptr noundef %88)
  br label %89

89:                                               ; preds = %87, %84
  %90 = load i64, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret i64 %90
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @HiiBlockToConfig(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

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 [155 x i8], align 1
@gRT = external local_unnamed_addr global ptr, align 8
@.str.35 = external hidden unnamed_addr constant [25 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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #1

declare i64 @AsciiStrSize(ptr noundef) local_unnamed_addr #1

declare ptr @AsciiStrToUnicodeStr(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @GetConfigRespFromEfiVarStore(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %4, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %1, i64 26
  %8 = tail call i64 @AsciiStrSize(ptr noundef nonnull %7) #3
  %9 = shl i64 %8, 1
  %10 = tail call ptr @AllocateZeroPool(i64 noundef %9) #3
  %11 = icmp eq ptr %10, null
  br i1 %11, label %.thread36, label %12

12:                                               ; preds = %5
  %13 = tail call ptr @AsciiStrToUnicodeStr(ptr noundef nonnull %7, ptr noundef nonnull %10) #3
  %14 = load ptr, ptr @gRT, align 8, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %14, i64 72
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %1, i64 4
  %18 = call i64 %16(ptr noundef nonnull %10, ptr noundef nonnull %17, ptr noundef null, ptr noundef nonnull %6, ptr noundef null) #3
  %.not = icmp eq i64 %18, -9223372036854775803
  br i1 %.not, label %19, label %.thread36.sink.split

19:                                               ; preds = %12
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = call ptr @AllocateZeroPool(i64 noundef %20) #3
  %22 = call zeroext i8 @DebugAssertEnabled() #3
  %23 = icmp eq i8 %22, 0
  %24 = icmp ne ptr %21, null
  %or.cond = select i1 %23, i1 true, i1 %24
  br i1 %or.cond, label %26, label %25

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

26:                                               ; preds = %25, %19
  %27 = load ptr, ptr @gRT, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %27, i64 72
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = call i64 %29(ptr noundef nonnull %10, ptr noundef nonnull %17, ptr noundef null, ptr noundef nonnull %6, ptr noundef %21) #3
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %35, label %32

32:                                               ; preds = %26
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = call i64 @HiiBlockToConfig(ptr noundef %0, ptr noundef %2, ptr noundef %21, i64 noundef %33, ptr noundef %3, ptr noundef nonnull %4)
  br label %35

35:                                               ; preds = %26, %32
  %.024.ph = phi i64 [ %34, %32 ], [ %30, %26 ]
  call void @FreePool(ptr noundef nonnull %10) #3
  %.not29 = icmp eq ptr %21, null
  br i1 %.not29, label %.thread36, label %.thread36.sink.split

.thread36.sink.split:                             ; preds = %35, %12
  %.sink = phi ptr [ %10, %12 ], [ %21, %35 ]
  %.0243340.ph = phi i64 [ %18, %12 ], [ %.024.ph, %35 ]
  call void @FreePool(ptr noundef nonnull %.sink) #3
  br label %.thread36

.thread36:                                        ; preds = %.thread36.sink.split, %5, %35
  %.0243340 = phi i64 [ %.024.ph, %35 ], [ -9223372036854775799, %5 ], [ %.0243340.ph, %.thread36.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i64 %.0243340
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @HiiBlockToConfig(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass