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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @CompareIso639LanguageCode(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @LookupUnicodeString(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %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
  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
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %15, label %12

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

15:                                               ; preds = %12, %4
  store i64 -9223372036854775806, ptr %5, align 8
  br label %60

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %22, label %19

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

22:                                               ; preds = %19, %16
  store i64 -9223372036854775805, ptr %5, align 8
  br label %60

23:                                               ; preds = %19
  br label %24

24:                                               ; preds = %56, %23
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %59

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call zeroext i8 @CompareIso639LanguageCode(ptr noundef %30, ptr noundef %31)
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %34, label %56

34:                                               ; preds = %29
  br label %35

35:                                               ; preds = %52, %34
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !10
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %55

40:                                               ; preds = %35
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !10
  %45 = call zeroext i8 @CompareIso639LanguageCode(ptr noundef %41, ptr noundef %44)
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %52

47:                                               ; preds = %40
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !12
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %50, ptr %51, align 8, !tbaa !5
  store i64 0, ptr %5, align 8
  br label %60

52:                                               ; preds = %40
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %53, i32 1
  store ptr %54, ptr %8, align 8, !tbaa !5
  br label %35, !llvm.loop !13

55:                                               ; preds = %35
  store i64 -9223372036854775805, ptr %5, align 8
  br label %60

56:                                               ; preds = %29
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 3
  store ptr %58, ptr %7, align 8, !tbaa !5
  br label %24, !llvm.loop !15

59:                                               ; preds = %24
  store i64 -9223372036854775805, ptr %5, align 8
  br label %60

60:                                               ; preds = %59, %55, %47, %22, %15
  %61 = load i64, ptr %5, align 8
  ret i64 %61
}

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"", !6, i64 0, !6, i64 8}
!12 = !{!11, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @CompareIso639LanguageCode(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @LookupUnicodeString(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, ptr noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %3, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %.loopexit, label %7

7:                                                ; preds = %4
  %8 = icmp eq ptr %1, null
  %9 = icmp eq ptr %2, null
  %or.cond3 = or i1 %8, %9
  br i1 %or.cond3, label %.loopexit, label %.preheader26

.preheader26:                                     ; preds = %7
  %10 = load i8, ptr %1, align 1, !tbaa !5
  %.not29 = icmp eq i8 %10, 0
  br i1 %.not29, label %.loopexit, label %.lr.ph

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %.01830, i64 3
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %.not = icmp eq i8 %13, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !8

.lr.ph:                                           ; preds = %.preheader26, %11
  %.01830 = phi ptr [ %12, %11 ], [ %1, %.preheader26 ]
  %14 = tail call zeroext i8 @CompareIso639LanguageCode(ptr noundef %0, ptr noundef nonnull %.01830)
  %.not23 = icmp eq i8 %14, 0
  br i1 %.not23, label %11, label %.preheader

.preheader:                                       ; preds = %.lr.ph
  %15 = load ptr, ptr %2, align 8, !tbaa !10
  %.not2431 = icmp eq ptr %15, null
  br i1 %.not2431, label %.loopexit, label %.lr.ph33

.lr.ph33:                                         ; preds = %.preheader, %21
  %16 = phi ptr [ %23, %21 ], [ %15, %.preheader ]
  %.01732 = phi ptr [ %22, %21 ], [ %2, %.preheader ]
  %17 = tail call zeroext i8 @CompareIso639LanguageCode(ptr noundef %0, ptr noundef nonnull %16)
  %.not25 = icmp eq i8 %17, 0
  br i1 %.not25, label %21, label %18

18:                                               ; preds = %.lr.ph33
  %19 = getelementptr inbounds i8, ptr %.01732, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  store ptr %20, ptr %3, align 8, !tbaa !14
  br label %.loopexit

21:                                               ; preds = %.lr.ph33
  %22 = getelementptr inbounds i8, ptr %.01732, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !10
  %.not24 = icmp eq ptr %23, null
  br i1 %.not24, label %.loopexit, label %.lr.ph33, !llvm.loop !15

.loopexit:                                        ; preds = %11, %21, %.preheader26, %.preheader, %7, %4, %18
  %.0 = phi i64 [ 0, %18 ], [ -9223372036854775806, %4 ], [ -9223372036854775805, %7 ], [ -9223372036854775805, %.preheader ], [ -9223372036854775805, %.preheader26 ], [ -9223372036854775805, %21 ], [ -9223372036854775805, %11 ]
  ret i64 %.0
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!11, !12, i64 8}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !9}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass