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

; 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.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._IP6_PREFIX_LIST_ENTRY = type { %struct._LIST_ENTRY, i64, i32, i32, i8, %struct.EFI_IPv6_ADDRESS }
%struct._LIST_ENTRY = type { ptr, ptr }

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

declare ptr @ZeroMem(ptr noundef, 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

; Function Attrs: nounwind uwtable
declare dso_local void @Ip6GetPrefix(i8 noundef zeroext, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @Ip6IsAnycast(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.EFI_IPv6_ADDRESS, align 1
  %8 = alloca i8, align 1
  %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 16, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %10 = call ptr @ZeroMem(ptr noundef %7, i64 noundef 16)
  store i8 0, ptr %8, align 1, !tbaa !9
  br label %11

11:                                               ; preds = %36, %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i8, ptr %8, align 1, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call ptr @Ip6FindPrefixListEntry(ptr noundef %12, i8 noundef zeroext %13, i8 noundef zeroext -1, ptr noundef %14)
  store ptr %15, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %30

18:                                               ; preds = %11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._IP6_PREFIX_LIST_ENTRY, ptr %19, i32 0, i32 5
  %21 = call ptr @CopyMem(ptr noundef %7, ptr noundef %20, i64 noundef 16)
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._IP6_PREFIX_LIST_ENTRY, ptr %22, i32 0, i32 4
  %24 = load i8, ptr %23, align 8, !tbaa !10
  call void @Ip6GetPrefix(i8 noundef zeroext %24, ptr noundef %7)
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i64 @CompareMem(ptr noundef %7, ptr noundef %25, i64 noundef 16)
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %18
  store i8 1, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %40

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29, %11
  %31 = load i8, ptr %8, align 1, !tbaa !9
  %32 = icmp ne i8 %31, 0
  %33 = xor i1 %32, true
  %34 = zext i1 %33 to i32
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %8, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %30
  %37 = load i8, ptr %8, align 1, !tbaa !9
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %11, label %39, !llvm.loop !16

39:                                               ; preds = %36
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %40

40:                                               ; preds = %39, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %41 = load i8, ptr %3, align 1
  ret i8 %41
}

declare ptr @Ip6FindPrefixListEntry(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) #1

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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 32}
!11 = !{!"_IP6_PREFIX_LIST_ENTRY", !12, i64 0, !13, i64 16, !14, i64 24, !14, i64 28, !7, i64 32, !15, i64 33}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%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

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; 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 void @Ip6GetPrefix(i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @Ip6IsAnycast(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
.peel.begin:
  %2 = alloca %struct.EFI_IPv6_ADDRESS, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  %3 = call ptr @ZeroMem(ptr noundef nonnull %2, i64 noundef 16) #3
  %4 = call ptr @Ip6FindPrefixListEntry(ptr noundef %0, i8 noundef zeroext 0, i8 noundef zeroext -1, ptr noundef %1) #3
  %.not.peel = icmp eq ptr %4, null
  br i1 %.not.peel, label %.backedge.peel, label %5

5:                                                ; preds = %.peel.begin
  %6 = getelementptr inbounds i8, ptr %4, i64 33
  %7 = call ptr @CopyMem(ptr noundef nonnull %2, ptr noundef nonnull %6, i64 noundef 16) #3
  %8 = getelementptr inbounds i8, ptr %4, i64 32
  %9 = load i8, ptr %8, align 8, !tbaa !5
  call void @Ip6GetPrefix(i8 noundef zeroext %9, ptr noundef nonnull %2)
  %10 = call i64 @CompareMem(ptr noundef nonnull %2, ptr noundef %1, i64 noundef 16) #3
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %.split.loop.exit14, label %.backedge.peel

.backedge.peel:                                   ; preds = %5, %.peel.begin
  %12 = call ptr @Ip6FindPrefixListEntry(ptr noundef %0, i8 noundef zeroext 1, i8 noundef zeroext -1, ptr noundef %1) #3
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %.split.loop.exit14, label %.split.loop.exit.loopexit

.split.loop.exit.loopexit:                        ; preds = %.backedge.peel
  %13 = getelementptr inbounds i8, ptr %12, i64 33
  %14 = call ptr @CopyMem(ptr noundef nonnull %2, ptr noundef nonnull %13, i64 noundef 16) #3
  %15 = getelementptr inbounds i8, ptr %12, i64 32
  %16 = load i8, ptr %15, align 8, !tbaa !5
  call void @Ip6GetPrefix(i8 noundef zeroext %16, ptr noundef nonnull %2)
  %17 = call i64 @CompareMem(ptr noundef nonnull %2, ptr noundef %1, i64 noundef 16) #3
  %18 = icmp eq i64 %17, 0
  %19 = zext i1 %18 to i8
  br label %.split.loop.exit14

.split.loop.exit14:                               ; preds = %.backedge.peel, %5, %.split.loop.exit.loopexit
  %.09 = phi i8 [ 1, %5 ], [ %19, %.split.loop.exit.loopexit ], [ 0, %.backedge.peel ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  ret i8 %.09
}

declare ptr @Ip6FindPrefixListEntry(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) local_unnamed_addr #1

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

attributes #0 = { mustprogress 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, !9, i64 32}
!6 = !{!"_IP6_PREFIX_LIST_ENTRY", !7, i64 0, !11, i64 16, !12, i64 24, !12, i64 28, !9, i64 32, !13, i64 33}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!"", !9, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopSimplifyPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass