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

; 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.NIC_IP4_CONFIG_INFO = type { %struct.NIC_ADDR, i32, i8, %struct.EFI_IP4_IPCONFIG_DATA }
%struct.NIC_ADDR = type { i16, i8, %struct.EFI_MAC_ADDRESS }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.EFI_IP4_IPCONFIG_DATA = type { %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i32, ptr }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.EFI_IP4_ROUTE_TABLE = type { %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS }

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

16:                                               ; preds = %1
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_IP4_IPCONFIG_DATA, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [4 x i8], ptr %19, i64 0, i64 0
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = call i32 @SwapBytes32(i32 noundef %21)
  store i32 %22, ptr %5, align 4, !tbaa !16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_IP4_IPCONFIG_DATA, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [4 x i8], ptr %25, i64 0, i64 0
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = call i32 @SwapBytes32(i32 noundef %27)
  store i32 %28, ptr %6, align 4, !tbaa !16
  %29 = load i32, ptr %6, align 4, !tbaa !16
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %43, label %31

31:                                               ; preds = %16
  %32 = load i32, ptr %6, align 4, !tbaa !16
  %33 = call i64 @NetGetMaskLength(i32 noundef %32)
  %34 = icmp ne i64 %33, 33
  br i1 %34, label %35, label %43

35:                                               ; preds = %31
  %36 = load i32, ptr %5, align 4, !tbaa !16
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %43, label %38

38:                                               ; preds = %35
  %39 = load i32, ptr %5, align 4, !tbaa !16
  %40 = load i32, ptr %6, align 4, !tbaa !16
  %41 = call zeroext i8 @NetIp4IsUnicast(i32 noundef %39, i32 noundef %40)
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %38, %35, %31, %16
  store i8 0, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %91

44:                                               ; preds = %38
  store i32 0, ptr %8, align 4, !tbaa !16
  br label %45

45:                                               ; preds = %80, %44
  %46 = load i32, ptr %8, align 4, !tbaa !16
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.EFI_IP4_IPCONFIG_DATA, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 8, !tbaa !17
  %50 = icmp ult i32 %46, %49
  br i1 %50, label %51, label %83

51:                                               ; preds = %45
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_IP4_IPCONFIG_DATA, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  %55 = load i32, ptr %8, align 4, !tbaa !16
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds %struct.EFI_IP4_ROUTE_TABLE, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.EFI_IP4_ROUTE_TABLE, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds [4 x i8], ptr %59, i64 0, i64 0
  %61 = load i32, ptr %60, align 1, !tbaa !16
  %62 = call i32 @SwapBytes32(i32 noundef %61)
  store i32 %62, ptr %7, align 4, !tbaa !16
  %63 = load i32, ptr %7, align 4, !tbaa !16
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %79

65:                                               ; preds = %51
  %66 = load i32, ptr %5, align 4, !tbaa !16
  %67 = load i32, ptr %6, align 4, !tbaa !16
  %68 = and i32 %66, %67
  %69 = load i32, ptr %7, align 4, !tbaa !16
  %70 = load i32, ptr %6, align 4, !tbaa !16
  %71 = and i32 %69, %70
  %72 = icmp eq i32 %68, %71
  br i1 %72, label %73, label %78

73:                                               ; preds = %65
  %74 = load i32, ptr %7, align 4, !tbaa !16
  %75 = load i32, ptr %6, align 4, !tbaa !16
  %76 = call zeroext i8 @NetIp4IsUnicast(i32 noundef %74, i32 noundef %75)
  %77 = icmp ne i8 %76, 0
  br i1 %77, label %79, label %78

78:                                               ; preds = %73, %65
  store i8 0, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %91

79:                                               ; preds = %73, %51
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %8, align 4, !tbaa !16
  %82 = add i32 %81, 1
  store i32 %82, ptr %8, align 4, !tbaa !16
  br label %45, !llvm.loop !19

83:                                               ; preds = %45
  store i8 1, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %91

