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

; 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._IP4_INTERFACE = type { i32, %struct._LIST_ENTRY, i64, i32, i32, i32, i32, i8, ptr, ptr, ptr, ptr, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i32, %struct._LIST_ENTRY, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._IP4_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i64, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, %struct.IP4_ASSEMBLE_TABLE, %struct.IGMP_SERVICE_DATA, ptr, ptr, ptr, ptr, %struct.EFI_MANAGED_NETWORK_CONFIG_DATA, %struct.EFI_SIMPLE_NETWORK_MODE, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct.IP4_ASSEMBLE_TABLE = type { [31 x %struct._LIST_ENTRY] }
%struct.IGMP_SERVICE_DATA = type { i64, %struct._LIST_ENTRY }
%struct.EFI_MANAGED_NETWORK_CONFIG_DATA = type { i32, i32, i16, i8, i8, i8, i8, i8, i8, i8 }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }

; 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 ptr @Ip4SelectInterface(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  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
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = call ptr @Ip4FindNet(ptr noundef %12, i32 noundef %13)
  store ptr %14, ptr %8, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %24

17:                                               ; preds = %3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %17
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %23, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %74

24:                                               ; preds = %17, %3
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = call ptr @Ip4FindInterface(ptr noundef %25, i32 noundef %26)
  store ptr %27, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %37

30:                                               ; preds = %24
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %30
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %36, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %74

37:                                               ; preds = %30, %24
  store ptr null, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._IP4_SERVICE, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds %struct._LIST_ENTRY, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  store ptr %41, ptr %10, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %68, %37
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._IP4_SERVICE, ptr %44, i32 0, i32 5
  %46 = icmp ne ptr %43, %45
  br i1 %46, label %47, label %72

47:                                               ; preds = %42
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = ptrtoint ptr %48 to i64
  %50 = sub i64 %49, ptrtoint (ptr getelementptr inbounds (%struct._IP4_INTERFACE, ptr null, i32 0, i32 1) to i64)
  %51 = inttoptr i64 %50 to ptr
  store ptr %51, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %52, i32 0, i32 7
  %54 = load i8, ptr %53, align 8, !tbaa !23
  %55 = zext i8 %54 to i32
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %67

57:                                               ; preds = %47
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %65, label %60

60:                                               ; preds = %57
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %61, i32 0, i32 3
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %60, %57
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %66, ptr %9, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %65, %60, %47
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._LIST_ENTRY, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !24
  store ptr %71, ptr %10, align 8, !tbaa !5
  br label %42, !llvm.loop !25

72:                                               ; preds = %42
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %73, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %74

74:                                               ; preds = %72, %35, %22
  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
  %75 = load ptr, ptr %4, align 8
  ret ptr %75
}

declare ptr @Ip4FindNet(ptr noundef, i32 noundef) #2

declare ptr @Ip4FindInterface(ptr noundef, i32 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"_IP4_INTERFACE", !10, i64 0, !13, i64 8, !14, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !13, i64 96, !13, i64 112, !6, i64 128, !15, i64 136, !15, i64 168, !10, i64 200, !13, i64 208, !7, i64 224}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = !{!17, !6, i64 56}
!17 = !{!"_IP4_SERVICE", !10, i64 0, !18, i64 8, !14, i64 24, !14, i64 32, !13, i64 40, !13, i64 56, !6, i64 72, !6, i64 80, !15, i64 88, !19, i64 584, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !20, i64 640, !22, i64 660, !6, i64 1320, !6, i64 1328, !6, i64 1336, !6, i64 1344, !6, i64 1352, !10, i64 1360, !10, i64 1364}
!18 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!19 = !{!"", !14, i64 0, !13, i64 8}
!20 = !{!"", !10, i64 0, !10, i64 4, !21, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !15, i64 552, !15, i64 584, !15, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!23 = !{!12, !7, i64 48}
!24 = !{!13, !6, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local ptr @Ip4SelectInterface(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @Ip4FindNet(ptr noundef %0, i32 noundef %1) #2
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %8, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not24 = icmp eq i32 %7, 0
  br i1 %.not24, label %8, label %.loopexit

8:                                                ; preds = %5, %3
  %9 = tail call ptr @Ip4FindInterface(ptr noundef %0, i32 noundef %2) #2
  %.not25 = icmp eq ptr %9, null
  br i1 %.not25, label %13, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %9, i64 32
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %.not26 = icmp eq i32 %12, 0
  br i1 %.not26, label %13, label %.loopexit

13:                                               ; preds = %10, %8
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %.029 = load ptr, ptr %14, align 8, !tbaa !14
  %.not2730 = icmp eq ptr %.029, %14
  br i1 %.not2730, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %13, %27
  %.032 = phi ptr [ %.0, %27 ], [ %.029, %13 ]
  %.02031 = phi ptr [ %.1, %27 ], [ null, %13 ]
  %15 = ptrtoint ptr %.032 to i64
  %16 = add i64 %15, -8
  %17 = inttoptr i64 %16 to ptr
  %18 = getelementptr inbounds i8, ptr %17, i64 48
  %19 = load i8, ptr %18, align 8, !tbaa !15
  %.not28 = icmp eq i8 %19, 0
  br i1 %.not28, label %27, label %20

20:                                               ; preds = %.lr.ph
  %21 = icmp eq ptr %.02031, null
  br i1 %21, label %26, label %22

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %.02031, i64 32
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %22, %20
  br label %27

27:                                               ; preds = %.lr.ph, %22, %26
  %.1 = phi ptr [ %17, %26 ], [ %.02031, %22 ], [ %.02031, %.lr.ph ]
  %.0 = load ptr, ptr %.032, align 8, !tbaa !14
  %.not27 = icmp eq ptr %.0, %14
  br i1 %.not27, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %27, %13, %10, %5
  %.021 = phi ptr [ %4, %5 ], [ %9, %10 ], [ null, %13 ], [ %.1, %27 ]
  ret ptr %.021
}

declare ptr @Ip4FindNet(ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @Ip4FindInterface(ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { 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 32}
!6 = !{!"_IP4_INTERFACE", !7, i64 0, !10, i64 8, !12, i64 24, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !8, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !10, i64 96, !10, i64 112, !11, i64 128, !13, i64 136, !13, i64 168, !7, i64 200, !10, i64 208, !8, i64 224}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"", !8, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!6, !8, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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