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

; 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_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i64, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, %struct.IP4_ASSEMBLE_TABLE, %struct.IGMP_SERVICE_DATA, ptr, ptr, ptr, ptr, %struct.EFI_MANAGED_NETWORK_CONFIG_DATA, %struct.EFI_SIMPLE_NETWORK_MODE, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.IP4_ASSEMBLE_TABLE = type { [31 x %struct._LIST_ENTRY] }
%struct.IGMP_SERVICE_DATA = type { i64, %struct._LIST_ENTRY }
%struct.EFI_MANAGED_NETWORK_CONFIG_DATA = type { i32, i32, i16, i8, i8, i8, i8, i8, i8, i8 }
%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.IGMP_GROUP = type { %struct._LIST_ENTRY, i64, i32, i64, i8, %struct.EFI_MAC_ADDRESS }

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

; 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 i64 @Ip4SendIgmpReport(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Ip4IgmpTicking(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._IP4_SERVICE, ptr %6, i32 0, i32 9
  store ptr %7, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.IGMP_SERVICE_DATA, ptr %8, i32 0, i32 0
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = icmp sgt i64 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.IGMP_SERVICE_DATA, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = add nsw i64 %15, -1
  store i64 %16, ptr %14, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %12, %1
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.IGMP_SERVICE_DATA, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct._LIST_ENTRY, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %4, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %68, %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.IGMP_SERVICE_DATA, ptr %24, i32 0, i32 1
  %26 = icmp ne ptr %23, %25
  br i1 %26, label %27, label %72

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, 0
  %31 = inttoptr i64 %30 to ptr
  store ptr %31, ptr %5, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %27
  %33 = call zeroext i8 @DebugAssertEnabled()
  %34 = icmp ne i8 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.IGMP_GROUP, ptr %36, i32 0, i32 3
  %38 = load i64, ptr %37, align 8, !tbaa !14
  %39 = icmp sge i64 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  call void @DebugAssert(ptr noundef @.str, i64 noundef 535, ptr noundef @.str.1)
  br label %41

41:                                               ; preds = %40, %35
  br label %42

42:                                               ; preds = %41, %32
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.IGMP_GROUP, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !14
  %48 = icmp sgt i64 %47, 0
  br i1 %48, label %49, label %67

49:                                               ; preds = %44
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IGMP_GROUP, ptr %50, i32 0, i32 3
  %52 = load i64, ptr %51, align 8, !tbaa !14
  %53 = add nsw i64 %52, -1
  store i64 %53, ptr %51, align 8, !tbaa !14
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.IGMP_GROUP, ptr %54, i32 0, i32 3
  %56 = load i64, ptr %55, align 8, !tbaa !14
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %66

58:                                               ; preds = %49
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.IGMP_GROUP, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !18
  %63 = call i64 @Ip4SendIgmpReport(ptr noundef %59, i32 noundef %62)
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.IGMP_GROUP, ptr %64, i32 0, i32 4
  store i8 1, ptr %65, align 8, !tbaa !19
  br label %66

66:                                               ; preds = %58, %49
  br label %67

67:                                               ; preds = %66, %44
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._LIST_ENTRY, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !20
  store ptr %71, ptr %4, align 8, !tbaa !5
  br label %22, !llvm.loop !21

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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !11, i64 32}
!15 = !{!"", !12, i64 0, !11, i64 16, !16, i64 24, !11, i64 32, !7, i64 40, !17, i64 41}
!16 = !{!"int", !7, i64 0}
!17 = !{!"", !7, i64 0}
!18 = !{!15, !16, i64 24}
!19 = !{!15, !7, i64 40}
!20 = !{!12, !6, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @Ip4IgmpTicking(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 584
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  %6 = add nsw i64 %3, -1
  store i64 %6, ptr %2, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %5, %1
  %8 = getelementptr inbounds i8, ptr %0, i64 592
  %.018 = load ptr, ptr %8, align 8, !tbaa !12
  %.not19 = icmp eq ptr %.018, %8
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %27
  %.020 = phi ptr [ %.0, %27 ], [ %.018, %7 ]
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not17 = icmp eq i8 %9, 0
  br i1 %.not17, label %15, label %10

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.020, i64 32
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = icmp sgt i64 %12, -1
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 535, ptr noundef nonnull @.str.1) #2
  br label %15

15:                                               ; preds = %10, %14, %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.020, i64 32
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = icmp sgt i64 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %15
  %20 = add nsw i64 %17, -1
  store i64 %20, ptr %16, align 8, !tbaa !13
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %.020, i64 24
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = tail call i64 @Ip4SendIgmpReport(ptr noundef %0, i32 noundef %24)
  %26 = getelementptr inbounds i8, ptr %.020, i64 40
  store i8 1, ptr %26, align 8, !tbaa !18
  br label %27

27:                                               ; preds = %15, %22, %19
  %.0 = load ptr, ptr %.020, align 8, !tbaa !12
  %.not = icmp eq ptr %.0, %8
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %27, %7
  ret void
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8}
!7 = !{!"long long", !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 = !{!10, !11, i64 0}
!13 = !{!14, !7, i64 32}
!14 = !{!"", !10, i64 0, !7, i64 16, !15, i64 24, !7, i64 32, !8, i64 40, !16, i64 41}
!15 = !{!"int", !8, i64 0}
!16 = !{!"", !8, i64 0}
!17 = !{!14, !15, i64 24}
!18 = !{!14, !8, i64 40}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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