; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip6Dxe (Ip6ProcessMldReport)

; 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.IP6_MLD_HEAD = type { %struct.IP6_ICMP_HEAD, i16, i16, %struct.EFI_IPv6_ADDRESS }
%struct.IP6_ICMP_HEAD = type { i8, i8, i16 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._EFI_IP6_HEADER = type { i16, i16, i16, i8, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS }
%struct.IP6_MLD_GROUP = type { %struct._LIST_ENTRY, i64, %struct.EFI_IPv6_ADDRESS, i32, i8, %struct.EFI_MAC_ADDRESS }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_MAC_ADDRESS = type { [32 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: 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 ptr @Ip6FindMldEntry(ptr noundef, ptr noundef) #1

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) #2

declare void @NetbufFree(ptr noundef) #2

declare zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef) #2

declare zeroext i8 @NetIp6IsLinkLocalAddr(ptr noundef) #2

declare i32 @NetbufCopy(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6ProcessMldReport(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.IP6_MLD_HEAD, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 -9223372036854775806, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %10, i32 0, i32 5
  %12 = call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef %11)
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %15, i32 0, i32 5
  %17 = call zeroext i8 @NetIp6IsLinkLocalAddr(ptr noundef %16)
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  br label %60

20:                                               ; preds = %14, %3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %21, i32 0, i32 4
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = icmp ne i32 %24, 1
  br i1 %25, label %34, label %26

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %27, i32 0, i32 6
  %29 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [16 x i8], ptr %29, i64 0, i64 0
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %32, 255
  br i1 %33, label %35, label %34

34:                                               ; preds = %26, %20
  br label %60

35:                                               ; preds = %26
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call i32 @NetbufCopy(ptr noundef %36, i32 noundef 0, i32 noundef 24, ptr noundef %7)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._EFI_IP6_HEADER, ptr %38, i32 0, i32 6
  %40 = getelementptr inbounds %struct.IP6_MLD_HEAD, ptr %7, i32 0, i32 3
  %41 = call i64 @CompareMem(ptr noundef %39, ptr noundef %40, i64 noundef 16)
  %42 = icmp eq i64 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %35
  br label %60

44:                                               ; preds = %35
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.IP6_MLD_HEAD, ptr %7, i32 0, i32 3
  %47 = call ptr @Ip6FindMldEntry(ptr noundef %45, ptr noundef %46)
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  br label %60

51:                                               ; preds = %44
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.IP6_MLD_GROUP, ptr %52, i32 0, i32 4
  %54 = load i8, ptr %53, align 4, !tbaa !16
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %59, label %56

56:                                               ; preds = %51
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.IP6_MLD_GROUP, ptr %57, i32 0, i32 3
  store i32 0, ptr %58, align 8, !tbaa !20
  br label %59

59:                                               ; preds = %56, %51
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %59, %50, %43, %34, %19
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %61)
  %62 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  ret i64 %62
}

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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 7}
!12 = !{!"_EFI_IP6_HEADER", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !13, i64 2, !13, i64 4, !7, i64 6, !7, i64 7, !14, i64 8, !14, i64 24}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !7, i64 44}
!17 = !{!"", !18, i64 0, !10, i64 16, !14, i64 24, !19, i64 40, !7, i64 44, !14, i64 45}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!"int", !7, i64 0}
!20 = !{!17, !19, i64 40}


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

%struct.IP6_MLD_HEAD = type { %struct.IP6_ICMP_HEAD, i16, i16, %struct.EFI_IPv6_ADDRESS }
%struct.IP6_ICMP_HEAD = type { i8, i8, i16 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

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

; Function Attrs: mustprogress 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 ptr @Ip6FindMldEntry(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @NetbufFree(ptr noundef) local_unnamed_addr #2

declare zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef) local_unnamed_addr #2

declare zeroext i8 @NetIp6IsLinkLocalAddr(ptr noundef) local_unnamed_addr #2

declare i32 @NetbufCopy(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @Ip6ProcessMldReport(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.IP6_MLD_HEAD, align 1
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = tail call zeroext i8 @NetIp6IsUnspecifiedAddr(ptr noundef nonnull %5) #3
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call zeroext i8 @NetIp6IsLinkLocalAddr(ptr noundef nonnull %5) #3
  %.not12 = icmp eq i8 %8, 0
  br i1 %.not12, label %29, label %9

9:                                                ; preds = %7, %3
  %10 = getelementptr inbounds i8, ptr %1, i64 7
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %.not13 = icmp eq i8 %11, 1
  br i1 %.not13, label %12, label %29

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = icmp eq i8 %14, -1
  br i1 %15, label %16, label %29

16:                                               ; preds = %12
  %17 = call i32 @NetbufCopy(ptr noundef %2, i32 noundef 0, i32 noundef 24, ptr noundef nonnull %4) #3
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  %19 = call i64 @CompareMem(ptr noundef nonnull %13, ptr noundef nonnull %18, i64 noundef 16) #3
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %16
  %22 = call ptr @Ip6FindMldEntry(ptr noundef %0, ptr noundef nonnull %18)
  %23 = icmp eq ptr %22, null
  br i1 %23, label %29, label %24

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %22, i64 44
  %26 = load i8, ptr %25, align 4, !tbaa !12
  %.not14 = icmp eq i8 %26, 0
  br i1 %.not14, label %27, label %29

27:                                               ; preds = %24
  %28 = getelementptr inbounds i8, ptr %22, i64 40
  store i32 0, ptr %28, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %24, %27, %21, %16, %9, %12, %7
  %.0 = phi i64 [ -9223372036854775806, %9 ], [ -9223372036854775806, %21 ], [ -9223372036854775806, %16 ], [ -9223372036854775806, %12 ], [ -9223372036854775806, %7 ], [ 0, %27 ], [ 0, %24 ]
  call void @NetbufFree(ptr noundef %2) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  ret i64 %.0
}

attributes #0 = { mustprogress 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, !7, i64 7}
!6 = !{!"_EFI_IP6_HEADER", !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !9, i64 2, !9, i64 4, !7, i64 6, !7, i64 7, !10, i64 8, !10, i64 24}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 44}
!13 = !{!"", !14, i64 0, !16, i64 16, !10, i64 24, !17, i64 40, !7, i64 44, !10, i64 45}
!14 = !{!"_LIST_ENTRY", !15, i64 0, !15, i64 8}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!13, !17, i64 40}


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