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

; 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_IPv4_ADDRESS = type { [4 x i8] }
%struct._UDP4_INSTANCE_DATA_ = type { i32, %struct._LIST_ENTRY, ptr, %struct._EFI_UDP4_PROTOCOL, %struct.EFI_UDP4_CONFIG_DATA, ptr, i8, i8, %struct.NET_MAP, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i16, i64, ptr, i8 }
%struct._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_UDP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_UDP4_SESSION_DATA = type { %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }

@mZeroIp4Addr = external global %struct.EFI_IPv4_ADDRESS, align 1

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

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

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

declare i32 @SwapBytes32(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @Udp4MatchDgram(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %9, i32 0, i32 4
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 1
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i8 1, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

16:                                               ; preds = %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %17, i32 0, i32 2
  %19 = load i8, ptr %18, align 2, !tbaa !14
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %31, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.EFI_UDP4_SESSION_DATA, ptr %22, i32 0, i32 3
  %24 = load i16, ptr %23, align 2, !tbaa !15
  %25 = zext i16 %24 to i32
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %26, i32 0, i32 12
  %28 = load i16, ptr %27, align 2, !tbaa !17
  %29 = zext i16 %28 to i32
  %30 = icmp ne i32 %25, %29
  br i1 %30, label %47, label %31

31:                                               ; preds = %21, %16
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %32, i32 0, i32 14
  %34 = load i16, ptr %33, align 4, !tbaa !18
  %35 = zext i16 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %48

37:                                               ; preds = %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.EFI_UDP4_SESSION_DATA, ptr %38, i32 0, i32 1
  %40 = load i16, ptr %39, align 2, !tbaa !19
  %41 = zext i16 %40 to i32
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %42, i32 0, i32 14
  %44 = load i16, ptr %43, align 4, !tbaa !18
  %45 = zext i16 %44 to i32
  %46 = icmp ne i32 %41, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %37, %21
  store i8 0, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

48:                                               ; preds = %37, %31
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %49, i32 0, i32 13
  %51 = call i64 @CompareMem(ptr noundef %50, ptr noundef @mZeroIp4Addr, i64 noundef 4)
  %52 = icmp eq i64 %51, 0
  br i1 %52, label %61, label %53

53:                                               ; preds = %48
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %54, i32 0, i32 13
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EFI_UDP4_SESSION_DATA, ptr %56, i32 0, i32 0
  %58 = call i64 @CompareMem(ptr noundef %55, ptr noundef %57, i64 noundef 4)
  %59 = icmp eq i64 %58, 0
  br i1 %59, label %61, label %60

60:                                               ; preds = %53
  store i8 0, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

61:                                               ; preds = %53, %48
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %62, i32 0, i32 10
  %64 = call i64 @CompareMem(ptr noundef %63, ptr noundef @mZeroIp4Addr, i64 noundef 4)
  %65 = icmp eq i64 %64, 0
  br i1 %65, label %73, label %66

66:                                               ; preds = %61
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.EFI_UDP4_SESSION_DATA, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %69, i32 0, i32 10
  %71 = call i64 @CompareMem(ptr noundef %68, ptr noundef %70, i64 noundef 4)
  %72 = icmp eq i64 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %66, %61
  store i8 1, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

74:                                               ; preds = %66
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.EFI_UDP4_SESSION_DATA, ptr %75, i32 0, i32 2
  %77 = call ptr @CopyMem(ptr noundef %7, ptr noundef %76, i64 noundef 4)
  %78 = load i32, ptr %7, align 4, !tbaa !20
  %79 = icmp eq i32 %78, -1
  br i1 %79, label %80, label %87

80:                                               ; preds = %74
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %81, i32 0, i32 0
  %83 = load i8, ptr %82, align 4, !tbaa !21
  %84 = zext i8 %83 to i32
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %80
  store i8 1, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

87:                                               ; preds = %80, %74
  %88 = load i32, ptr %7, align 4, !tbaa !20
  %89 = call i32 @SwapBytes32(i32 noundef %88)
  %90 = and i32 %89, -268435456
  %91 = icmp eq i32 %90, -536870912
  br i1 %91, label %92, label %101

92:                                               ; preds = %87
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %93, i32 0, i32 10
  %95 = load i32, ptr %7, align 4, !tbaa !20
  %96 = zext i32 %95 to i64
  %97 = inttoptr i64 %96 to ptr
  %98 = call ptr @NetMapFindKey(ptr noundef %94, ptr noundef %97)
  %99 = icmp ne ptr %98, null
  br i1 %99, label %100, label %101

100:                                              ; preds = %92
  store i8 1, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

101:                                              ; preds = %92, %87
  store i8 0, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %102

102:                                              ; preds = %101, %100, %86, %73, %60, %47, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %103 = load i8, ptr %3, align 1
  ret i8 %103
}

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, !7, i64 1}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !11, i64 8, !11, i64 12, !7, i64 16, !12, i64 17, !12, i64 21, !13, i64 26, !12, i64 28, !13, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !7, i64 2}
!15 = !{!16, !13, i64 10}
!16 = !{!"", !12, i64 0, !13, i64 4, !12, i64 6, !13, i64 10}
!17 = !{!10, !13, i64 26}
!18 = !{!10, !13, i64 32}
!19 = !{!16, !13, i64 4}
!20 = !{!11, !11, i64 0}
!21 = !{!10, !7, i64 0}


