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

; 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._UDP4_INSTANCE_DATA_ = type { i32, %struct._LIST_ENTRY, ptr, %struct._EFI_UDP4_PROTOCOL, %struct.EFI_UDP4_CONFIG_DATA, ptr, i8, i8, %struct.NET_MAP, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i16, i64, ptr, i8 }
%struct._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_UDP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._LIST_ENTRY = type { ptr, ptr }

; 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 void @Udp4RecycleRxDataWrap(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Udp4FlushRcvdDgram(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  br label %4

4:                                                ; preds = %10, %1
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %5, i32 0, i32 11
  %7 = call zeroext i8 @IsListEmpty(ptr noundef %6)
  %8 = icmp ne i8 %7, 0
  %9 = xor i1 %8, true
  br i1 %9, label %10, label %19

10:                                               ; preds = %4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %11, i32 0, i32 11
  %13 = getelementptr inbounds %struct._LIST_ENTRY, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = ptrtoint ptr %14 to i64
  %16 = sub i64 %15, 0
  %17 = inttoptr i64 %16 to ptr
  store ptr %17, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Udp4RecycleRxDataWrap(ptr noundef null, ptr noundef %18)
  br label %4, !llvm.loop !19

19:                                               ; preds = %4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare zeroext i8 @IsListEmpty(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, !6, i64 272}
!10 = !{!"_UDP4_INSTANCE_DATA_", !11, i64 0, !12, i64 8, !6, i64 24, !13, i64 32, !14, i64 96, !6, i64 136, !7, i64 144, !7, i64 145, !17, i64 152, !17, i64 192, !17, i64 232, !12, i64 272, !12, i64 288, !16, i64 304, !18, i64 312, !6, i64 320, !7, i64 328}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"_EFI_UDP4_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}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !11, i64 8, !11, i64 12, !7, i64 16, !15, i64 17, !15, i64 21, !16, i64 26, !15, i64 28, !16, i64 32}
!15 = !{!"", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !12, i64 0, !12, i64 16, !18, i64 32}
!18 = !{!"long long", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
define dso_local void @Udp4FlushRcvdDgram(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 272
  %3 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %2) #2
  %.not3 = icmp eq i8 %3, 0
  br i1 %.not3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @Udp4RecycleRxDataWrap(ptr noundef null, ptr noundef %4)
  %5 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %2) #2
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret void
}

declare zeroext i8 @IsListEmpty(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, !11, i64 272}
!6 = !{!"_UDP4_INSTANCE_DATA_", !7, i64 0, !10, i64 8, !11, i64 24, !12, i64 32, !13, i64 96, !11, i64 136, !8, i64 144, !8, i64 145, !16, i64 152, !16, i64 192, !16, i64 232, !10, i64 272, !10, i64 288, !15, i64 304, !17, i64 312, !11, i64 320, !8, i64 328}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_EFI_UDP4_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}
!13 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !7, i64 8, !7, i64 12, !8, i64 16, !14, i64 17, !14, i64 21, !15, i64 26, !14, i64 28, !15, i64 32}
!14 = !{!"", !8, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 16, !17, i64 32}
!17 = !{!"long long", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass