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

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

22:                                               ; preds = %4
  store i64 -9223372036854775799, ptr %9, align 8, !tbaa !9
  br label %91

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

38:                                               ; preds = %23
  br label %91

39:                                               ; preds = %23
  %40 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %40, ptr %13, align 8, !tbaa !9
  %41 = load i64, ptr %12, align 8, !tbaa !9
  %42 = call ptr @AllocateZeroPool(i64 noundef %41)
  store ptr %42, ptr %11, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %39
  %44 = call zeroext i8 @DebugAssertEnabled()
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %46, label %51

46:                                               ; preds = %43
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  call void @DebugAssert(ptr noundef @.str, i64 noundef 3444, ptr noundef @.str.35)
  br label %50

50:                                               ; preds = %49, %46
  br label %51

51:                                               ; preds = %50, %43
  br label %52

52:                                               ; preds = %51
  br label %53

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

64:                                               ; preds = %53
  br label %91

65:                                               ; preds = %53
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = call i64 @HiiConfigToBlock(ptr noundef %66, ptr noundef %67, ptr noundef %68, ptr noundef %13, ptr noundef %69)
  store i64 %70, ptr %9, align 8, !tbaa !9
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = icmp slt i64 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %65
  br label %91

74:                                               ; preds = %65
  %75 = load ptr, ptr @gRT, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %75, i32 0, i32 9
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._EFI_IFR_VARSTORE_EFI, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._EFI_IFR_VARSTORE_EFI, ptr %81, i32 0, i32 3
  %83 = load i32, ptr %82, align 1, !tbaa !16
  %84 = load i64, ptr %12, align 8, !tbaa !9
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = call i64 %77(ptr noundef %78, ptr noundef %80, i32 noundef %83, i64 noundef %84, ptr noundef %85)
  store i64 %86, ptr %9, align 8, !tbaa !9
  %87 = load i64, ptr %9, align 8, !tbaa !9
  %88 = icmp slt i64 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %74
  br label %91

90:                                               ; preds = %74
  br label %91

91:                                               ; preds = %90, %89, %73, %64, %38, %22
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = icmp ne ptr %92, null
  br i1 %93, label %94, label %96

94:                                               ; preds = %91
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FreePool(ptr noundef %95)
  br label %96

96:                                               ; preds = %94, %91
  %97 = load ptr, ptr %11, align 8, !tbaa !5
  %98 = icmp ne ptr %97, null
  br i1 %98, label %99, label %101

99:                                               ; preds = %96
  %100 = load ptr, ptr %11, align 8, !tbaa !5
  call void @FreePool(ptr noundef %100)
  br label %101

101:                                              ; preds = %99, %96
  %102 = load i64, ptr %9, align 8, !tbaa !9
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i64 %102
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @HiiConfigToBlock(ptr noundef, ptr noundef, ptr 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}
!15 = !{!12, !6, i64 88}
!16 = !{!17, !14, i64 20}
!17 = !{!"_EFI_IFR_VARSTORE_EFI", !18, i64 0, !19, i64 2, !20, i64 4, !14, i64 20, !19, i64 24, !7, i64 26}
!18 = !{!"_EFI_IFR_OP_HEADER", !7, i64 0, !7, i64 1, !7, i64 1}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !14, i64 0, !19, i64 4, !19, i64 6, !7, 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"

@.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 @RouteConfigRespForEfiVarStore(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 0, ptr %5, align 8, !tbaa !5
  %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 %.thread39, label %12

12:                                               ; preds = %4
  %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 %5, ptr noundef null) #3
  %.not = icmp eq i64 %18, -9223372036854775803
  br i1 %.not, label %19, label %.thread39.sink.split

19:                                               ; preds = %12
  %20 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %20, 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 3444, 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 %5, ptr noundef %21) #3
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %43, label %32

32:                                               ; preds = %26
  %33 = call i64 @HiiConfigToBlock(ptr noundef %0, ptr noundef %2, ptr noundef %21, ptr noundef nonnull %6, ptr noundef %3)
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %43, label %35

35:                                               ; preds = %32
  %36 = load ptr, ptr @gRT, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %36, i64 88
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds i8, ptr %1, i64 20
  %40 = load i32, ptr %39, align 1, !tbaa !16
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = call i64 %38(ptr noundef nonnull %10, ptr noundef nonnull %17, i32 noundef %40, i64 noundef %41, ptr noundef %21) #3
  br label %43

43:                                               ; preds = %26, %32, %35
  %.026.ph = phi i64 [ %42, %35 ], [ %33, %32 ], [ %30, %26 ]
  call void @FreePool(ptr noundef nonnull %10) #3
  %.not32 = icmp eq ptr %21, null
  br i1 %.not32, label %.thread39, label %.thread39.sink.split

.thread39.sink.split:                             ; preds = %43, %12
  %.sink = phi ptr [ %10, %12 ], [ %21, %43 ]
  %.0263643.ph = phi i64 [ %18, %12 ], [ %.026.ph, %43 ]
  call void @FreePool(ptr noundef nonnull %.sink) #3
  br label %.thread39

.thread39:                                        ; preds = %.thread39.sink.split, %4, %43
  %.0263643 = phi i64 [ %.026.ph, %43 ], [ -9223372036854775799, %4 ], [ %.0263643.ph, %.thread39.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.0263643
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @HiiConfigToBlock(ptr noundef, ptr noundef, ptr 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}
!15 = !{!12, !10, i64 88}
!16 = !{!17, !14, i64 20}
!17 = !{!"_EFI_IFR_VARSTORE_EFI", !18, i64 0, !19, i64 2, !20, i64 4, !14, i64 20, !19, i64 24, !7, i64 26}
!18 = !{!"_EFI_IFR_OP_HEADER", !7, i64 0, !7, i64 1, !7, i64 1}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !14, i64 0, !19, i64 4, !19, i64 6, !7, i64 8}


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