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

; 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_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] }
%struct._DHCP_PROTOCOL = type { i32, %struct._EFI_DHCP4_PROTOCOL, %struct._LIST_ENTRY, ptr, ptr, i8, ptr, ptr, ptr, ptr, i32, i16, %struct.NET_BUF_QUEUE }
%struct._EFI_DHCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }

; 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
define dso_local i64 @DhcpCallUser(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  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 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %16, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %15, %4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %18, i32 0, i32 28
  store ptr %19, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.EFI_DHCP4_CONFIG_DATA, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %29

24:                                               ; preds = %17
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i64 -9223372036854775802, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %56

28:                                               ; preds = %24
  store i64 0, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %56

29:                                               ; preds = %17
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_DHCP4_CONFIG_DATA, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %33, i32 0, i32 27
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct._DHCP_PROTOCOL, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_DHCP4_CONFIG_DATA, ptr %37, i32 0, i32 6
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %40, i32 0, i32 7
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %43 = trunc i64 %42 to i32
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call i64 %32(ptr noundef %36, ptr noundef %39, i32 noundef %43, i32 noundef %44, ptr noundef %45, ptr noundef %46)
  store i64 %47, ptr %11, align 8, !tbaa !21
  %48 = load i64, ptr %11, align 8, !tbaa !21
  %49 = icmp eq i64 %48, 0
  br i1 %49, label %53, label %50

50:                                               ; preds = %29
  %51 = load i64, ptr %11, align 8, !tbaa !21
  %52 = icmp eq i64 %51, -9223372036854775802
  br i1 %52, label %53, label %55

53:                                               ; preds = %50, %29
  %54 = load i64, ptr %11, align 8, !tbaa !21
  store i64 %54, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %56

55:                                               ; preds = %50
  store i64 -9223372036854775787, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %56

56:                                               ; preds = %55, %53, %28, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %57 = load i64, ptr %5, align 8
  ret i64 %57
}

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

; Function Attrs: nounwind uwtable
define dso_local i64 @DhcpCallUser(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %4
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %4
  %7 = getelementptr inbounds i8, ptr %0, i64 280
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  %11 = icmp eq i32 %1, 2
  %. = select i1 %11, i64 -9223372036854775802, i64 0
  br label %22

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 232
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = getelementptr inbounds i8, ptr %0, i64 288
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %0, i64 72
  %19 = load i64, ptr %18, align 8, !tbaa !19
  %20 = trunc i64 %19 to i32
  %21 = tail call i64 %8(ptr noundef nonnull %15, ptr noundef %17, i32 noundef %20, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1
  %switch.selectcmp = icmp eq i64 %21, 0
  %switch.select = select i1 %switch.selectcmp, i64 0, i64 -9223372036854775787
  %switch.selectcmp18 = icmp eq i64 %21, -9223372036854775802
  %switch.select19 = select i1 %switch.selectcmp18, i64 -9223372036854775802, i64 %switch.select
  br label %22

22:                                               ; preds = %12, %10
  %.0 = phi i64 [ %., %10 ], [ %switch.select19, %12 ]
  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" }
attributes #1 = { 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, !6, i64 40}
!10 = !{!"", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !6, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !7, i64 0}
!13 = !{!14, !6, i64 232}
!14 = !{!"_DHCP_SERVICE", !11, i64 0, !15, i64 8, !16, i64 24, !6, i64 32, !6, i64 40, !17, i64 48, !16, i64 64, !16, i64 72, !16, 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, !16, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !12, i64 176, !7, i64 208, !7, i64 209, !7, i64 210, !6, i64 232, !10, i64 240, !11, i64 312, !6, i64 320, !11, i64 328, !11, i64 332, !16, i64 336, !16, i64 344, !11, i64 352}
!15 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!18 = !{!10, !6, i64 48}
!19 = !{!14, !16, i64 72}


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