84:                                               ; preds = %1
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.NIC_IP4_CONFIG_INFO, ptr %85, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = icmp eq i32 %87, 0
  %89 = zext i1 %88 to i32
  %90 = trunc i32 %89 to i8
  store i8 %90, ptr %2, align 1
  store i32 1, ptr %9, align 4
  br label %91

91:                                               ; preds = %84, %83, %78, %43
  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 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %92 = load i8, ptr %2, align 1
  ret i8 %92
}

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

declare i32 @SwapBytes32(i32 noundef) #2

declare i64 @NetGetMaskLength(i32 noundef) #2

declare zeroext i8 @NetIp4IsUnicast(i32 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, !14, i64 36}
!10 = !{!"", !11, i64 0, !14, i64 36, !7, i64 40, !15, i64 48}
!11 = !{!"", !12, i64 0, !7, i64 2, !13, i64 3}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !13, i64 0, !13, i64 4, !14, i64 8, !6, i64 16}
!16 = !{!14, !14, i64 0}
!17 = !{!15, !14, i64 8}
!18 = !{!15, !6, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%struct.EFI_IP4_ROUTE_TABLE = type { %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @Ip4ConfigIsValid(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 36
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %5, label %37

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load i32, ptr %6, align 8, !tbaa !15
  %8 = tail call i32 @SwapBytes32(i32 noundef %7) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 52
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = tail call i32 @SwapBytes32(i32 noundef %10) #2
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %5
  %14 = tail call i64 @NetGetMaskLength(i32 noundef %11) #2
  %15 = icmp eq i64 %14, 33
  %16 = icmp eq i32 %8, 0
  %or.cond = select i1 %15, i1 true, i1 %16
  br i1 %or.cond, label %.loopexit, label %17

17:                                               ; preds = %13
  %18 = tail call zeroext i8 @NetIp4IsUnicast(i32 noundef %8, i32 noundef %11) #2
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %17
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load i32, ptr %19, align 8, !tbaa !16
  %.not35 = icmp eq i32 %20, 0
  br i1 %.not35, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  br label %22

22:                                               ; preds = %.lr.ph, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %33 ]
  %23 = load ptr, ptr %21, align 8, !tbaa !17
  %24 = getelementptr inbounds %struct.EFI_IP4_ROUTE_TABLE, ptr %23, i64 %indvars.iv, i32 2
  %25 = load i32, ptr %24, align 1, !tbaa !15
  %26 = tail call i32 @SwapBytes32(i32 noundef %25) #2
  %.not28 = icmp eq i32 %26, 0
  br i1 %.not28, label %33, label %27

27:                                               ; preds = %22
  %28 = xor i32 %26, %8
  %29 = and i32 %28, %11
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %.loopexit

31:                                               ; preds = %27
  %32 = tail call zeroext i8 @NetIp4IsUnicast(i32 noundef %26, i32 noundef %11) #2
  %.not29 = icmp eq i8 %32, 0
  br i1 %.not29, label %.loopexit, label %33

33:                                               ; preds = %22, %31
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = load i32, ptr %19, align 8, !tbaa !16
  %35 = zext i32 %34 to i64
  %36 = icmp ult i64 %indvars.iv.next, %35
  br i1 %36, label %22, label %.loopexit, !llvm.loop !18

37:                                               ; preds = %1
  %38 = icmp eq i32 %3, 0
  %39 = zext i1 %38 to i8
  br label %.loopexit

.loopexit:                                        ; preds = %31, %27, %33, %.preheader, %5, %13, %17, %37
  %.023 = phi i8 [ %39, %37 ], [ 0, %17 ], [ 0, %13 ], [ 0, %5 ], [ 1, %.preheader ], [ 0, %31 ], [ 0, %27 ], [ 1, %33 ]
  ret i8 %.023
}

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #1

declare i64 @NetGetMaskLength(i32 noundef) local_unnamed_addr #1

declare zeroext i8 @NetIp4IsUnicast(i32 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, !12, i64 36}
!6 = !{!"", !7, i64 0, !12, i64 36, !9, i64 40, !13, i64 48}
!7 = !{!"", !8, i64 0, !9, i64 2, !11, i64 3}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8, !14, i64 16}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!13, !12, i64 8}
!17 = !{!13, !14, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass