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

; 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_HII_STRING_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [145 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@gHiiString = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i32], align 4
@.str.6 = external hidden unnamed_addr constant [1 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

declare ptr @HiiGetSupportedLanguages(ptr noundef) #1

declare void @FreePool(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @HiiGetString(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, 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
  br label %14

14:                                               ; preds = %3
  %15 = call zeroext i8 @DebugAssertEnabled()
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %22

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

20:                                               ; preds = %17
  call void @DebugAssert(ptr noundef @.str, i64 noundef 231, ptr noundef @.str.1)
  br label %21

21:                                               ; preds = %20, %17
  br label %22

22:                                               ; preds = %21, %14
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = call zeroext i8 @DebugAssertEnabled()
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = load i16, ptr %5, align 2, !tbaa !9
  %30 = zext i16 %29 to i32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @DebugAssert(ptr noundef @.str, i64 noundef 232, ptr noundef @.str.4)
  br label %33

33:                                               ; preds = %32, %28
  br label %34

34:                                               ; preds = %33, %25
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  store ptr null, ptr %11, align 8, !tbaa !5
  store ptr null, ptr %12, align 8, !tbaa !5
  store ptr null, ptr %13, align 8, !tbaa !5
  store ptr null, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call ptr @HiiGetSupportedLanguages(ptr noundef %37)
  store ptr %38, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  br label %95

42:                                               ; preds = %36
  %43 = call i64 @GetEfiGlobalVariable2(ptr noundef @.str.5, ptr noundef %12, ptr noundef null)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  store ptr @.str.6, ptr %6, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %46, %42
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %54

52:                                               ; preds = %47
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  br label %55

54:                                               ; preds = %47
  br label %55

55:                                               ; preds = %54, %52
  %56 = phi ptr [ %53, %52 ], [ @.str.6, %54 ]
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = call ptr (ptr, i8, ...) @GetBestLanguage(ptr noundef %48, i8 noundef zeroext 0, ptr noundef %49, ptr noundef %56, ptr noundef %57, ptr noundef null)
  store ptr %58, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  br label %95

62:                                               ; preds = %55
  store i64 0, ptr %8, align 8, !tbaa !11
  %63 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._EFI_HII_STRING_PROTOCOL, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i16, ptr %5, align 2, !tbaa !9
  %70 = call i64 %65(ptr noundef %66, ptr noundef %67, ptr noundef %68, i16 noundef zeroext %69, ptr noundef %9, ptr noundef %8, ptr noundef null)
  store i64 %70, ptr %7, align 8, !tbaa !11
  %71 = load i64, ptr %7, align 8, !tbaa !11
  %72 = icmp ne i64 %71, -9223372036854775803
  br i1 %72, label %73, label %74

73:                                               ; preds = %62
  br label %95

74:                                               ; preds = %62
  %75 = load i64, ptr %8, align 8, !tbaa !11
  %76 = call ptr @AllocateZeroPool(i64 noundef %75)
  store ptr %76, ptr %10, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = icmp eq ptr %77, null
  br i1 %78, label %79, label %80

79:                                               ; preds = %74
  br label %95

80:                                               ; preds = %74
  %81 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._EFI_HII_STRING_PROTOCOL, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !13
  %84 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %85 = load ptr, ptr %13, align 8, !tbaa !5
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i16, ptr %5, align 2, !tbaa !9
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = call i64 %83(ptr noundef %84, ptr noundef %85, ptr noundef %86, i16 noundef zeroext %87, ptr noundef %88, ptr noundef %8, ptr noundef null)
  store i64 %89, ptr %7, align 8, !tbaa !11
  %90 = load i64, ptr %7, align 8, !tbaa !11
  %91 = icmp slt i64 %90, 0
  br i1 %91, label %92, label %94

92:                                               ; preds = %80
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  call void @FreePool(ptr noundef %93)
  store ptr null, ptr %10, align 8, !tbaa !5
  br label %94

94:                                               ; preds = %92, %80
  br label %95

95:                                               ; preds = %94, %79, %73, %61, %41
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  %97 = icmp ne ptr %96, null
  br i1 %97, label %98, label %100

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

100:                                              ; preds = %98, %95
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = icmp ne ptr %101, null
  br i1 %102, label %103, label %105

103:                                              ; preds = %100
  %104 = load ptr, ptr %12, align 8, !tbaa !5
  call void @FreePool(ptr noundef %104)
  br label %105

105:                                              ; preds = %103, %100
  %106 = load ptr, ptr %13, align 8, !tbaa !5
  %107 = icmp ne ptr %106, null
  br i1 %107, label %108, label %110

108:                                              ; preds = %105
  %109 = load ptr, ptr %13, align 8, !tbaa !5
  call void @FreePool(ptr noundef %109)
  br label %110

110:                                              ; preds = %108, %105
  %111 = load ptr, ptr %10, align 8, !tbaa !5
  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 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %111
}

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

declare ptr @GetBestLanguage(ptr noundef, i8 noundef zeroext, ...) #1

declare ptr @AllocateZeroPool(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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_EFI_HII_STRING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


; 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 [145 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@gHiiString = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [13 x i32], align 4
@.str.6 = external hidden unnamed_addr constant [1 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

declare ptr @HiiGetSupportedLanguages(ptr noundef) local_unnamed_addr #1

declare void @FreePool(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

; Function Attrs: nounwind uwtable
define dso_local ptr @HiiGetString(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca i64, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = tail call zeroext i8 @DebugAssertEnabled() #3
  %8 = icmp eq i8 %7, 0
  %9 = icmp ne ptr %0, null
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %11, label %10

10:                                               ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 231, ptr noundef nonnull @.str.1) #3
  br label %11

11:                                               ; preds = %3, %10
  %12 = tail call zeroext i8 @DebugAssertEnabled() #3
  %13 = icmp eq i8 %12, 0
  %14 = icmp ne i16 %1, 0
  %or.cond4 = or i1 %14, %13
  br i1 %or.cond4, label %16, label %15

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

16:                                               ; preds = %15, %11
  store ptr null, ptr %6, align 8, !tbaa !5
  %17 = tail call ptr @HiiGetSupportedLanguages(ptr noundef %0) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.thread50, label %19

19:                                               ; preds = %16
  %20 = call i64 @GetEfiGlobalVariable2(ptr noundef nonnull @.str.5, ptr noundef nonnull %6, ptr noundef null) #3
  %21 = icmp eq ptr %2, null
  %spec.store.select = select i1 %21, ptr @.str.6, ptr %2
  %22 = load ptr, ptr %6, align 8
  %.not = icmp eq ptr %22, null
  %23 = select i1 %.not, ptr @.str.6, ptr %22
  %24 = call ptr (ptr, i8, ...) @GetBestLanguage(ptr noundef nonnull %17, i8 noundef zeroext 0, ptr noundef nonnull %spec.store.select, ptr noundef nonnull %23, ptr noundef nonnull %17, ptr noundef null) #3
  %25 = icmp eq ptr %24, null
  br i1 %25, label %42, label %26

26:                                               ; preds = %19
  store i64 0, ptr %4, align 8, !tbaa !9
  %27 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = call i64 %29(ptr noundef %27, ptr noundef nonnull %24, ptr noundef %0, i16 noundef zeroext %1, ptr noundef nonnull %5, ptr noundef nonnull %4, ptr noundef null) #3
  %.not35 = icmp eq i64 %30, -9223372036854775803
  br i1 %.not35, label %31, label %42

31:                                               ; preds = %26
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = call ptr @AllocateZeroPool(i64 noundef %32) #3
  %34 = icmp eq ptr %33, null
  br i1 %34, label %42, label %35

35:                                               ; preds = %31
  %36 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = call i64 %38(ptr noundef %36, ptr noundef nonnull %24, ptr noundef %0, i16 noundef zeroext %1, ptr noundef nonnull %33, ptr noundef nonnull %4, ptr noundef null) #3
  %40 = icmp slt i64 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  call void @FreePool(ptr noundef nonnull %33) #3
  br label %42

42:                                               ; preds = %19, %26, %31, %41, %35
  %.028.ph = phi ptr [ %33, %35 ], [ null, %41 ], [ null, %31 ], [ null, %26 ], [ null, %19 ]
  call void @FreePool(ptr noundef nonnull %17) #3
  %.pre = load ptr, ptr %6, align 8, !tbaa !5
  %.not37 = icmp eq ptr %.pre, null
  br i1 %.not37, label %44, label %43

43:                                               ; preds = %42
  call void @FreePool(ptr noundef nonnull %.pre) #3
  br label %44

44:                                               ; preds = %43, %42
  %.not38 = icmp eq ptr %24, null
  br i1 %.not38, label %.thread50, label %45

45:                                               ; preds = %44
  call void @FreePool(ptr noundef nonnull %24) #3
  br label %.thread50

.thread50:                                        ; preds = %16, %45, %44
  %.028424954 = phi ptr [ %.028.ph, %45 ], [ %.028.ph, %44 ], [ null, %16 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret ptr %.028424954
}

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

declare ptr @GetBestLanguage(ptr noundef, i8 noundef zeroext, ...) local_unnamed_addr #1

declare ptr @AllocateZeroPool(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 = !{!"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 8}
!12 = !{!"_EFI_HII_STRING_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}


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