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

; 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_PROTOCOL = type { i32, %struct._EFI_IP6_PROTOCOL, ptr, i64, ptr, %struct._LIST_ENTRY, i8, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct.EFI_LOCK, ptr, %struct._LIST_ENTRY, ptr, i32, %struct.EFI_IP6_CONFIG_DATA, i8 }
%struct._EFI_IP6_PROTOCOL = type { ptr, 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_IP6_CONFIG_DATA = type { i8, i8, i8, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS, i8, i8, i32, i32, i32 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

@.str = external hidden unnamed_addr constant [128 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [27 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

declare zeroext i8 @DebugAssertEnabled() #1

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

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

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

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

12:                                               ; preds = %28, %2
  %13 = load i32, ptr %6, align 4, !tbaa !19
  %14 = load i32, ptr %7, align 4, !tbaa !19
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %16, label %31

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %17, i32 0, i32 14
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = load i32, ptr %6, align 4, !tbaa !19
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %19, i64 %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call i64 @CompareMem(ptr noundef %22, ptr noundef %23, i64 noundef 16)
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %16
  br label %31

27:                                               ; preds = %16
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %6, align 4, !tbaa !19
  %30 = add i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !19
  br label %12, !llvm.loop !21

31:                                               ; preds = %26, %12
  %32 = load i32, ptr %6, align 4, !tbaa !19
  %33 = load i32, ptr %7, align 4, !tbaa !19
  %34 = icmp eq i32 %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i64 -9223372036854775794, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %77

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %42, %36
  %38 = load i32, ptr %6, align 4, !tbaa !19
  %39 = load i32, ptr %7, align 4, !tbaa !19
  %40 = sub i32 %39, 1
  %41 = icmp ult i32 %38, %40
  br i1 %41, label %42, label %59

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %43, i32 0, i32 14
  %45 = load ptr, ptr %44, align 8, !tbaa !20
  %46 = load i32, ptr %6, align 4, !tbaa !19
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %45, i64 %47
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %49, i32 0, i32 14
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = load i32, ptr %6, align 4, !tbaa !19
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %54, i64 1
  %56 = call ptr @CopyMem(ptr noundef %48, ptr noundef %55, i64 noundef 16)
  %57 = load i32, ptr %6, align 4, !tbaa !19
  %58 = add i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !19
  br label %37, !llvm.loop !23

59:                                               ; preds = %37
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i8 @DebugAssertEnabled()
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %70

63:                                               ; preds = %60
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %64, i32 0, i32 15
  %66 = load i32, ptr %65, align 8, !tbaa !9
  %67 = icmp ugt i32 %66, 0
  br i1 %67, label %69, label %68

68:                                               ; preds = %63
  call void @DebugAssert(ptr noundef @.str, i64 noundef 470, ptr noundef @.str.9)
  br label %69

69:                                               ; preds = %68, %63
  br label %70

70:                                               ; preds = %69, %60
  br label %71

71:                                               ; preds = %70
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %73, i32 0, i32 15
  %75 = load i32, ptr %74, align 8, !tbaa !9
  %76 = add i32 %75, -1
  store i32 %76, ptr %74, align 8, !tbaa !9
  store i64 0, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %77

77:                                               ; preds = %72, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %78 = load i64, ptr %3, align 8
  ret i64 %78
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 296}
!10 = !{!"_IP6_PROTOCOL", !11, i64 0, !12, i64 8, !6, i64 80, !13, i64 88, !6, i64 96, !14, i64 104, !7, i64 120, !15, i64 128, !15, i64 168, !14, i64 208, !14, i64 224, !16, i64 240, !6, i64 264, !14, i64 272, !6, i64 288, !11, i64 296, !17, i64 300, !7, i64 352}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_IP6_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, !6, i64 64}
!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, !18, i64 4, !18, i64 20, !7, i64 36, !7, i64 37, !11, i64 40, !11, i64 44, !11, i64 48}
!18 = !{!"", !7, i64 0}
!19 = !{!11, !11, i64 0}
!20 = !{!10, !6, i64 288}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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.EFI_IPv6_ADDRESS = type { [16 x i8] }

@.str = external hidden unnamed_addr constant [128 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [27 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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775794, 1) i64 @Ip6RemoveGroup(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 296
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 288
  %.not26 = icmp eq i32 %4, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %10
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %10 ]
  %6 = load ptr, ptr %5, align 8, !tbaa !18
  %7 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %6, i64 %indvars.iv
  %8 = tail call i64 @CompareMem(ptr noundef %7, ptr noundef %1, i64 noundef 16) #2
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %._crit_edge.loopexit, label %10

10:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !19

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %11 = trunc nuw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.018.lcssa = phi i32 [ 0, %2 ], [ %11, %._crit_edge.loopexit ]
  %12 = icmp eq i32 %.018.lcssa, %4
  br i1 %12, label %._crit_edge.thread, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %13 = add i32 %4, -1
  %14 = icmp ult i32 %.018.lcssa, %13
  br i1 %14, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %.preheader
  %15 = zext i32 %.018.lcssa to i64
  br label %16

16:                                               ; preds = %.lr.ph24, %16
  %indvars.iv28 = phi i64 [ %15, %.lr.ph24 ], [ %indvars.iv.next29, %16 ]
  %17 = load ptr, ptr %5, align 8, !tbaa !18
  %18 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %17, i64 %indvars.iv28
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = tail call ptr @CopyMem(ptr noundef %18, ptr noundef nonnull %19, i64 noundef 16) #2
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next29 to i32
  %exitcond31.not = icmp eq i32 %13, %lftr.wideiv
  br i1 %exitcond31.not, label %._crit_edge25, label %16, !llvm.loop !21

._crit_edge25:                                    ; preds = %16, %.preheader
  %21 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp ne i8 %21, 0
  %.pre32 = load i32, ptr %3, align 8, !tbaa !5
  %.not19 = icmp eq i32 %.pre32, 0
  %or.cond = select i1 %.not, i1 %.not19, i1 false
  br i1 %or.cond, label %22, label %23

22:                                               ; preds = %._crit_edge25
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 470, ptr noundef nonnull @.str.9) #2
  %.pre = load i32, ptr %3, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %22, %._crit_edge25
  %24 = phi i32 [ %.pre, %22 ], [ %.pre32, %._crit_edge25 ]
  %25 = add i32 %24, -1
  store i32 %25, ptr %3, align 8, !tbaa !5
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %10, %._crit_edge, %23
  %.0 = phi i64 [ 0, %23 ], [ -9223372036854775794, %._crit_edge ], [ -9223372036854775794, %10 ]
  ret i64 %.0
}

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 296}
!6 = !{!"_IP6_PROTOCOL", !7, i64 0, !10, i64 8, !11, i64 80, !12, i64 88, !11, i64 96, !13, i64 104, !8, i64 120, !14, i64 128, !14, i64 168, !13, i64 208, !13, i64 224, !15, i64 240, !11, i64 264, !13, i64 272, !11, i64 288, !7, i64 296, !16, i64 300, !8, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_EFI_IP6_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, i64 64}
!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, !17, i64 4, !17, i64 20, !8, i64 36, !8, i64 37, !7, i64 40, !7, i64 44, !7, i64 48}
!17 = !{!"", !8, i64 0}
!18 = !{!6, !11, i64 288}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass