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

; 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] }
%struct.IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT = type { ptr, ptr }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }

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

; 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
define dso_local i64 @Ip6DestroyChildEntryByAddr(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 ptr, align 8
  %8 = alloca ptr, align 8
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = call zeroext i8 @DebugAssertEnabled()
  %11 = zext i8 %10 to i32
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %23

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  %16 = sub i64 %15, ptrtoint (ptr getelementptr inbounds (%struct._IP6_PROTOCOL, ptr null, i32 0, i32 5) to i64)
  %17 = inttoptr i64 %16 to ptr
  %18 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = icmp ne i32 %19, 1345736777
  br i1 %20, label %21, label %23

21:                                               ; preds = %13
  call void @DebugAssert(ptr noundef @.str, i64 noundef 352, ptr noundef @.str.1)
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  br label %28

23:                                               ; preds = %13, %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %25, ptrtoint (ptr getelementptr inbounds (%struct._IP6_PROTOCOL, ptr null, i32 0, i32 5) to i64)
  %27 = inttoptr i64 %26 to ptr
  br label %28

28:                                               ; preds = %23, %21
  %29 = phi ptr [ %22, %21 ], [ %27, %23 ]
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.IP6_DESTROY_CHILD_BY_ADDR_CALLBACK_CONTEXT, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %36, i32 0, i32 3
  %38 = load i64, ptr %37, align 8, !tbaa !22
  %39 = icmp eq i64 %38, 1
  br i1 %39, label %40, label %56

40:                                               ; preds = %28
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %41, i32 0, i32 16
  %43 = getelementptr inbounds %struct.EFI_IP6_CONFIG_DATA, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call i64 @CompareMem(ptr noundef %43, ptr noundef %44, i64 noundef 16)
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %56

47:                                               ; preds = %40
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !23
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !25
  %55 = call i64 %50(ptr noundef %51, ptr noundef %54)
  store i64 %55, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

56:                                               ; preds = %40, %28
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %56, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %58 = load i64, ptr %3, align 8
  ret i64 %58
}

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

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 = !{!20, !6, i64 0}
!20 = !{!"", !6, i64 0, !6, i64 8}
!21 = !{!20, !6, i64 8}
!22 = !{!10, !13, i64 88}
!23 = !{!24, !6, i64 8}
!24 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!25 = !{!10, !6, i64 80}


; 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 [131 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6DestroyChildEntryByAddr(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %3, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre12 = add i64 %.pre, -104
  %.pre14 = inttoptr i64 %.pre12 to ptr
  br i1 %.not, label %._crit_edge, label %4

4:                                                ; preds = %2
  %5 = load i32, ptr %.pre14, align 8, !tbaa !5
  %.not11 = icmp eq i32 %5, 1345736777
  br i1 %.not11, label %._crit_edge, label %6

6:                                                ; preds = %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 352, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %4, %6
  %7 = phi ptr [ %0, %6 ], [ %.pre14, %4 ], [ %.pre14, %2 ]
  %8 = load ptr, ptr %1, align 8, !tbaa !18
  %9 = getelementptr inbounds i8, ptr %7, i64 88
  %10 = load i64, ptr %9, align 8, !tbaa !20
  %11 = icmp eq i64 %10, 1
  br i1 %11, label %12, label %24

12:                                               ; preds = %._crit_edge
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %7, i64 320
  %16 = tail call i64 @CompareMem(ptr noundef nonnull %15, ptr noundef %14, i64 noundef 16) #2
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %8, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  %21 = getelementptr inbounds i8, ptr %7, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !24
  %23 = tail call i64 %20(ptr noundef %8, ptr noundef %22) #2
  br label %24

24:                                               ; preds = %._crit_edge, %12, %18
  %.0 = phi i64 [ %23, %18 ], [ 0, %12 ], [ 0, %._crit_edge ]
  ret i64 %.0
}

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = !{!19, !11, i64 0}
!19 = !{!"", !11, i64 0, !11, i64 8}
!20 = !{!6, !12, i64 88}
!21 = !{!19, !11, i64 8}
!22 = !{!23, !11, i64 8}
!23 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !11, i64 0, !11, i64 8}
!24 = !{!6, !11, i64 80}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass