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

; 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_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] }
%struct.DHCP_PARAMETER = type { i32, i32, i8, i8, i32, i32, i32, i32 }
%struct._DHCP_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i64, ptr, ptr, %struct._LIST_ENTRY, i64, i64, i64, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, i64, ptr, ptr, ptr, %struct.EFI_MAC_ADDRESS, i8, i8, [16 x i8], ptr, %struct.EFI_DHCP4_CONFIG_DATA, i32, ptr, i32, i32, i64, i64, i32 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.EFI_DHCP4_CONFIG_DATA = type { i32, ptr, i32, ptr, %struct.EFI_IPv4_ADDRESS, ptr, ptr, i32, ptr }

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpInitRequest(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpCallUser(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @DhcpNotifyUser(ptr noundef, i64 noundef) #0

declare i32 @SwapBytes32(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpLeaseAcquired(ptr noundef) #0

declare void @FreePool(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @DhcpHandleReboot(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %11, i32 0, i32 2
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  store ptr %13, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %34, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %17, i32 0, i32 2
  %19 = load i8, ptr %18, align 4, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %34, label %22

22:                                               ; preds = %16
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %23, i32 0, i32 2
  %25 = load i8, ptr %24, align 4, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 5
  br i1 %27, label %28, label %35

28:                                               ; preds = %22
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %29, i32 0, i32 2
  %31 = load i8, ptr %30, align 4, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 6
  br i1 %33, label %34, label %35

34:                                               ; preds = %28, %16, %3
  store i64 0, ptr %9, align 8, !tbaa !12
  br label %94

35:                                               ; preds = %28, %22
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %36, i32 0, i32 2
  %38 = load i8, ptr %37, align 4, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = icmp eq i32 %39, 6
  br i1 %40, label %41, label %51

41:                                               ; preds = %35
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call i64 @DhcpCallUser(ptr noundef %42, i32 noundef 6, ptr noundef %43, ptr noundef null)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %45, i32 0, i32 10
  store i32 0, ptr %46, align 4, !tbaa !14
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %47, i32 0, i32 7
  store i64 1, ptr %48, align 8, !tbaa !20
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call i64 @DhcpInitRequest(ptr noundef %49)
  store i64 %50, ptr %9, align 8, !tbaa !12
  br label %94

51:                                               ; preds = %35
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_DHCP4_HEADER, ptr %52, i32 0, i32 8
  %54 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [4 x i8], ptr %54, i64 0, i64 0
  %56 = load i32, ptr %55, align 1, !tbaa !21
  %57 = call i32 @SwapBytes32(i32 noundef %56)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %58, i32 0, i32 10
  %60 = load i32, ptr %59, align 4, !tbaa !14
  %61 = icmp ne i32 %57, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %51
  store i64 -9223372036854775801, ptr %9, align 8, !tbaa !12
  br label %94

63:                                               ; preds = %51
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call i64 @DhcpCallUser(ptr noundef %64, i32 noundef 5, ptr noundef %65, ptr noundef null)
  store i64 %66, ptr %9, align 8, !tbaa !12
  %67 = load i64, ptr %9, align 8, !tbaa !12
  %68 = icmp slt i64 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %63
  br label %94

70:                                               ; preds = %63
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = call ptr @AllocateCopyPool(i64 noundef 28, ptr noundef %71)
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %73, i32 0, i32 15
  store ptr %72, ptr %74, align 8, !tbaa !22
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %75, i32 0, i32 15
  %77 = load ptr, ptr %76, align 8, !tbaa !22
  %78 = icmp eq ptr %77, null
  br i1 %78, label %79, label %80

79:                                               ; preds = %70
  store i64 -9223372036854775799, ptr %9, align 8, !tbaa !12
  br label %94

80:                                               ; preds = %70
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %82, i32 0, i32 14
  store ptr %81, ptr %83, align 8, !tbaa !23
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = call i64 @DhcpLeaseAcquired(ptr noundef %84)
  store i64 %85, ptr %9, align 8, !tbaa !12
  %86 = load i64, ptr %9, align 8, !tbaa !12
  %87 = icmp slt i64 %86, 0
  br i1 %87, label %88, label %90

88:                                               ; preds = %80
  %89 = load i64, ptr %9, align 8, !tbaa !12
  store i64 %89, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %97

90:                                               ; preds = %80
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %91, i32 0, i32 8
  store i64 0, ptr %92, align 8, !tbaa !24
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  call void @DhcpNotifyUser(ptr noundef %93, i64 noundef 1)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %97

94:                                               ; preds = %79, %69, %62, %41, %34
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %95)
  %96 = load i64, ptr %9, align 8, !tbaa !12
  store i64 %96, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %97

97:                                               ; preds = %94, %90, %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %98 = load i64, ptr %4, align 8
  ret i64 %98
}

declare ptr @AllocateCopyPool(i64 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, !7, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 9, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !11, i64 92}
!15 = !{!"_DHCP_SERVICE", !11, i64 0, !16, i64 8, !13, i64 24, !6, i64 32, !6, i64 40, !17, i64 48, !13, i64 64, !13, i64 72, !13, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !11, i64 128, !11, i64 132, !11, i64 136, !13, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !18, i64 176, !7, i64 208, !7, i64 209, !7, i64 210, !6, i64 232, !19, i64 240, !11, i64 312, !6, i64 320, !11, i64 328, !11, i64 332, !13, i64 336, !13, i64 344, !11, i64 352}
!16 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!17 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!18 = !{!"", !7, i64 0}
!19 = !{!"", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !18, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !6, i64 64}
!20 = !{!15, !13, i64 72}
!21 = !{!11, !11, i64 0}
!22 = !{!15, !6, i64 120}
!23 = !{!15, !6, i64 112}
!24 = !{!15, !13, i64 80}


; 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: nounwind uwtable
declare dso_local i64 @DhcpInitRequest(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpCallUser(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @DhcpNotifyUser(ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @SwapBytes32(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpLeaseAcquired(ptr noundef) local_unnamed_addr #0

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @DhcpHandleReboot(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %2, null
  br i1 %4, label %34, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i8, ptr %6, align 4, !tbaa !5
  %.off = add i8 %7, -5
  %switch = icmp ult i8 %.off, 2
  br i1 %switch, label %8, label %34

8:                                                ; preds = %5
  %9 = icmp eq i8 %7, 6
  br i1 %9, label %10, label %15

10:                                               ; preds = %8
  %11 = tail call i64 @DhcpCallUser(ptr noundef %0, i32 noundef 6, ptr noundef %1, ptr noundef null)
  %12 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 0, ptr %12, align 4, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %0, i64 72
  store i64 1, ptr %13, align 8, !tbaa !18
  %14 = tail call i64 @DhcpInitRequest(ptr noundef %0)
  br label %34

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  %17 = load i32, ptr %16, align 1, !tbaa !19
  %18 = tail call i32 @SwapBytes32(i32 noundef %17) #2
  %19 = getelementptr inbounds i8, ptr %0, i64 92
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %.not34 = icmp eq i32 %18, %20
  br i1 %.not34, label %21, label %34

21:                                               ; preds = %15
  %22 = tail call i64 @DhcpCallUser(ptr noundef nonnull %0, i32 noundef 5, ptr noundef nonnull %1, ptr noundef null)
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %34, label %24

24:                                               ; preds = %21
  %25 = tail call ptr @AllocateCopyPool(i64 noundef 28, ptr noundef nonnull %2) #2
  %26 = getelementptr inbounds i8, ptr %0, i64 120
  store ptr %25, ptr %26, align 8, !tbaa !20
  %27 = icmp eq ptr %25, null
  br i1 %27, label %34, label %28

28:                                               ; preds = %24
  %29 = getelementptr inbounds i8, ptr %0, i64 112
  store ptr %1, ptr %29, align 8, !tbaa !21
  %30 = tail call i64 @DhcpLeaseAcquired(ptr noundef nonnull %0)
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %35, label %32

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 0, ptr %33, align 8, !tbaa !22
  tail call void @DhcpNotifyUser(ptr noundef nonnull %0, i64 noundef 1)
  br label %35

34:                                               ; preds = %5, %24, %15, %3, %21, %10
  %.0 = phi i64 [ %14, %10 ], [ %22, %21 ], [ 0, %5 ], [ 0, %3 ], [ -9223372036854775801, %15 ], [ -9223372036854775799, %24 ]
  tail call void @FreePool(ptr noundef %1) #2
  br label %35

35:                                               ; preds = %28, %34, %32
  %.028 = phi i64 [ %.0, %34 ], [ 0, %32 ], [ %30, %28 ]
  ret i64 %.028
}

declare ptr @AllocateCopyPool(i64 noundef, ptr 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, !8, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !8, i64 9, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 92}
!11 = !{!"_DHCP_SERVICE", !7, i64 0, !12, i64 8, !14, i64 24, !13, i64 32, !13, i64 40, !15, i64 48, !14, i64 64, !14, i64 72, !14, i64 80, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !13, i64 104, !13, i64 112, !13, i64 120, !7, i64 128, !7, i64 132, !7, i64 136, !14, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !16, i64 176, !8, i64 208, !8, i64 209, !8, i64 210, !13, i64 232, !17, i64 240, !7, i64 312, !13, i64 320, !7, i64 328, !7, i64 332, !14, i64 336, !14, i64 344, !7, i64 352}
!12 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !13, i64 0, !13, i64 8}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"_LIST_ENTRY", !13, i64 0, !13, i64 8}
!16 = !{!"", !8, i64 0}
!17 = !{!"", !7, i64 0, !13, i64 8, !7, i64 16, !13, i64 24, !16, i64 32, !13, i64 40, !13, i64 48, !7, i64 56, !13, i64 64}
!18 = !{!11, !14, i64 72}
!19 = !{!7, !7, i64 0}
!20 = !{!11, !13, i64 120}
!21 = !{!11, !13, i64 112}
!22 = !{!11, !14, i64 80}


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