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

; 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_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY = type { ptr, ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [134 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@gBS = external global ptr, align 8

; 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 zeroext i8 @DebugAssertEnabled() #1

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

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

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

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @DebugAssert(ptr noundef @.str, i64 noundef 556, ptr noundef @.str.3)
  br label %20

20:                                               ; preds = %19, %16
  br label %21

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

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr @gBS, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %24, i32 0, i32 35
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call i64 %26(ptr noundef %27, ptr noundef %28, ptr noundef %9, ptr noundef %10)
  store i64 %29, ptr %8, align 8, !tbaa !14
  %30 = load i64, ptr %8, align 8, !tbaa !14
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %23
  store i64 -9223372036854775805, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %62

33:                                               ; preds = %23
  store i64 -9223372036854775805, ptr %8, align 8, !tbaa !14
  store i64 0, ptr %11, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %56, %33
  %35 = load i64, ptr %11, align 8, !tbaa !14
  %36 = load i64, ptr %10, align 8, !tbaa !14
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %38, label %59

38:                                               ; preds = %34
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i64, ptr %11, align 8, !tbaa !14
  %41 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %39, i64 %40
  %42 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = icmp eq ptr %43, %44
  br i1 %45, label %46, label %55

46:                                               ; preds = %38
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %11, align 8, !tbaa !14
  %49 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %47, i64 %48
  %50 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !17
  %52 = and i32 %51, 8
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %46
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %59

55:                                               ; preds = %46, %38
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %11, align 8, !tbaa !14
  %58 = add i64 %57, 1
  store i64 %58, ptr %11, align 8, !tbaa !14
  br label %34, !llvm.loop !18

59:                                               ; preds = %54, %34
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  call void @FreePool(ptr noundef %60)
  %61 = load i64, ptr %8, align 8, !tbaa !14
  store i64 %61, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %62

62:                                               ; preds = %59, %32
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %63 = load i64, ptr %4, align 8
  ret i64 %63
}

declare void @FreePool(ptr 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, !6, i64 296}
!10 = !{!"", !11, 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, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20}
!17 = !{!16, !13, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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_OPEN_PROTOCOL_INFORMATION_ENTRY = type { ptr, ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [134 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: nounwind uwtable
define dso_local range(i64 -9223372036854775805, 1) i64 @EfiTestChildHandle(ptr noundef %0, ptr noundef readnone %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = tail call zeroext i8 @DebugAssertEnabled() #3
  %7 = icmp eq i8 %6, 0
  %8 = icmp ne ptr %2, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %10, label %9

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

10:                                               ; preds = %9, %3
  %11 = load ptr, ptr @gBS, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 296
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = call i64 %13(ptr noundef %0, ptr noundef %2, ptr noundef nonnull %4, ptr noundef nonnull %5) #3
  %15 = icmp slt i64 %14, 0
  br i1 %15, label %27, label %.preheader

.preheader:                                       ; preds = %10
  %16 = load i64, ptr %5, align 8, !tbaa !14
  %.not16 = icmp eq i64 %16, 0
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %25
  %.013 = phi i64 [ %26, %25 ], [ 0, %.preheader ]
  %17 = getelementptr inbounds %struct.EFI_OPEN_PROTOCOL_INFORMATION_ENTRY, ptr %.pre, i64 %.013
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = icmp eq ptr %19, %1
  br i1 %20, label %21, label %25

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %17, i64 16
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = and i32 %23, 8
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %25, label %._crit_edge

25:                                               ; preds = %.lr.ph, %21
  %26 = add nuw i64 %.013, 1
  %exitcond.not = icmp eq i64 %26, %16
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %25, %21, %.preheader
  %.011 = phi i64 [ -9223372036854775805, %.preheader ], [ 0, %21 ], [ -9223372036854775805, %25 ]
  call void @FreePool(ptr noundef %.pre) #3
  br label %27

27:                                               ; preds = %10, %._crit_edge
  %.012 = phi i64 [ %.011, %._crit_edge ], [ -9223372036854775805, %10 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i64 %.012
}

declare void @FreePool(ptr 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, !6, i64 296}
!10 = !{!"", !11, 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, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20}
!17 = !{!16, !13, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass