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

; 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.6 = external hidden unnamed_addr constant [119 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [38 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 @AllocatePool(i64 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 void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6CombineGroups(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = 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 8, ptr %6) #3
  br label %8

8:                                                ; preds = %2
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %21

11:                                               ; preds = %8
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %19

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i32 %17, 1345736777
  br i1 %18, label %20, label %19

19:                                               ; preds = %14, %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 403, ptr noundef @.str.6)
  br label %20

20:                                               ; preds = %19, %14
  br label %21

21:                                               ; preds = %20, %8
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = call zeroext i8 @DebugAssertEnabled()
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %39

27:                                               ; preds = %24
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %37

30:                                               ; preds = %27
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [16 x i8], ptr %32, i64 0, i64 0
  %34 = load i8, ptr %33, align 1, !tbaa !19
  %35 = zext i8 %34 to i32
  %36 = icmp eq i32 %35, 255
  br i1 %36, label %38, label %37

37:                                               ; preds = %30, %27
  call void @DebugAssert(ptr noundef @.str, i64 noundef 404, ptr noundef @.str.7)
  br label %38

38:                                               ; preds = %37, %30
  br label %39

39:                                               ; preds = %38, %24
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %42, i32 0, i32 15
  %44 = load i32, ptr %43, align 8, !tbaa !20
  %45 = add i32 %44, 1
  store i32 %45, ptr %43, align 8, !tbaa !20
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %46, i32 0, i32 15
  %48 = load i32, ptr %47, align 8, !tbaa !20
  %49 = zext i32 %48 to i64
  %50 = mul i64 %49, 16
  %51 = call ptr @AllocatePool(i64 noundef %50)
  store ptr %51, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %41
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %101

55:                                               ; preds = %41
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %56, i32 0, i32 15
  %58 = load i32, ptr %57, align 8, !tbaa !20
  %59 = icmp ugt i32 %58, 1
  br i1 %59, label %60, label %88

60:                                               ; preds = %55
  br label %61

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

64:                                               ; preds = %61
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %65, i32 0, i32 14
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = icmp ne ptr %67, null
  br i1 %68, label %70, label %69

69:                                               ; preds = %64
  call void @DebugAssert(ptr noundef @.str, i64 noundef 414, ptr noundef @.str.8)
  br label %70

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

71:                                               ; preds = %70, %61
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %75, i32 0, i32 14
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %78, i32 0, i32 15
  %80 = load i32, ptr %79, align 8, !tbaa !20
  %81 = sub i32 %80, 1
  %82 = zext i32 %81 to i64
  %83 = mul i64 %82, 16
  %84 = call ptr @CopyMem(ptr noundef %74, ptr noundef %77, i64 noundef %83)
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %85, i32 0, i32 14
  %87 = load ptr, ptr %86, align 8, !tbaa !21
  call void @FreePool(ptr noundef %87)
  br label %88

88:                                               ; preds = %73, %55
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %90, i32 0, i32 15
  %92 = load i32, ptr %91, align 8, !tbaa !20
  %93 = sub i32 %92, 1
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %89, i64 %94
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = call ptr @CopyMem(ptr noundef %95, ptr noundef %96, i64 noundef 16)
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %99, i32 0, i32 14
  store ptr %98, ptr %100, align 8, !tbaa !21
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %101

101:                                              ; preds = %88, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %102 = load i64, ptr %3, align 8
  ret i64 %102
}

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 0}
!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 = !{!7, !7, i64 0}
!20 = !{!10, !11, i64 296}
!21 = !{!10, !6, i64 288}


; 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.6 = external hidden unnamed_addr constant [119 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [38 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 @AllocatePool(i64 noundef) local_unnamed_addr #0

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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @Ip6CombineGroups(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %9, label %4

4:                                                ; preds = %2
  %.not21 = icmp eq ptr %0, null
  br i1 %.not21, label %8, label %5

5:                                                ; preds = %4
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1345736777
  br i1 %7, label %9, label %8

8:                                                ; preds = %5, %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 403, ptr noundef nonnull @.str.6) #2
  br label %9

9:                                                ; preds = %2, %8, %5
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not22 = icmp eq i8 %10, 0
  br i1 %.not22, label %16, label %11

11:                                               ; preds = %9
  %.not23 = icmp eq ptr %1, null
  br i1 %.not23, label %15, label %12

12:                                               ; preds = %11
  %13 = load i8, ptr %1, align 1, !tbaa !18
  %14 = icmp eq i8 %13, -1
  br i1 %14, label %16, label %15

15:                                               ; preds = %12, %11
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 404, ptr noundef nonnull @.str.7) #2
  br label %16

16:                                               ; preds = %12, %15, %9
  %17 = getelementptr inbounds i8, ptr %0, i64 296
  %18 = load i32, ptr %17, align 8, !tbaa !19
  %19 = add i32 %18, 1
  store i32 %19, ptr %17, align 8, !tbaa !19
  %20 = zext i32 %19 to i64
  %21 = shl nuw nsw i64 %20, 4
  %22 = tail call ptr @AllocatePool(i64 noundef %21) #2
  %23 = icmp eq ptr %22, null
  br i1 %23, label %49, label %24

24:                                               ; preds = %16
  %25 = load i32, ptr %17, align 8, !tbaa !19
  %26 = icmp ugt i32 %25, 1
  br i1 %26, label %27, label %42

27:                                               ; preds = %24
  %28 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not24 = icmp eq i8 %28, 0
  br i1 %.not24, label %33, label %29

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %0, i64 288
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %.not25 = icmp eq ptr %31, null
  br i1 %.not25, label %32, label %33

32:                                               ; preds = %29
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 414, ptr noundef nonnull @.str.8) #2
  br label %33

33:                                               ; preds = %29, %32, %27
  %34 = getelementptr inbounds i8, ptr %0, i64 288
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = load i32, ptr %17, align 8, !tbaa !19
  %37 = add i32 %36, -1
  %38 = zext i32 %37 to i64
  %39 = shl nuw nsw i64 %38, 4
  %40 = tail call ptr @CopyMem(ptr noundef nonnull %22, ptr noundef %35, i64 noundef %39) #2
  %41 = load ptr, ptr %34, align 8, !tbaa !20
  tail call void @FreePool(ptr noundef %41) #2
  %.pre = load i32, ptr %17, align 8, !tbaa !19
  br label %42

42:                                               ; preds = %33, %24
  %43 = phi i32 [ %.pre, %33 ], [ %25, %24 ]
  %44 = add i32 %43, -1
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %22, i64 %45
  %47 = tail call ptr @CopyMem(ptr noundef nonnull %46, ptr noundef %1, i64 noundef 16) #2
  %48 = getelementptr inbounds i8, ptr %0, i64 288
  store ptr %22, ptr %48, align 8, !tbaa !20
  br label %49

49:                                               ; preds = %16, %42
  %.0 = phi i64 [ 0, %42 ], [ -9223372036854775799, %16 ]
  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 0}
!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 = !{!8, !8, i64 0}
!19 = !{!6, !7, i64 296}
!20 = !{!6, !11, i64 288}


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