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

; 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] }

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

; Function Attrs: nounwind uwtable
define dso_local i64 @DhcpSetState(ptr noundef %0, i64 noundef %1, i8 noundef zeroext %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i8 %2, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load i8, ptr %7, align 1, !tbaa !11
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %38

12:                                               ; preds = %3
  store i64 0, ptr %8, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp eq i64 %13, 5
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i64 @DhcpCallUser(ptr noundef %16, i32 noundef 9, ptr noundef null, ptr noundef null)
  store i64 %17, ptr %8, align 8, !tbaa !9
  br label %32

18:                                               ; preds = %12
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 6
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i64 @DhcpCallUser(ptr noundef %22, i32 noundef 10, ptr noundef null, ptr noundef null)
  store i64 %23, ptr %8, align 8, !tbaa !9
  br label %31

24:                                               ; preds = %18
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 4
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i64 @DhcpCallUser(ptr noundef %28, i32 noundef 8, ptr noundef null, ptr noundef null)
  store i64 %29, ptr %8, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %27, %24
  br label %31

31:                                               ; preds = %30, %21
  br label %32

32:                                               ; preds = %31, %15
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %32
  %36 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %36, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %75

37:                                               ; preds = %32
  br label %38

38:                                               ; preds = %37, %3
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = icmp eq i64 %39, 2
  br i1 %40, label %41, label %49

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %42, i32 0, i32 28
  %44 = getelementptr inbounds %struct.EFI_DHCP4_CONFIG_DATA, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !12
  %46 = zext i32 %45 to i64
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %47, i32 0, i32 34
  store i64 %46, ptr %48, align 8, !tbaa !19
  br label %57

49:                                               ; preds = %38
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %50, i32 0, i32 28
  %52 = getelementptr inbounds %struct.EFI_DHCP4_CONFIG_DATA, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !20
  %54 = zext i32 %53 to i64
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %55, i32 0, i32 34
  store i64 %54, ptr %56, align 8, !tbaa !19
  br label %57

57:                                               ; preds = %49, %41
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %58, i32 0, i32 34
  %60 = load i64, ptr %59, align 8, !tbaa !19
  %61 = icmp eq i64 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %57
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %63, i32 0, i32 34
  store i64 4, ptr %64, align 8, !tbaa !19
  br label %65

65:                                               ; preds = %62, %57
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %66, i32 0, i32 33
  store i64 0, ptr %67, align 8, !tbaa !21
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %68, i32 0, i32 31
  store i32 0, ptr %69, align 8, !tbaa !22
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %70, i32 0, i32 32
  store i32 0, ptr %71, align 4, !tbaa !23
  %72 = load i64, ptr %6, align 8, !tbaa !9
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %73, i32 0, i32 7
  store i64 %72, ptr %74, align 8, !tbaa !24
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %75

75:                                               ; preds = %65, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %76 = load i64, ptr %4, align 8
  ret i64 %76
}

; 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

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


; 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 range(i64 -9223372036854775808, 1) i64 @DhcpSetState(ptr noundef %0, i64 noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %.thread, label %4

4:                                                ; preds = %3
  switch i64 %1, label %.thread24 [
    i64 5, label %7
    i64 6, label %5
    i64 4, label %6
    i64 2, label %11
  ]

5:                                                ; preds = %4
  br label %7

6:                                                ; preds = %4
  br label %7

7:                                                ; preds = %4, %5, %6
  %.sink = phi i32 [ 10, %5 ], [ 8, %6 ], [ 9, %4 ]
  %8 = tail call i64 @DhcpCallUser(ptr noundef %0, i32 noundef %.sink, ptr noundef null, ptr noundef null)
  %9 = icmp slt i64 %8, 0
  br i1 %9, label %22, label %.thread24

.thread:                                          ; preds = %3
  %10 = icmp eq i64 %1, 2
  br i1 %10, label %11, label %.thread24

.thread24:                                        ; preds = %4, %7, %.thread
  br label %11

11:                                               ; preds = %.thread, %4, %.thread24
  %.sink29 = phi i64 [ 256, %.thread24 ], [ 240, %4 ], [ 240, %.thread ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %.sink29
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %0, i64 344
  store i64 %14, ptr %15, align 8, !tbaa !9
  %16 = icmp eq i32 %13, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %11
  %18 = getelementptr inbounds i8, ptr %0, i64 344
  store i64 4, ptr %18, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %17, %11
  %20 = getelementptr inbounds i8, ptr %0, i64 328
  %21 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %20, i8 0, i64 16, i1 false)
  store i64 %1, ptr %21, align 8, !tbaa !17
  br label %22

22:                                               ; preds = %7, %19
  %.021 = phi i64 [ 0, %19 ], [ %8, %7 ]
  ret i64 %.021
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass