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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

declare void @FreePool(ptr noundef) #1

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

8:                                                ; preds = %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %41

9:                                                ; preds = %1
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %10

10:                                               ; preds = %36, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %11, i64 %12
  %14 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %39

17:                                               ; preds = %10
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %18, i64 %19
  %21 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  call void @FreePool(ptr noundef %22)
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %23, i64 %24
  %26 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %35

29:                                               ; preds = %17
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %30, i64 %31
  %33 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  call void @FreePool(ptr noundef %34)
  br label %35

35:                                               ; preds = %29, %17
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %4, align 8, !tbaa !9
  br label %10, !llvm.loop !14

39:                                               ; preds = %10
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  call void @FreePool(ptr noundef %40)
  store i64 0, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %41

41:                                               ; preds = %39, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %42 = load i64, ptr %2, align 8
  ret i64 %42
}

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


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

%struct.EFI_UNICODE_STRING_TABLE = type { ptr, ptr }

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @FreeUnicodeStringTable(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %12, label %.preheader

.preheader:                                       ; preds = %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not16 = icmp eq ptr %3, null
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %8
  %4 = phi ptr [ %11, %8 ], [ %3, %.preheader ]
  %.017 = phi i64 [ %9, %8 ], [ 0, %.preheader ]
  tail call void @FreePool(ptr noundef nonnull %4) #2
  %5 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %0, i64 %.017, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %.not15 = icmp eq ptr %6, null
  br i1 %.not15, label %8, label %7

7:                                                ; preds = %.lr.ph
  tail call void @FreePool(ptr noundef nonnull %6) #2
  br label %8

8:                                                ; preds = %.lr.ph, %7
  %9 = add i64 %.017, 1
  %10 = getelementptr inbounds %struct.EFI_UNICODE_STRING_TABLE, ptr %0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %8, %.preheader
  tail call void @FreePool(ptr noundef nonnull %0) #2
  br label %12

12:                                               ; preds = %1, %._crit_edge
  ret i64 0
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass