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

; 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_MTFTP4_OVERRIDE_DATA = type { %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, i16, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._MTFTP4_PROTOCOL = type { i32, %struct._LIST_ENTRY, %struct._EFI_MTFTP4_PROTOCOL, i64, i8, ptr, ptr, %struct.EFI_MTFTP4_CONFIG_DATA, ptr, %struct.MTFTP4_OPTION, i16, i16, i16, %struct._LIST_ENTRY, i32, i16, i16, i32, ptr, ptr, i32, i32, i32, i32, i32, i16, i8, ptr }
%struct._EFI_MTFTP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_MTFTP4_CONFIG_DATA = type { i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, i16, i16 }
%struct.MTFTP4_OPTION = type { i16, i8, i32, i32, i16, i8, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }

; 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

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

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

18:                                               ; preds = %2
  store i8 0, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %20, i32 0, i32 7
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.EFI_MTFTP4_OVERRIDE_DATA, ptr %22, i32 0, i32 0
  %24 = call ptr @CopyMem(ptr noundef %9, ptr noundef %23, i64 noundef 4)
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = call i32 @SwapBytes32(i32 noundef %25)
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_MTFTP4_CONFIG_DATA, ptr %27, i32 0, i32 0
  %29 = load i8, ptr %28, align 2, !tbaa !11
  %30 = icmp ne i8 %29, 0
  br i1 %30, label %59, label %31

31:                                               ; preds = %19
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %59

34:                                               ; preds = %31
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.EFI_MTFTP4_CONFIG_DATA, ptr %35, i32 0, i32 2
  %37 = call ptr @CopyMem(ptr noundef %8, ptr noundef %36, i64 noundef 4)
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.EFI_MTFTP4_CONFIG_DATA, ptr %38, i32 0, i32 1
  %40 = call ptr @CopyMem(ptr noundef %7, ptr noundef %39, i64 noundef 4)
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = call i32 @SwapBytes32(i32 noundef %41)
  store i32 %42, ptr %8, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = call i32 @SwapBytes32(i32 noundef %43)
  store i32 %44, ptr %7, align 4, !tbaa !9
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = call zeroext i8 @NetIp4IsUnicast(i32 noundef %45, i32 noundef %46)
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %57

49:                                               ; preds = %34
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = and i32 %50, %51
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = and i32 %53, %54
  %56 = icmp eq i32 %52, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %49, %34
  store i8 0, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

58:                                               ; preds = %49
  br label %59

59:                                               ; preds = %58, %31, %19
  store i8 1, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %60

60:                                               ; preds = %59, %57, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %61 = load i8, ptr %3, align 1
  ret i8 %61
}

declare zeroext i8 @NetIp4IsUnicast(i32 noundef, i32 noundef) #1

declare i32 @SwapBytes32(i32 noundef) #1

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !7, i64 0, !13, i64 1, !13, i64 5, !14, i64 10, !13, i64 12, !13, i64 16, !14, i64 20, !14, i64 22, !14, i64 24}
!13 = !{!"", !7, i64 0}
!14 = !{!"short", !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"

; 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

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

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

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 120
  %13 = call ptr @CopyMem(ptr noundef nonnull %5, ptr noundef %1, i64 noundef 4) #3
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = call i32 @SwapBytes32(i32 noundef %14) #3
  store i32 %15, ptr %5, align 4, !tbaa !5
  %16 = load i8, ptr %12, align 2, !tbaa !9
  %17 = icmp eq i8 %16, 0
  %18 = icmp ne i32 %15, 0
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %19, label %38

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %0, i64 125
  %21 = call ptr @CopyMem(ptr noundef nonnull %4, ptr noundef nonnull %20, i64 noundef 4) #3
  %22 = getelementptr inbounds i8, ptr %0, i64 121
  %23 = call ptr @CopyMem(ptr noundef nonnull %3, ptr noundef nonnull %22, i64 noundef 4) #3
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = call i32 @SwapBytes32(i32 noundef %24) #3
  store i32 %25, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = call i32 @SwapBytes32(i32 noundef %26) #3
  store i32 %27, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = call zeroext i8 @NetIp4IsUnicast(i32 noundef %28, i32 noundef %29) #3
  %.not7 = icmp eq i8 %30, 0
  br i1 %.not7, label %39, label %31

31:                                               ; preds = %19
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = xor i32 %34, %32
  %36 = and i32 %35, %33
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %31, %11
  br label %39

39:                                               ; preds = %19, %31, %2, %38
  %.0 = phi i8 [ 1, %38 ], [ 0, %2 ], [ 0, %31 ], [ 0, %19 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i8 %.0
}

declare zeroext i8 @NetIp4IsUnicast(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #1

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"", !7, i64 0, !11, i64 1, !11, i64 5, !12, i64 10, !11, i64 12, !11, i64 16, !12, i64 20, !12, i64 22, !12, i64 24}
!11 = !{!"", !7, i64 0}
!12 = !{!"short", !7, i64 0}


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