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

; 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.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._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @PxeBcConfigureUdpWriteInstance(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.EFI_UDP4_CONFIG_DATA, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 36, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %13 = call ptr @ZeroMem(ptr noundef %11, i64 noundef 36)
  %14 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 7
  store i32 50000, ptr %14, align 4, !tbaa !9
  %15 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 4
  store i8 0, ptr %15, align 4, !tbaa !14
  %16 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 5
  store i8 16, ptr %16, align 1, !tbaa !15
  %17 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 3
  store i8 1, ptr %17, align 1, !tbaa !16
  %18 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 10
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call ptr @CopyMem(ptr noundef %18, ptr noundef %19, i64 noundef 4)
  %21 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 11
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call ptr @CopyMem(ptr noundef %21, ptr noundef %22, i64 noundef 4)
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = load i16, ptr %24, align 2, !tbaa !17
  %26 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 12
  store i16 %25, ptr %26, align 2, !tbaa !18
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i64 %29(ptr noundef %30, ptr noundef null)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call i64 %34(ptr noundef %35, ptr noundef %11)
  store i64 %36, ptr %12, align 8, !tbaa !21
  %37 = load i64, ptr %12, align 8, !tbaa !21
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %62, label %39

39:                                               ; preds = %5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [4 x i8], ptr %41, i64 0, i64 0
  %43 = load i8, ptr %42, align 1, !tbaa !23
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %62

46:                                               ; preds = %39
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !24
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = call i64 %49(ptr noundef %50, i8 noundef zeroext 0, ptr noundef @mZeroIp4Addr, ptr noundef @mZeroIp4Addr, ptr noundef %51)
  store i64 %52, ptr %12, align 8, !tbaa !21
  %53 = load i64, ptr %12, align 8, !tbaa !21
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %61

55:                                               ; preds = %46
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = call i64 %58(ptr noundef %59, ptr noundef null)
  br label %61

61:                                               ; preds = %55, %46
  br label %62

62:                                               ; preds = %61, %39, %5
  %63 = load i64, ptr %12, align 8, !tbaa !21
  %64 = icmp slt i64 %63, 0
  br i1 %64, label %79, label %65

65:                                               ; preds = %62
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i16, ptr %66, align 2, !tbaa !17
  %68 = zext i16 %67 to i32
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %79

70:                                               ; preds = %65
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._EFI_UDP4_PROTOCOL, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !25
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = call i64 %73(ptr noundef %74, ptr noundef %11, ptr noundef null, ptr noundef null, ptr noundef null)
  %76 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %11, i32 0, i32 12
  %77 = load i16, ptr %76, align 2, !tbaa !18
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  store i16 %77, ptr %78, align 2, !tbaa !17
  br label %79

79:                                               ; preds = %70, %65, %62
  %80 = load i64, ptr %12, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 36, ptr %11) #3
  ret i64 %80
}

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

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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, !11, i64 8}
!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 4}
!15 = !{!10, !7, i64 5}
!16 = !{!10, !7, i64 3}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !13, i64 26}
!19 = !{!20, !6, i64 8}
!20 = !{!"_EFI_UDP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!21 = !{!22, !22, i64 0}
!22 = !{!"long long", !7, i64 0}
!23 = !{!7, !7, i64 0}
!24 = !{!20, !6, i64 24}
!25 = !{!20, !6, 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] }
%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 }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @PxeBcConfigureUdpWriteInstance(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = alloca %struct.EFI_UDP4_CONFIG_DATA, align 4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %6) #3
  %7 = call ptr @ZeroMem(ptr noundef nonnull %6, i64 noundef 36) #3
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 50000, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 4
  store i8 0, ptr %9, align 4, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %6, i64 5
  store i8 16, ptr %10, align 1, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %6, i64 3
  store i8 1, ptr %11, align 1, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %6, i64 17
  %13 = call ptr @CopyMem(ptr noundef nonnull %12, ptr noundef %1, i64 noundef 4) #3
  %14 = getelementptr inbounds i8, ptr %6, i64 21
  %15 = call ptr @CopyMem(ptr noundef nonnull %14, ptr noundef %2, i64 noundef 4) #3
  %16 = load i16, ptr %4, align 2, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %6, i64 26
  store i16 %16, ptr %17, align 2, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = call i64 %19(ptr noundef %0, ptr noundef null) #3
  %21 = load ptr, ptr %18, align 8, !tbaa !17
  %22 = call i64 %21(ptr noundef %0, ptr noundef nonnull %6) #3
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %.thread, label %24

24:                                               ; preds = %5
  %25 = load i8, ptr %3, align 1, !tbaa !20
  %.not = icmp eq i8 %25, 0
  br i1 %.not, label %34, label %26

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = call i64 %28(ptr noundef nonnull %0, i8 noundef zeroext 0, ptr noundef nonnull @mZeroIp4Addr, ptr noundef nonnull @mZeroIp4Addr, ptr noundef nonnull %3) #3
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %26
  %32 = load ptr, ptr %18, align 8, !tbaa !17
  %33 = call i64 %32(ptr noundef nonnull %0, ptr noundef null) #3
  br label %.thread

34:                                               ; preds = %24, %26
  %.0 = phi i64 [ %29, %26 ], [ %22, %24 ]
  %35 = load i16, ptr %4, align 2, !tbaa !15
  %36 = icmp eq i16 %35, 0
  br i1 %36, label %37, label %.thread

37:                                               ; preds = %34
  %38 = load ptr, ptr %0, align 8, !tbaa !22
  %39 = call i64 %38(ptr noundef nonnull %0, ptr noundef nonnull %6, ptr noundef null, ptr noundef null, ptr noundef null) #3
  %40 = load i16, ptr %17, align 2, !tbaa !16
  store i16 %40, ptr %4, align 2, !tbaa !15
  br label %.thread

.thread:                                          ; preds = %31, %5, %37, %34
  %.024 = phi i64 [ %.0, %37 ], [ %.0, %34 ], [ %29, %31 ], [ %22, %5 ]
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %6) #3
  ret i64 %.024
}

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

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

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

; Function Attrs: mustprogress 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 = { mustprogress 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, !9, i64 8}
!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 4}
!13 = !{!6, !7, i64 5}
!14 = !{!6, !7, i64 3}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !11, i64 26}
!17 = !{!18, !19, i64 8}
!18 = !{!"_EFI_UDP4_PROTOCOL", !19, i64 0, !19, i64 8, !19, i64 16, !19, i64 24, !19, i64 32, !19, i64 40, !19, i64 48, !19, i64 56}
!19 = !{!"any pointer", !7, i64 0}
!20 = !{!7, !7, i64 0}
!21 = !{!18, !19, i64 24}
!22 = !{!18, !19, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass