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

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

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @DhcpComputeLease(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %2
  %6 = call zeroext i8 @DebugAssertEnabled()
  %7 = icmp ne i8 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @DebugAssert(ptr noundef @.str, i64 noundef 288, ptr noundef @.str.3)
  br label %12

12:                                               ; preds = %11, %8
  br label %13

13:                                               ; preds = %12, %5
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %15, i32 0, i32 5
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %18, i32 0, i32 16
  store i32 %17, ptr %19, align 8, !tbaa !12
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %20, i32 0, i32 7
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %23, i32 0, i32 18
  store i32 %22, ptr %24, align 8, !tbaa !20
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %25, i32 0, i32 6
  %27 = load i32, ptr %26, align 4, !tbaa !21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %28, i32 0, i32 17
  store i32 %27, ptr %29, align 4, !tbaa !22
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %30, i32 0, i32 16
  %32 = load i32, ptr %31, align 8, !tbaa !12
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %14
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %35, i32 0, i32 16
  store i32 604800, ptr %36, align 8, !tbaa !12
  br label %37

37:                                               ; preds = %34, %14
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %38, i32 0, i32 18
  %40 = load i32, ptr %39, align 8, !tbaa !20
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %50, label %42

42:                                               ; preds = %37
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %43, i32 0, i32 18
  %45 = load i32, ptr %44, align 8, !tbaa !20
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %46, i32 0, i32 5
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp uge i32 %45, %48
  br i1 %49, label %50, label %61

50:                                               ; preds = %42, %37
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %51, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %54, i32 0, i32 5
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = lshr i32 %56, 3
  %58 = sub i32 %53, %57
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %59, i32 0, i32 18
  store i32 %58, ptr %60, align 8, !tbaa !20
  br label %61

61:                                               ; preds = %50, %42
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %62, i32 0, i32 17
  %64 = load i32, ptr %63, align 4, !tbaa !22
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %74, label %66

66:                                               ; preds = %61
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %67, i32 0, i32 17
  %69 = load i32, ptr %68, align 4, !tbaa !22
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.DHCP_PARAMETER, ptr %70, i32 0, i32 7
  %72 = load i32, ptr %71, align 4, !tbaa !19
  %73 = icmp uge i32 %69, %72
  br i1 %73, label %74, label %81

74:                                               ; preds = %66, %61
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %75, i32 0, i32 16
  %77 = load i32, ptr %76, align 8, !tbaa !12
  %78 = lshr i32 %77, 1
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._DHCP_SERVICE, ptr %79, i32 0, i32 17
  store i32 %78, ptr %80, align 4, !tbaa !22
  br label %81

81:                                               ; preds = %74, %66
  ret void
}

attributes #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 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" }

!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 16}
!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, !11, i64 128}
!13 = !{!"_DHCP_SERVICE", !11, i64 0, !14, i64 8, !15, i64 24, !6, i64 32, !6, i64 40, !16, i64 48, !15, i64 64, !15, i64 72, !15, 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, !15, 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, !11, i64 312, !6, i64 320, !11, i64 328, !11, i64 332, !15, i64 336, !15, i64 344, !11, i64 352}
!14 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"", !7, i64 0}
!18 = !{!"", !11, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !17, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !6, i64 64}
!19 = !{!10, !11, i64 24}
!20 = !{!13, !11, i64 136}
!21 = !{!10, !11, i64 20}
!22 = !{!13, !11, i64 132}


; 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"

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @DhcpComputeLease(ptr nocapture noundef writeonly %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %4 = icmp eq i8 %3, 0
  %5 = icmp ne ptr %1, null
  %or.cond = or i1 %5, %4
  br i1 %or.cond, label %7, label %6

6:                                                ; preds = %2
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 288, ptr noundef nonnull @.str.3) #2
  br label %7

7:                                                ; preds = %2, %6
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 %9, ptr %10, align 8, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  %12 = load i32, ptr %11, align 4, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %0, i64 136
  store i32 %12, ptr %13, align 8, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %1, i64 20
  %15 = load i32, ptr %14, align 4, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %0, i64 132
  store i32 %15, ptr %16, align 4, !tbaa !21
  %17 = icmp eq i32 %9, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %7
  store i32 604800, ptr %10, align 8, !tbaa !10
  br label %19

19:                                               ; preds = %18, %7
  %20 = phi i32 [ 604800, %18 ], [ %9, %7 ]
  %21 = icmp ne i32 %12, 0
  %.not = icmp ult i32 %12, %9
  %or.cond23 = and i1 %21, %.not
  br i1 %or.cond23, label %25, label %22

22:                                               ; preds = %19
  %23 = lshr i32 %9, 3
  %24 = sub i32 %9, %23
  store i32 %24, ptr %13, align 8, !tbaa !19
  br label %25

25:                                               ; preds = %19, %22
  %26 = icmp ne i32 %15, 0
  %.not22 = icmp ult i32 %15, %12
  %or.cond24 = select i1 %26, i1 %.not22, i1 false
  br i1 %or.cond24, label %29, label %27

27:                                               ; preds = %25
  %28 = lshr i32 %20, 1
  store i32 %28, ptr %16, align 4, !tbaa !21
  br label %29

29:                                               ; preds = %25, %27
  ret void
}

attributes #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 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, !7, i64 16}
!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 128}
!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 = !{!6, !7, i64 24}
!19 = !{!11, !7, i64 136}
!20 = !{!6, !7, i64 20}
!21 = !{!11, !7, i64 132}


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