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

; 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.DHCP_PARSE_CONTEXT = type { ptr, i32, i32 }
%struct.EFI_DHCP4_PACKET = type <{ i32, i32, %struct.anon }>
%struct.anon = type <{ %struct.EFI_DHCP4_HEADER, i32, [1 x i8] }>
%struct.EFI_DHCP4_HEADER = type { i8, i8, i8, i8, i32, i16, i16, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, [16 x i8], [64 x i8], [128 x i8] }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

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

15:                                               ; preds = %4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18, %15, %4
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 1, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 1, !tbaa !16
  %30 = zext i32 %29 to i64
  %31 = add i64 %30, 8
  %32 = icmp ult i64 %26, %31
  br i1 %32, label %43, label %33

33:                                               ; preds = %22
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %34, i32 0, i32 2
  %36 = getelementptr inbounds %struct.anon, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 1, !tbaa !17
  %38 = icmp ne i32 %37, 1666417251
  br i1 %38, label %43, label %39

39:                                               ; preds = %33
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = call i64 @DhcpValidateOptions(ptr noundef %40, ptr noundef null)
  %42 = icmp slt i64 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %39, %33, %22
  store i64 -9223372036854775806, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

44:                                               ; preds = %39
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i32, ptr %45, align 4, !tbaa !18
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %52

48:                                               ; preds = %44
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i64 -9223372036854775803, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

52:                                               ; preds = %48, %44
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !18
  %56 = zext i32 %55 to i64
  %57 = mul i64 %56, 8
  %58 = call ptr @ZeroMem(ptr noundef %53, i64 noundef %57)
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.DHCP_PARSE_CONTEXT, ptr %10, i32 0, i32 0
  store ptr %59, ptr %60, align 8, !tbaa !19
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i32, ptr %61, align 4, !tbaa !18
  %63 = getelementptr inbounds %struct.DHCP_PARSE_CONTEXT, ptr %10, i32 0, i32 1
  store i32 %62, ptr %63, align 8, !tbaa !21
  %64 = getelementptr inbounds %struct.DHCP_PARSE_CONTEXT, ptr %10, i32 0, i32 2
  store i32 0, ptr %64, align 4, !tbaa !22
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i64 @DhcpIterateOptions(ptr noundef %65, ptr noundef @Dhcp4ParseCheckOption, ptr noundef %10)
  store i64 %66, ptr %11, align 8, !tbaa !23
  %67 = load i64, ptr %11, align 8, !tbaa !23
  %68 = icmp slt i64 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %52
  %70 = load i64, ptr %11, align 8, !tbaa !23
  store i64 %70, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

71:                                               ; preds = %52
  %72 = getelementptr inbounds %struct.DHCP_PARSE_CONTEXT, ptr %10, i32 0, i32 2
  %73 = load i32, ptr %72, align 4, !tbaa !22
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %73, ptr %74, align 4, !tbaa !18
  %75 = getelementptr inbounds %struct.DHCP_PARSE_CONTEXT, ptr %10, i32 0, i32 2
  %76 = load i32, ptr %75, align 4, !tbaa !22
  %77 = getelementptr inbounds %struct.DHCP_PARSE_CONTEXT, ptr %10, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !21
  %79 = icmp ugt i32 %76, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %71
  store i64 -9223372036854775803, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

81:                                               ; preds = %71
  store i64 0, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

82:                                               ; preds = %81, %80, %69, %51, %43, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  %83 = load i64, ptr %5, align 8
  ret i64 %83
}

; 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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @Dhcp4ParseCheckOption(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef) #0

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

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 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0, !11, i64 236, !7, i64 240}
!13 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 4, !14, i64 8, !14, i64 10, !15, i64 12, !15, i64 16, !15, i64 20, !15, i64 24, !7, i64 28, !7, i64 44, !7, i64 108}
!14 = !{!"short", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = !{!10, !11, i64 4}
!17 = !{!10, !11, i64 244}
!18 = !{!11, !11, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!21 = !{!20, !11, i64 8}
!22 = !{!20, !11, i64 12}
!23 = !{!24, !24, i64 0}
!24 = !{!"long long", !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.DHCP_PARSE_CONTEXT = type { ptr, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @EfiDhcp4Parse(ptr noundef readnone %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.DHCP_PARSE_CONTEXT, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  %8 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %8
  br i1 %or.cond3, label %40, label %9

9:                                                ; preds = %4
  %10 = load i32, ptr %1, align 1, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = load i32, ptr %12, align 1, !tbaa !14
  %14 = zext i32 %13 to i64
  %15 = add nuw nsw i64 %14, 8
  %16 = icmp ugt i64 %15, %11
  br i1 %16, label %40, label %17

17:                                               ; preds = %9
  %18 = getelementptr inbounds i8, ptr %1, i64 244
  %19 = load i32, ptr %18, align 1, !tbaa !15
  %.not = icmp eq i32 %19, 1666417251
  br i1 %.not, label %20, label %40

20:                                               ; preds = %17
  %21 = tail call i64 @DhcpValidateOptions(ptr noundef nonnull %1, ptr noundef null) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %40, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr %2, align 4, !tbaa !16
  %25 = icmp ne i32 %24, 0
  %26 = icmp eq ptr %3, null
  %or.cond5 = and i1 %26, %25
  br i1 %or.cond5, label %40, label %27

27:                                               ; preds = %23
  %28 = zext i32 %24 to i64
  %29 = shl nuw nsw i64 %28, 3
  %30 = tail call ptr @ZeroMem(ptr noundef %3, i64 noundef %29) #3
  store ptr %3, ptr %5, align 8, !tbaa !17
  %31 = load i32, ptr %2, align 4, !tbaa !16
  %32 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %31, ptr %32, align 8, !tbaa !20
  %33 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 0, ptr %33, align 4, !tbaa !21
  %34 = call i64 @DhcpIterateOptions(ptr noundef nonnull %1, ptr noundef nonnull @Dhcp4ParseCheckOption, ptr noundef nonnull %5) #3
  %35 = icmp slt i64 %34, 0
  br i1 %35, label %40, label %36

36:                                               ; preds = %27
  %37 = load i32, ptr %33, align 4, !tbaa !21
  store i32 %37, ptr %2, align 4, !tbaa !16
  %38 = load i32, ptr %32, align 8, !tbaa !20
  %39 = icmp ugt i32 %37, %38
  %. = select i1 %39, i64 -9223372036854775803, i64 0
  br label %40

40:                                               ; preds = %36, %27, %23, %9, %17, %20, %4
  %.0 = phi i64 [ -9223372036854775806, %4 ], [ -9223372036854775806, %20 ], [ -9223372036854775806, %17 ], [ -9223372036854775806, %9 ], [ -9223372036854775803, %23 ], [ %34, %27 ], [ %., %36 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  ret i64 %.0
}

; 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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @Dhcp4ParseCheckOption(i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef) #0

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

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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !7, i64 236, !8, i64 240}
!11 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !7, i64 4, !12, i64 8, !12, i64 10, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !8, i64 28, !8, i64 44, !8, i64 108}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !8, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 244}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !19, i64 0}
!18 = !{!"", !19, i64 0, !7, i64 8, !7, i64 12}
!19 = !{!"any pointer", !8, i64 0}
!20 = !{!18, !7, i64 8}
!21 = !{!18, !7, i64 12}


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