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

; 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_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._LIST_ENTRY = 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 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%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 }

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ip4GetNetCast(i32 noundef, ptr noundef) #0

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

18:                                               ; preds = %3
  store i64 1, ptr %10, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %18, %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._IP4_SERVICE, ptr %20, i32 0, i32 5
  %22 = getelementptr inbounds %struct._LIST_ENTRY, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !22
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %53, %19
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._IP4_SERVICE, ptr %26, i32 0, i32 5
  %28 = icmp ne ptr %25, %27
  br i1 %28, label %29, label %57

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = sub i64 %31, ptrtoint (ptr getelementptr inbounds (%struct._IP4_INTERFACE, ptr null, i32 0, i32 1) to i64)
  %33 = inttoptr i64 %32 to ptr
  store ptr %33, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %34, i32 0, i32 7
  %36 = load i8, ptr %35, align 8, !tbaa !23
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %43

38:                                               ; preds = %29
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = call i64 @Ip4GetNetCast(i32 noundef %39, ptr noundef %40)
  %42 = icmp sge i64 %41, 4
  br i1 %42, label %43, label %44

43:                                               ; preds = %38, %29
  br label %53

44:                                               ; preds = %38
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call i64 @Ip4GetNetCast(i32 noundef %45, ptr noundef %46)
  store i64 %47, ptr %11, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !11
  %49 = icmp sgt i64 %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %44
  %51 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %51, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %87

52:                                               ; preds = %44
  br label %53

53:                                               ; preds = %52, %43
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._LIST_ENTRY, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !25
  store ptr %56, ptr %8, align 8, !tbaa !5
  br label %24, !llvm.loop !26

57:                                               ; preds = %24
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = icmp eq i32 %58, -1
  br i1 %59, label %60, label %73

60:                                               ; preds = %57
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = call ptr @Ip4FindNet(ptr noundef %61, i32 noundef %62)
  store ptr %63, ptr %9, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %72

66:                                               ; preds = %60
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = call i64 @Ip4GetNetCast(i32 noundef %67, ptr noundef %68)
  %70 = icmp sge i64 %69, 4
  br i1 %70, label %72, label %71

71:                                               ; preds = %66
  store i64 4, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %87

72:                                               ; preds = %66, %60
  br label %85

73:                                               ; preds = %57
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = and i32 %74, -268435456
  %76 = icmp eq i32 %75, -536870912
  br i1 %76, label %77, label %84

77:                                               ; preds = %73
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._IP4_SERVICE, ptr %78, i32 0, i32 9
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = call ptr @Ip4FindGroup(ptr noundef %79, i32 noundef %80)
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %84

83:                                               ; preds = %77
  store i64 3, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %87

84:                                               ; preds = %77, %73
  br label %85

85:                                               ; preds = %84, %72
  %86 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %86, ptr %4, align 8
  store i32 1, ptr %12, align 4
  br label %87

