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

; 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_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct.EFI_UNICODE_STRING_TABLE = type { ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%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 }

@gPxeBcComponentName = external dso_local global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@mPxeBcControllerNameTable = external dso_local global [2 x %struct.EFI_UNICODE_STRING_TABLE], align 16
@gEfiArpProtocolGuid = external global %struct.GUID, align 4
@gEfiDhcp4ProtocolGuid = external global %struct.GUID, align 4
@gEfiIp4ProtocolGuid = external global %struct.GUID, align 4
@gEfiUdp4ProtocolGuid = external global %struct.GUID, align 4
@gEfiMtftp4ProtocolGuid = external global %struct.GUID, align 4
@gBS = external global ptr, align 8
@gEfiPxeBaseCodeProtocolGuid = external global %struct.GUID, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @PxeBcComponentNameGetControllerName(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %21, label %18

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

21:                                               ; preds = %18, %5
  store i64 -9223372036854775805, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %73

22:                                               ; preds = %18
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call ptr @NetLibGetNicHandle(ptr noundef %23, ptr noundef @gEfiArpProtocolGuid)
  store ptr %24, ptr %13, align 8, !tbaa !5
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %52

27:                                               ; preds = %22
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = call ptr @NetLibGetNicHandle(ptr noundef %28, ptr noundef @gEfiDhcp4ProtocolGuid)
  store ptr %29, ptr %13, align 8, !tbaa !5
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %51

32:                                               ; preds = %27
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = call ptr @NetLibGetNicHandle(ptr noundef %33, ptr noundef @gEfiIp4ProtocolGuid)
  store ptr %34, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %50

37:                                               ; preds = %32
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = call ptr @NetLibGetNicHandle(ptr noundef %38, ptr noundef @gEfiUdp4ProtocolGuid)
  store ptr %39, ptr %13, align 8, !tbaa !5
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %49

42:                                               ; preds = %37
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call ptr @NetLibGetNicHandle(ptr noundef %43, ptr noundef @gEfiMtftp4ProtocolGuid)
  store ptr %44, ptr %13, align 8, !tbaa !5
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  store i64 -9223372036854775805, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %73

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %48, %37
  br label %50

50:                                               ; preds = %49, %32
  br label %51

51:                                               ; preds = %50, %27
  br label %52

52:                                               ; preds = %51, %22
  %53 = load ptr, ptr @gBS, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %53, i32 0, i32 33
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = call i64 %55(ptr noundef %56, ptr noundef @gEfiPxeBaseCodeProtocolGuid, ptr noundef %12, ptr noundef null, ptr noundef null, i32 noundef 2)
  store i64 %57, ptr %14, align 8, !tbaa !14
  %58 = load i64, ptr %14, align 8, !tbaa !14
  %59 = icmp slt i64 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %52
  %61 = load i64, ptr %14, align 8, !tbaa !14
  store i64 %61, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %73

62:                                               ; preds = %52
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._EFI_COMPONENT_NAME_PROTOCOL, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = icmp eq ptr %68, @gPxeBcComponentName
  %70 = zext i1 %69 to i32
  %71 = trunc i32 %70 to i8
  %72 = call i64 @LookupUnicodeString2(ptr noundef %63, ptr noundef %66, ptr noundef @mPxeBcControllerNameTable, ptr noundef %67, i8 noundef zeroext %71)
  store i64 %72, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %73

73:                                               ; preds = %62, %60, %47, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %74 = load i64, ptr %6, align 8
  ret i64 %74
}

declare i64 @LookupUnicodeString2(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) #1

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

declare ptr @NetLibGetNicHandle(ptr noundef, ptr noundef) #1

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 280}
!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 16}
!16 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}


; 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_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct.EFI_UNICODE_STRING_TABLE = type { ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }

@gPxeBcComponentName = external dso_local global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@mPxeBcControllerNameTable = external dso_local global [2 x %struct.EFI_UNICODE_STRING_TABLE], align 16
@gEfiArpProtocolGuid = external global %struct.GUID, align 4
@gEfiDhcp4ProtocolGuid = external global %struct.GUID, align 4
@gEfiIp4ProtocolGuid = external global %struct.GUID, align 4
@gEfiUdp4ProtocolGuid = external global %struct.GUID, align 4
@gEfiMtftp4ProtocolGuid = external global %struct.GUID, align 4
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiPxeBaseCodeProtocolGuid = external global %struct.GUID, align 4

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

9:                                                ; preds = %5
  %10 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiArpProtocolGuid) #3
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %24

12:                                               ; preds = %9
  %13 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiDhcp4ProtocolGuid) #3
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %24

15:                                               ; preds = %12
  %16 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiIp4ProtocolGuid) #3
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %24

18:                                               ; preds = %15
  %19 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiUdp4ProtocolGuid) #3
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = tail call ptr @NetLibGetNicHandle(ptr noundef nonnull %1, ptr noundef nonnull @gEfiMtftp4ProtocolGuid) #3
  %23 = icmp eq ptr %22, null
  br i1 %23, label %36, label %24

24:                                               ; preds = %12, %18, %21, %15, %9
  %.020 = phi ptr [ %22, %21 ], [ %19, %18 ], [ %16, %15 ], [ %13, %12 ], [ %10, %9 ]
  %25 = load ptr, ptr @gBS, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 280
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = call i64 %27(ptr noundef nonnull %.020, ptr noundef nonnull @gEfiPxeBaseCodeProtocolGuid, ptr noundef nonnull %6, ptr noundef null, ptr noundef null, i32 noundef 2) #3
  %29 = icmp slt i64 %28, 0
  br i1 %29, label %36, label %30

30:                                               ; preds = %24
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = icmp eq ptr %0, @gPxeBcComponentName
  %34 = zext i1 %33 to i8
  %35 = call i64 @LookupUnicodeString2(ptr noundef %3, ptr noundef %32, ptr noundef nonnull @mPxeBcControllerNameTable, ptr noundef %4, i8 noundef zeroext %34) #3
  br label %36

36:                                               ; preds = %24, %21, %5, %30
  %.0 = phi i64 [ %35, %30 ], [ -9223372036854775805, %5 ], [ -9223372036854775805, %21 ], [ %28, %24 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i64 %.0
}

declare i64 @LookupUnicodeString2(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

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

declare ptr @NetLibGetNicHandle(ptr noundef, 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) #2

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 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 280}
!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 = !{!15, !6, i64 16}
!15 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass