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

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

@gBS = external global ptr, align 8
@gEfiManagedNetworkServiceBindingProtocolGuid = external global %struct.GUID, align 4

; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @Ip4ConfigIsNicExist(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  %10 = alloca %struct.EFI_MAC_ADDRESS, align 1
  %11 = 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 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  %12 = load ptr, ptr @gBS, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %12, i32 0, i32 37
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = call i64 %14(i32 noundef 2, ptr noundef @gEfiManagedNetworkServiceBindingProtocolGuid, ptr noundef null, ptr noundef %6, ptr noundef %5)
  store i64 %15, ptr %4, align 8, !tbaa !14
  %16 = load i64, ptr %4, align 8, !tbaa !14
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %1
  store i8 0, ptr %2, align 1
  store i32 1, ptr %11, align 4
  br label %59

19:                                               ; preds = %1
  store i8 0, ptr %8, align 1, !tbaa !15
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %20

20:                                               ; preds = %52, %19
  %21 = load i64, ptr %7, align 8, !tbaa !14
  %22 = load i64, ptr %6, align 8, !tbaa !14
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %55

24:                                               ; preds = %20
  store i64 0, ptr %9, align 8, !tbaa !14
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %7, align 8, !tbaa !14
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = call i64 @NetLibGetMacAddress(ptr noundef %28, ptr noundef %10, ptr noundef %9)
  store i64 %29, ptr %4, align 8, !tbaa !14
  %30 = load i64, ptr %4, align 8, !tbaa !14
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  store i8 0, ptr %8, align 1, !tbaa !15
  br label %56

33:                                               ; preds = %24
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NIC_ADDR, ptr %34, i32 0, i32 1
  %36 = load i8, ptr %35, align 2, !tbaa !16
  %37 = zext i8 %36 to i64
  %38 = load i64, ptr %9, align 8, !tbaa !14
  %39 = icmp eq i64 %37, %38
  br i1 %39, label %40, label %51

40:                                               ; preds = %33
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.NIC_ADDR, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [32 x i8], ptr %43, i64 0, i64 0
  %45 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %10, i32 0, i32 0
  %46 = getelementptr inbounds [32 x i8], ptr %45, i64 0, i64 0
  %47 = load i64, ptr %9, align 8, !tbaa !14
  %48 = call i64 @CompareMem(ptr noundef %44, ptr noundef %46, i64 noundef %47)
  %49 = icmp eq i64 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %40
  store i8 1, ptr %8, align 1, !tbaa !15
  br label %56

51:                                               ; preds = %40, %33
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %7, align 8, !tbaa !14
  %54 = add i64 %53, 1
  store i64 %54, ptr %7, align 8, !tbaa !14
  br label %20, !llvm.loop !20

55:                                               ; preds = %20
  br label %56

56:                                               ; preds = %55, %50, %32
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  call void @FreePool(ptr noundef %57)
  %58 = load i8, ptr %8, align 1, !tbaa !15
  store i8 %58, ptr %2, align 1
  store i32 1, ptr %11, align 4
  br label %59

59:                                               ; preds = %56, %18
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  %60 = load i8, ptr %2, align 1
  ret i8 %60
}

declare i64 @NetLibGetMacAddress(ptr noundef, ptr noundef, ptr noundef) #2

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #2

declare void @FreePool(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 312}
!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 = !{!7, !7, i64 0}
!16 = !{!17, !7, i64 2}
!17 = !{!"", !18, i64 0, !7, i64 2, !19, i64 3}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

@gBS = external local_unnamed_addr global ptr, align 8
@gEfiManagedNetworkServiceBindingProtocolGuid = external global %struct.GUID, align 4

; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @Ip4ConfigIsNicExist(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.EFI_MAC_ADDRESS, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  %6 = load ptr, ptr @gBS, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 312
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = call i64 %8(i32 noundef 2, ptr noundef nonnull @gEfiManagedNetworkServiceBindingProtocolGuid, ptr noundef null, ptr noundef nonnull %3, ptr noundef nonnull %2) #3
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %33, label %.preheader

.preheader:                                       ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 3
  %12 = load i64, ptr %3, align 8, !tbaa !14
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %0, i64 2
  br label %14

14:                                               ; preds = %.lr.ph, %28
  %.0811 = phi i64 [ 0, %.lr.ph ], [ %29, %28 ]
  store i64 0, ptr %4, align 8, !tbaa !14
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %15, i64 %.0811
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = call i64 @NetLibGetMacAddress(ptr noundef %17, ptr noundef nonnull %5, ptr noundef nonnull %4) #3
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %._crit_edge, label %20

20:                                               ; preds = %14
  %21 = load i8, ptr %13, align 2, !tbaa !15
  %22 = zext i8 %21 to i64
  %23 = load i64, ptr %4, align 8, !tbaa !14
  %24 = icmp eq i64 %23, %22
  br i1 %24, label %25, label %28

25:                                               ; preds = %20
  %26 = call i64 @CompareMem(ptr noundef nonnull %11, ptr noundef nonnull %5, i64 noundef %22) #3
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %._crit_edge, label %28

28:                                               ; preds = %20, %25
  %29 = add nuw i64 %.0811, 1
  %30 = load i64, ptr %3, align 8, !tbaa !14
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %14, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %28, %14, %25, %.preheader
  %.0 = phi i8 [ 0, %.preheader ], [ 1, %25 ], [ 0, %14 ], [ 0, %28 ]
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %32) #3
  br label %33

33:                                               ; preds = %1, %._crit_edge
  %.09 = phi i8 [ %.0, %._crit_edge ], [ 0, %1 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret i8 %.09
}

declare i64 @NetLibGetMacAddress(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 312}
!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, !7, i64 2}
!16 = !{!"", !17, i64 0, !7, i64 2, !18, i64 3}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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