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

; 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 [147 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@gHiiString = external global ptr, align 8

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

9:                                                ; preds = %1
  %10 = call zeroext i8 @DebugAssertEnabled()
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @DebugAssert(ptr noundef @.str, i64 noundef 47, ptr noundef @.str.1)
  br label %16

16:                                               ; preds = %15, %12
  br label %17

17:                                               ; preds = %16, %9
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  store i64 0, ptr %5, align 8, !tbaa !9
  %20 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._EFI_HII_STRING_PROTOCOL, ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call i64 %22(ptr noundef %23, ptr noundef %24, ptr noundef %6, ptr noundef %5)
  store i64 %25, ptr %4, align 8, !tbaa !9
  %26 = load i64, ptr %4, align 8, !tbaa !9
  %27 = icmp ne i64 %26, -9223372036854775803
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %49

29:                                               ; preds = %19
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = call ptr @AllocateZeroPool(i64 noundef %30)
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %49

35:                                               ; preds = %29
  %36 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._EFI_HII_STRING_PROTOCOL, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr @gHiiString, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i64 %38(ptr noundef %39, ptr noundef %40, ptr noundef %41, ptr noundef %5)
  store i64 %42, ptr %4, align 8, !tbaa !9
  %43 = load i64, ptr %4, align 8, !tbaa !9
  %44 = icmp slt i64 %43, 0
  br i1 %44, label %45, label %47

45:                                               ; preds = %35
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  call void @FreePool(ptr noundef %46)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %49

47:                                               ; preds = %35
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %48, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %49

49:                                               ; preds = %47, %45, %34, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %50 = load ptr, ptr %2, align 8
  ret ptr %50
}

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

declare zeroext i8 @DebugAssertEnabled() #2

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

declare ptr @AllocateZeroPool(i64 noundef) #2

declare void @FreePool(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"_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 [147 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

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

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

8:                                                ; preds = %7, %1
  store i64 0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr @gHiiString, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = call i64 %11(ptr noundef %9, ptr noundef %0, ptr noundef nonnull %3, ptr noundef nonnull %2) #3
  %.not = icmp eq i64 %12, -9223372036854775803
  br i1 %.not, label %13, label %24

13:                                               ; preds = %8
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = call ptr @AllocateZeroPool(i64 noundef %14) #3
  %16 = icmp eq ptr %15, null
  br i1 %16, label %24, label %17

17:                                               ; preds = %13
  %18 = load ptr, ptr @gHiiString, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = call i64 %20(ptr noundef %18, ptr noundef %0, ptr noundef nonnull %15, ptr noundef nonnull %2) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  call void @FreePool(ptr noundef nonnull %15) #3
  br label %24

24:                                               ; preds = %17, %13, %8, %23
  %.0 = phi ptr [ null, %23 ], [ null, %8 ], [ null, %13 ], [ %15, %17 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret ptr %.0
}

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 24}
!12 = !{!"_EFI_HII_STRING_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}


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