87:                                               ; preds = %85, %83, %71, %50
  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
  %88 = load i64, ptr %4, align 8
  ret i64 %88
}

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @Ip4FindNet(ptr noundef, i32 noundef) #0

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !7, i64 653}
!14 = !{!"_IP4_SERVICE", !10, i64 0, !15, i64 8, !12, i64 24, !12, i64 32, !16, i64 40, !16, i64 56, !6, i64 72, !6, i64 80, !17, i64 88, !18, i64 584, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !19, i64 640, !21, i64 660, !6, i64 1320, !6, i64 1328, !6, i64 1336, !6, i64 1344, !6, i64 1352, !10, i64 1360, !10, i64 1364}
!15 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"", !7, i64 0}
!18 = !{!"", !12, i64 0, !16, i64 8}
!19 = !{!"", !10, i64 0, !10, i64 4, !20, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!"", !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, !17, i64 552, !17, i64 584, !17, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!22 = !{!14, !6, i64 56}
!23 = !{!24, !7, i64 48}
!24 = !{!"_IP4_INTERFACE", !10, i64 0, !16, i64 8, !12, 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, !16, i64 96, !16, i64 112, !6, i64 128, !17, i64 136, !17, i64 168, !10, i64 200, !16, i64 208, !7, i64 224}
!25 = !{!16, !6, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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
declare dso_local i64 @Ip4GetNetCast(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, -9223372036854775808) i64 @Ip4GetHostCast(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 653
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %.not = icmp ne i8 %5, 0
  %spec.store.select = zext i1 %.not to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %.02331 = load ptr, ptr %6, align 8, !tbaa !19
  %.not2732 = icmp eq ptr %.02331, %6
  br i1 %.not2732, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %18
  %.02333 = phi ptr [ %.023, %18 ], [ %.02331, %3 ]
  %7 = ptrtoint ptr %.02333 to i64
  %8 = add i64 %7, -8
  %9 = inttoptr i64 %8 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 48
  %11 = load i8, ptr %10, align 8, !tbaa !20
  %.not30 = icmp eq i8 %11, 0
  br i1 %.not30, label %18, label %12

12:                                               ; preds = %.lr.ph
  %13 = tail call i64 @Ip4GetNetCast(i32 noundef %2, ptr noundef nonnull %9)
  %14 = icmp sgt i64 %13, 3
  br i1 %14, label %18, label %15

15:                                               ; preds = %12
  %16 = tail call i64 @Ip4GetNetCast(i32 noundef %1, ptr noundef nonnull %9)
  %17 = icmp sgt i64 %16, %spec.store.select
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %15, %.lr.ph, %12
  %.023 = load ptr, ptr %.02333, align 8, !tbaa !19
  %.not27 = icmp eq ptr %.023, %6
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %18, %3
  %19 = icmp eq i32 %1, -1
  br i1 %19, label %20, label %25

20:                                               ; preds = %._crit_edge
  %21 = tail call ptr @Ip4FindNet(ptr noundef %0, i32 noundef %2)
  %.not29 = icmp eq ptr %21, null
  br i1 %.not29, label %31, label %22

22:                                               ; preds = %20
  %23 = tail call i64 @Ip4GetNetCast(i32 noundef %2, ptr noundef nonnull %21)
  %24 = icmp sgt i64 %23, 3
  br i1 %24, label %31, label %.loopexit

25:                                               ; preds = %._crit_edge
  %26 = and i32 %1, -268435456
  %27 = icmp eq i32 %26, -536870912
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %0, i64 584
  %30 = tail call ptr @Ip4FindGroup(ptr noundef nonnull %29, i32 noundef %1) #2
  %.not28 = icmp eq ptr %30, null
  br i1 %.not28, label %31, label %.loopexit

31:                                               ; preds = %25, %28, %20, %22
  br label %.loopexit

.loopexit:                                        ; preds = %15, %28, %22, %31
  %.0 = phi i64 [ %spec.store.select, %31 ], [ 4, %22 ], [ 3, %28 ], [ %16, %15 ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @Ip4FindNet(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @Ip4FindGroup(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, !8, i64 653}
!6 = !{!"_IP4_SERVICE", !7, i64 0, !10, i64 8, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 56, !11, i64 72, !11, i64 80, !14, i64 88, !15, i64 584, !11, i64 608, !11, i64 616, !11, i64 624, !11, i64 632, !16, i64 640, !18, i64 660, !11, i64 1320, !11, i64 1328, !11, i64 1336, !11, i64 1344, !11, i64 1352, !7, i64 1360, !7, i64 1364}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!14 = !{!"", !8, i64 0}
!15 = !{!"", !12, i64 0, !13, i64 8}
!16 = !{!"", !7, i64 0, !7, i64 4, !17, i64 8, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16}
!17 = !{!"short", !8, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !8, i64 40, !14, i64 552, !14, i64 584, !14, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!19 = !{!13, !11, i64 0}
!20 = !{!21, !8, i64 48}
!21 = !{!"_IP4_INTERFACE", !7, i64 0, !13, 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, !13, i64 96, !13, i64 112, !11, i64 128, !14, i64 136, !14, i64 168, !7, i64 200, !13, i64 208, !8, i64 224}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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