; 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_IPv4_ADDRESS = type { [4 x i8] }

@mZeroIp4Addr = external global %struct.EFI_IPv4_ADDRESS, align 1

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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) #0

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

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #1

declare ptr @NetMapFindKey(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @Udp4MatchDgram(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = getelementptr inbounds i8, ptr %0, i64 97
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %7, label %53

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 98
  %9 = load i8, ptr %8, align 2, !tbaa !12
  %.not18 = icmp eq i8 %9, 0
  br i1 %.not18, label %10, label %15

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 10
  %12 = load i16, ptr %11, align 2, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 122
  %14 = load i16, ptr %13, align 2, !tbaa !15
  %.not19 = icmp eq i16 %12, %14
  br i1 %.not19, label %15, label %53

15:                                               ; preds = %10, %7
  %16 = getelementptr inbounds i8, ptr %0, i64 128
  %17 = load i16, ptr %16, align 4, !tbaa !16
  %.not20 = icmp eq i16 %17, 0
  br i1 %.not20, label %21, label %18

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %1, i64 4
  %20 = load i16, ptr %19, align 2, !tbaa !17
  %.not21 = icmp eq i16 %20, %17
  br i1 %.not21, label %21, label %53

21:                                               ; preds = %18, %15
  %22 = getelementptr inbounds i8, ptr %0, i64 124
  %23 = tail call i64 @CompareMem(ptr noundef nonnull %22, ptr noundef nonnull @mZeroIp4Addr, i64 noundef 4) #3
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %28, label %25

25:                                               ; preds = %21
  %26 = tail call i64 @CompareMem(ptr noundef nonnull %22, ptr noundef %1, i64 noundef 4) #3
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %53

28:                                               ; preds = %25, %21
  %29 = getelementptr inbounds i8, ptr %0, i64 113
  %30 = tail call i64 @CompareMem(ptr noundef nonnull %29, ptr noundef nonnull @mZeroIp4Addr, i64 noundef 4) #3
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %53, label %32

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %1, i64 6
  %34 = tail call i64 @CompareMem(ptr noundef nonnull %33, ptr noundef nonnull %29, i64 noundef 4) #3
  %35 = icmp eq i64 %34, 0
  br i1 %35, label %53, label %36

36:                                               ; preds = %32
  %37 = call ptr @CopyMem(ptr noundef nonnull %3, ptr noundef nonnull %33, i64 noundef 4) #3
  %38 = load i32, ptr %3, align 4, !tbaa !18
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %40, label %42

40:                                               ; preds = %36
  %41 = load i8, ptr %4, align 4, !tbaa !19
  %.not22 = icmp eq i8 %41, 0
  br i1 %.not22, label %42, label %53

42:                                               ; preds = %40, %36
  %43 = call i32 @SwapBytes32(i32 noundef %38) #3
  %44 = and i32 %43, -268435456
  %45 = icmp eq i32 %44, -536870912
  br i1 %45, label %46, label %52

46:                                               ; preds = %42
  %47 = getelementptr inbounds i8, ptr %0, i64 232
  %48 = load i32, ptr %3, align 4, !tbaa !18
  %49 = zext i32 %48 to i64
  %50 = inttoptr i64 %49 to ptr
  %51 = call ptr @NetMapFindKey(ptr noundef nonnull %47, ptr noundef %50) #3
  %.not23 = icmp eq ptr %51, null
  br i1 %.not23, label %52, label %53

52:                                               ; preds = %46, %42
  br label %53

53:                                               ; preds = %46, %40, %28, %32, %25, %10, %18, %2, %52
  %.0 = phi i8 [ 0, %52 ], [ 1, %2 ], [ 0, %18 ], [ 0, %10 ], [ 0, %25 ], [ 1, %32 ], [ 1, %28 ], [ 1, %40 ], [ 1, %46 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i8 %.0
}

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, !7, i64 1}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !9, i64 8, !9, i64 12, !7, i64 16, !10, i64 17, !10, i64 21, !11, i64 26, !10, i64 28, !11, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"", !7, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!6, !7, i64 2}
!13 = !{!14, !11, i64 10}
!14 = !{!"", !10, i64 0, !11, i64 4, !10, i64 6, !11, i64 10}
!15 = !{!6, !11, i64 26}
!16 = !{!6, !11, i64 32}
!17 = !{!14, !11, i64 4}
!18 = !{!9, !9, i64 0}
!19 = !{!6, !7, i64 0}


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