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

; 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._IP4_PROTOCOL = type { i32, %struct._EFI_IP4_PROTOCOL, ptr, i64, ptr, %struct._LIST_ENTRY, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct.EFI_LOCK, ptr, %struct._LIST_ENTRY, ptr, ptr, i32, ptr, i32, %struct.EFI_IP4_CONFIG_DATA }
%struct._EFI_IP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, i8, i8, i8, i32, i32 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.NET_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%struct.IP4_CLIP_INFO = type { i64, i64, i64, i64, i64, i32, i64 }

; 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 zeroext i8 @Ip4InstanceFrameAcceptable(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4InstanceEnquePacket(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 ptr, align 8
  %9 = alloca ptr, 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 %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i64 -9223372036854775789, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %46

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = call zeroext i8 @Ip4InstanceFrameAcceptable(ptr noundef %17, ptr noundef %18, ptr noundef %19)
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %46

23:                                               ; preds = %16
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call ptr @NetbufClone(ptr noundef %24)
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %46

29:                                               ; preds = %23
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.NET_BUF, ptr %30, i32 0, i32 6
  %32 = getelementptr inbounds [64 x i8], ptr %31, i64 0, i64 0
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %33, i32 0, i32 18
  %35 = getelementptr inbounds %struct.EFI_IP4_CONFIG_DATA, ptr %34, i32 0, i32 12
  %36 = load i32, ptr %35, align 4, !tbaa !19
  %37 = add i32 %36, 999999
  %38 = udiv i32 %37, 1000000
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.IP4_CLIP_INFO, ptr %39, i32 0, i32 5
  store i32 %38, ptr %40, align 8, !tbaa !20
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._IP4_PROTOCOL, ptr %41, i32 0, i32 8
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NET_BUF, ptr %43, i32 0, i32 2
  %45 = call ptr @InsertTailList(ptr noundef %42, ptr noundef %44)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %46

46:                                               ; preds = %29, %28, %22, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %47 = load i64, ptr %4, align 8
  ret i64 %47
}

declare ptr @NetbufClone(ptr noundef) #2

declare ptr @InsertTailList(ptr noundef, ptr noundef) #2

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, !13, i64 80}
!10 = !{!"_IP4_PROTOCOL", !11, i64 0, !12, i64 8, !6, i64 72, !13, i64 80, !6, i64 88, !14, i64 96, !15, i64 112, !15, i64 152, !14, i64 192, !14, i64 208, !16, i64 224, !6, i64 248, !14, i64 256, !6, i64 272, !6, i64 280, !11, i64 288, !6, i64 296, !11, i64 304, !17, i64 308}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_IP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"", !14, i64 0, !14, i64 16, !13, i64 32}
!16 = !{!"", !13, i64 0, !13, i64 8, !11, i64 16}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !18, i64 6, !18, i64 10, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !11, i64 20, !11, i64 24}
!18 = !{!"", !7, i64 0}
!19 = !{!10, !11, i64 328}
!20 = !{!21, !11, i64 40}
!21 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !11, i64 40, !13, i64 48}


; 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 zeroext i8 @Ip4InstanceFrameAcceptable(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @Ip4InstanceEnquePacket(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 1
  br i1 %.not, label %6, label %20

6:                                                ; preds = %3
  %7 = tail call zeroext i8 @Ip4InstanceFrameAcceptable(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2)
  %.not12 = icmp eq i8 %7, 0
  br i1 %.not12, label %20, label %8

8:                                                ; preds = %6
  %9 = tail call ptr @NetbufClone(ptr noundef %2) #2
  %10 = icmp eq ptr %9, null
  br i1 %10, label %20, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 328
  %13 = load i32, ptr %12, align 4, !tbaa !18
  %14 = add i32 %13, 999999
  %15 = udiv i32 %14, 1000000
  %16 = getelementptr inbounds i8, ptr %9, i64 96
  store i32 %15, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %0, i64 192
  %18 = getelementptr inbounds i8, ptr %9, i64 16
  %19 = tail call ptr @InsertTailList(ptr noundef nonnull %17, ptr noundef nonnull %18) #2
  br label %20

20:                                               ; preds = %8, %6, %3, %11
  %.0 = phi i64 [ 0, %11 ], [ -9223372036854775789, %3 ], [ -9223372036854775806, %6 ], [ -9223372036854775799, %8 ]
  ret i64 %.0
}

declare ptr @NetbufClone(ptr noundef) local_unnamed_addr #1

declare ptr @InsertTailList(ptr 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, !12, i64 80}
!6 = !{!"_IP4_PROTOCOL", !7, i64 0, !10, i64 8, !11, i64 72, !12, i64 80, !11, i64 88, !13, i64 96, !14, i64 112, !14, i64 152, !13, i64 192, !13, i64 208, !15, i64 224, !11, i64 248, !13, i64 256, !11, i64 272, !11, i64 280, !7, i64 288, !11, i64 296, !7, i64 304, !16, i64 308}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_IP4_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!14 = !{!"", !13, i64 0, !13, i64 16, !12, i64 32}
!15 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16}
!16 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !17, i64 6, !17, i64 10, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !7, i64 20, !7, i64 24}
!17 = !{!"", !8, i64 0}
!18 = !{!6, !7, i64 328}
!19 = !{!20, !7, i64 40}
!20 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !7, i64 40, !12, i64 48}


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