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

; 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_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 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

; 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 i64 @DhcpCallUser(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare void @FreePool(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpChooseOffer(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @DhcpHandleSelect(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = 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
  store i64 0, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %30, label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %13, i32 0, i32 2
  %15 = load i8, ptr %14, align 4, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %30, label %18

18:                                               ; preds = %12
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %19, i32 0, i32 2
  %21 = load i8, ptr %20, align 4, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 2
  br i1 %23, label %29, label %24

24:                                               ; preds = %18
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %25, i32 0, i32 4
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %24, %18
  br label %74

30:                                               ; preds = %24, %12, %3
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i64 @DhcpCallUser(ptr noundef %31, i32 noundef 2, ptr noundef %32, ptr noundef null)
  store i64 %33, ptr %8, align 8, !tbaa !9
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = icmp eq i64 %34, 0
  br i1 %35, label %36, label %51

36:                                               ; preds = %30
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %37, i32 0, i32 13
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %45

41:                                               ; preds = %36
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %42, i32 0, i32 13
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  call void @FreePool(ptr noundef %44)
  br label %45

45:                                               ; preds = %41, %36
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %47, i32 0, i32 13
  store ptr %46, ptr %48, align 8, !tbaa !15
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call i64 @DhcpChooseOffer(ptr noundef %49)
  store i64 %50, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

51:                                               ; preds = %30
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = icmp eq i64 %52, -9223372036854775802
  br i1 %53, label %54, label %67

54:                                               ; preds = %51
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %55, i32 0, i32 13
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %63

59:                                               ; preds = %54
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %60, i32 0, i32 13
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  call void @FreePool(ptr noundef %62)
  br label %63

63:                                               ; preds = %59, %54
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %65, i32 0, i32 13
  store ptr %64, ptr %66, align 8, !tbaa !15
  br label %72

67:                                               ; preds = %51
  %68 = load i64, ptr %8, align 8, !tbaa !9
  %69 = icmp eq i64 %68, -9223372036854775787
  br i1 %69, label %70, label %71

70:                                               ; preds = %67
  br label %74

71:                                               ; preds = %67
  br label %72

72:                                               ; preds = %71, %63
  br label %73

73:                                               ; preds = %72
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

74:                                               ; preds = %70, %29
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %75)
  %76 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %76, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %77

77:                                               ; preds = %74, %73, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %78 = load i64, ptr %4, align 8
  ret i64 %78
}

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


; 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 @DhcpCallUser(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @FreePool(ptr noundef) local_unnamed_addr #1

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

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

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i8, ptr %6, align 4, !tbaa !5
  switch i8 %7, label %25 [
    i8 0, label %12
    i8 2, label %8
  ]

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %2, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %25, label %12

12:                                               ; preds = %5, %8, %3
  %13 = tail call i64 @DhcpCallUser(ptr noundef %0, i32 noundef 2, ptr noundef %1, ptr noundef null)
  switch i64 %13, label %26 [
    i64 0, label %14
    i64 -9223372036854775802, label %20
    i64 -9223372036854775787, label %25
  ]

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 104
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %.not27 = icmp eq ptr %16, null
  br i1 %.not27, label %18, label %17

17:                                               ; preds = %14
  tail call void @FreePool(ptr noundef nonnull %16) #2
  br label %18

18:                                               ; preds = %17, %14
  store ptr %1, ptr %15, align 8, !tbaa !11
  %19 = tail call i64 @DhcpChooseOffer(ptr noundef nonnull %0)
  br label %26

20:                                               ; preds = %12
  %21 = getelementptr inbounds i8, ptr %0, i64 104
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %.not26 = icmp eq ptr %22, null
  br i1 %.not26, label %24, label %23

23:                                               ; preds = %20
  tail call void @FreePool(ptr noundef nonnull %22) #2
  br label %24

24:                                               ; preds = %23, %20
  store ptr %1, ptr %21, align 8, !tbaa !11
  br label %26

25:                                               ; preds = %12, %5, %8
  %.0 = phi i64 [ 0, %8 ], [ 0, %5 ], [ %13, %12 ]
  tail call void @FreePool(ptr noundef %1) #2
  br label %26

26:                                               ; preds = %24, %12, %25, %18
  %.020 = phi i64 [ %19, %18 ], [ %.0, %25 ], [ 0, %12 ], [ 0, %24 ]
  ret i64 %.020
}

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


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