; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library (NetIp6IsValidUnicast)

; 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] }

; 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
define dso_local zeroext i8 @NetIp6IsValidUnicast(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 255
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store i8 0, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %49

14:                                               ; preds = %1
  store i8 0, ptr %5, align 1, !tbaa !9
  br label %15

15:                                               ; preds = %30, %14
  %16 = load i8, ptr %5, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp slt i32 %17, 15
  br i1 %18, label %19, label %33

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %5, align 1, !tbaa !9
  %23 = zext i8 %22 to i64
  %24 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store i8 1, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %49

29:                                               ; preds = %19
  br label %30

30:                                               ; preds = %29
  %31 = load i8, ptr %5, align 1, !tbaa !9
  %32 = add i8 %31, 1
  store i8 %32, ptr %5, align 1, !tbaa !9
  br label %15, !llvm.loop !10

33:                                               ; preds = %15
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %5, align 1, !tbaa !9
  %37 = zext i8 %36 to i64
  %38 = getelementptr inbounds [16 x i8], ptr %35, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !9
  store i8 %39, ptr %4, align 1, !tbaa !9
  %40 = load i8, ptr %4, align 1, !tbaa !9
  %41 = zext i8 %40 to i32
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %47, label %43

43:                                               ; preds = %33
  %44 = load i8, ptr %4, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %47, label %48

47:                                               ; preds = %43, %33
  store i8 0, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %49

48:                                               ; preds = %43
  store i8 1, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %49

49:                                               ; preds = %48, %47, %28, %13
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %50 = load i8, ptr %2, align 1
  ret i8 %50
}

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 = { 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 = distinct !{!10, !11}
!11 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local zeroext range(i8 0, 2) i8 @NetIp6IsValidUnicast(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  switch i8 %2, label %.loopexit.fold.split [
    i8 -1, label %.loopexit
    i8 0, label %.preheader.1
  ]

.preheader.1:                                     ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 1
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %.not.1 = icmp eq i8 %4, 0
  br i1 %.not.1, label %.preheader.2, label %.loopexit

.preheader.2:                                     ; preds = %.preheader.1
  %5 = getelementptr inbounds i8, ptr %0, i64 2
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not.2 = icmp eq i8 %6, 0
  br i1 %.not.2, label %.preheader.3, label %.loopexit

.preheader.3:                                     ; preds = %.preheader.2
  %7 = getelementptr inbounds i8, ptr %0, i64 3
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %.not.3 = icmp eq i8 %8, 0
  br i1 %.not.3, label %.preheader.4, label %.loopexit

.preheader.4:                                     ; preds = %.preheader.3
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not.4 = icmp eq i8 %10, 0
  br i1 %.not.4, label %.preheader.5, label %.loopexit

.preheader.5:                                     ; preds = %.preheader.4
  %11 = getelementptr inbounds i8, ptr %0, i64 5
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not.5 = icmp eq i8 %12, 0
  br i1 %.not.5, label %.preheader.6, label %.loopexit

.preheader.6:                                     ; preds = %.preheader.5
  %13 = getelementptr inbounds i8, ptr %0, i64 6
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %.not.6 = icmp eq i8 %14, 0
  br i1 %.not.6, label %.preheader.7, label %.loopexit

.preheader.7:                                     ; preds = %.preheader.6
  %15 = getelementptr inbounds i8, ptr %0, i64 7
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %.not.7 = icmp eq i8 %16, 0
  br i1 %.not.7, label %.preheader.8, label %.loopexit

.preheader.8:                                     ; preds = %.preheader.7
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %.not.8 = icmp eq i8 %18, 0
  br i1 %.not.8, label %.preheader.9, label %.loopexit

.preheader.9:                                     ; preds = %.preheader.8
  %19 = getelementptr inbounds i8, ptr %0, i64 9
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %.not.9 = icmp eq i8 %20, 0
  br i1 %.not.9, label %.preheader.10, label %.loopexit

.preheader.10:                                    ; preds = %.preheader.9
  %21 = getelementptr inbounds i8, ptr %0, i64 10
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %.not.10 = icmp eq i8 %22, 0
  br i1 %.not.10, label %.preheader.11, label %.loopexit

.preheader.11:                                    ; preds = %.preheader.10
  %23 = getelementptr inbounds i8, ptr %0, i64 11
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %.not.11 = icmp eq i8 %24, 0
  br i1 %.not.11, label %.preheader.12, label %.loopexit

.preheader.12:                                    ; preds = %.preheader.11
  %25 = getelementptr inbounds i8, ptr %0, i64 12
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %.not.12 = icmp eq i8 %26, 0
  br i1 %.not.12, label %.preheader.13, label %.loopexit

.preheader.13:                                    ; preds = %.preheader.12
  %27 = getelementptr inbounds i8, ptr %0, i64 13
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %.not.13 = icmp eq i8 %28, 0
  br i1 %.not.13, label %.preheader.14, label %.loopexit

.preheader.14:                                    ; preds = %.preheader.13
  %29 = getelementptr inbounds i8, ptr %0, i64 14
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %.not.14 = icmp eq i8 %30, 0
  br i1 %.not.14, label %31, label %.loopexit

31:                                               ; preds = %.preheader.14
  %32 = getelementptr inbounds i8, ptr %0, i64 15
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %or.cond = icmp ugt i8 %33, 1
  %. = zext i1 %or.cond to i8
  br label %.loopexit

.loopexit.fold.split:                             ; preds = %1
  br label %.loopexit

.loopexit:                                        ; preds = %1, %.loopexit.fold.split, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %.preheader.8, %.preheader.9, %.preheader.10, %.preheader.11, %.preheader.12, %.preheader.13, %.preheader.14, %31
  %.011 = phi i8 [ 0, %1 ], [ %., %31 ], [ 1, %.preheader.14 ], [ 1, %.preheader.13 ], [ 1, %.preheader.12 ], [ 1, %.preheader.11 ], [ 1, %.preheader.10 ], [ 1, %.preheader.9 ], [ 1, %.preheader.8 ], [ 1, %.preheader.7 ], [ 1, %.preheader.6 ], [ 1, %.preheader.5 ], [ 1, %.preheader.4 ], [ 1, %.preheader.3 ], [ 1, %.preheader.2 ], [ 1, %.preheader.1 ], [ 1, %.loopexit.fold.split ]
  ret i8 %.011
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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