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

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

@mUdp4RandomPort = external dso_local global i16, align 2

; 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
declare dso_local zeroext i8 @Udp4FindInstanceByPort(ptr noundef, ptr noundef, i16 noundef zeroext) #1

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

13:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %83

14:                                               ; preds = %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %15, i32 0, i32 10
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %17, i32 0, i32 12
  %19 = load i16, ptr %18, align 2, !tbaa !14
  %20 = zext i16 %19 to i32
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %38

22:                                               ; preds = %14
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %23, i32 0, i32 3
  %25 = load i8, ptr %24, align 1, !tbaa !15
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %37, label %27

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %30, i32 0, i32 12
  %32 = load i16, ptr %31, align 2, !tbaa !14
  %33 = call zeroext i8 @Udp4FindInstanceByPort(ptr noundef %28, ptr noundef %29, i16 noundef zeroext %32)
  %34 = zext i8 %33 to i32
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %27
  store i64 -9223372036854775793, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %83

37:                                               ; preds = %27, %22
  br label %82

38:                                               ; preds = %14
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %39, i32 0, i32 3
  %41 = load i8, ptr %40, align 1, !tbaa !15
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %38
  %44 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %45, i32 0, i32 12
  store i16 %44, ptr %46, align 2, !tbaa !14
  br label %74

47:                                               ; preds = %38
  %48 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  store i16 %48, ptr %7, align 2, !tbaa !16
  br label %49

49:                                               ; preds = %69, %47
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %53 = call zeroext i8 @Udp4FindInstanceByPort(ptr noundef %50, ptr noundef %51, i16 noundef zeroext %52)
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %70

55:                                               ; preds = %49
  %56 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %57 = add i16 %56, 1
  store i16 %57, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %58 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %59 = zext i16 %58 to i32
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %55
  store i16 1024, ptr @mUdp4RandomPort, align 2, !tbaa !16
  br label %62

62:                                               ; preds = %61, %55
  %63 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %64 = zext i16 %63 to i32
  %65 = load i16, ptr %7, align 2, !tbaa !16
  %66 = zext i16 %65 to i32
  %67 = icmp eq i32 %64, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %62
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %83

69:                                               ; preds = %62
  br label %49, !llvm.loop !17

70:                                               ; preds = %49
  %71 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.EFI_UDP4_CONFIG_DATA, ptr %72, i32 0, i32 12
  store i16 %71, ptr %73, align 2, !tbaa !14
  br label %74

74:                                               ; preds = %70, %43
  %75 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %76 = add i16 %75, 1
  store i16 %76, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %77 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !16
  %78 = zext i16 %77 to i32
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %74
  store i16 1024, ptr @mUdp4RandomPort, align 2, !tbaa !16
  br label %81

81:                                               ; preds = %80, %74
  br label %82

82:                                               ; preds = %81, %37
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %83

83:                                               ; preds = %82, %68, %36, %13
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %84 = load i64, ptr %3, align 8
  ret i64 %84
}

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 = { 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 2}
!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, !13, i64 26}
!15 = !{!10, !7, i64 3}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@mUdp4RandomPort = external dso_local local_unnamed_addr global i16, align 2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Udp4FindInstanceByPort(ptr noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @Udp4Bind(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 2
  %4 = load i8, ptr %3, align 2, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %.loopexit19

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 17
  %7 = getelementptr inbounds i8, ptr %1, i64 26
  %8 = load i16, ptr %7, align 2, !tbaa !12
  %.not14 = icmp eq i16 %8, 0
  %9 = getelementptr inbounds i8, ptr %1, i64 3
  %10 = load i8, ptr %9, align 1, !tbaa !13
  %.not15 = icmp eq i8 %10, 0
  br i1 %.not14, label %14, label %11

11:                                               ; preds = %5
  br i1 %.not15, label %12, label %27

12:                                               ; preds = %11
  %13 = tail call zeroext i8 @Udp4FindInstanceByPort(ptr noundef %0, ptr noundef nonnull %6, i16 noundef zeroext %8)
  %.not18 = icmp eq i8 %13, 0
  br i1 %.not18, label %27, label %.loopexit19

14:                                               ; preds = %5
  br i1 %.not15, label %15, label %.loopexit

15:                                               ; preds = %14
  %16 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !14
  br label %17

17:                                               ; preds = %20, %15
  %18 = phi i16 [ %spec.store.select, %20 ], [ %16, %15 ]
  %19 = tail call zeroext i8 @Udp4FindInstanceByPort(ptr noundef %0, ptr noundef nonnull %6, i16 noundef zeroext %18)
  %.not16 = icmp eq i8 %19, 0
  br i1 %.not16, label %.loopexit, label %20

20:                                               ; preds = %17
  %21 = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !14
  %22 = add i16 %21, 1
  %23 = icmp eq i16 %22, 0
  %spec.store.select = select i1 %23, i16 1024, i16 %22
  store i16 %spec.store.select, ptr @mUdp4RandomPort, align 2
  %24 = icmp eq i16 %spec.store.select, %16
  br i1 %24, label %.loopexit19, label %17, !llvm.loop !15

.loopexit:                                        ; preds = %17, %14
  %storemerge = load i16, ptr @mUdp4RandomPort, align 2, !tbaa !14
  store i16 %storemerge, ptr %7, align 2, !tbaa !12
  %25 = add i16 %storemerge, 1
  %26 = icmp eq i16 %25, 0
  %spec.store.select1 = select i1 %26, i16 1024, i16 %25
  store i16 %spec.store.select1, ptr @mUdp4RandomPort, align 2
  br label %27

27:                                               ; preds = %11, %12, %.loopexit
  br label %.loopexit19

.loopexit19:                                      ; preds = %20, %12, %2, %27
  %.0 = phi i64 [ 0, %27 ], [ 0, %2 ], [ -9223372036854775793, %12 ], [ -9223372036854775799, %20 ]
  ret i64 %.0
}

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" }

!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 2}
!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, !11, i64 26}
!13 = !{!6, !7, i64 3}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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