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

; 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"

; 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 @Ip6IsNDOptionValid(ptr noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i8, align 1
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  store i16 0, ptr %6, align 2, !tbaa !9
  br label %10

10:                                               ; preds = %53, %2
  %11 = load i16, ptr %6, align 2, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = load i16, ptr %5, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %16, label %60

16:                                               ; preds = %10
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i16, ptr %6, align 2, !tbaa !9
  %19 = zext i16 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %17, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  store i8 %22, ptr %7, align 1, !tbaa !11
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i16, ptr %6, align 2, !tbaa !9
  %25 = zext i16 %24 to i32
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %23, i64 %26
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = mul nsw i32 %30, 8
  %32 = trunc i32 %31 to i16
  store i16 %32, ptr %8, align 2, !tbaa !9
  %33 = load i8, ptr %7, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  switch i32 %34, label %47 [
    i32 3, label %35
    i32 5, label %41
  ]

35:                                               ; preds = %16
  %36 = load i16, ptr %8, align 2, !tbaa !9
  %37 = zext i16 %36 to i32
  %38 = icmp ne i32 %37, 32
  br i1 %38, label %39, label %40

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

40:                                               ; preds = %35
  br label %53

41:                                               ; preds = %16
  %42 = load i16, ptr %8, align 2, !tbaa !9
  %43 = zext i16 %42 to i32
  %44 = icmp ne i32 %43, 8
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %61

46:                                               ; preds = %41
  br label %53

47:                                               ; preds = %16
  %48 = load i16, ptr %8, align 2, !tbaa !9
  %49 = zext i16 %48 to i32
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %47
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %61

52:                                               ; preds = %47
  br label %53

53:                                               ; preds = %52, %46, %40
  %54 = load i16, ptr %6, align 2, !tbaa !9
  %55 = zext i16 %54 to i32
  %56 = load i16, ptr %8, align 2, !tbaa !9
  %57 = zext i16 %56 to i32
  %58 = add nsw i32 %55, %57
  %59 = trunc i32 %58 to i16
  store i16 %59, ptr %6, align 2, !tbaa !9
  br label %10, !llvm.loop !12

60:                                               ; preds = %10
  store i8 1, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %61

61:                                               ; preds = %60, %51, %45, %39
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  %62 = load i8, ptr %3, align 1
  ret i8 %62
}

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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local zeroext range(i8 0, 2) i8 @Ip6IsNDOptionValid(ptr nocapture noundef readonly %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i16 %1 to i32
  %.not21 = icmp eq i16 %1, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %16
  %4 = phi i32 [ %18, %16 ], [ 0, %2 ]
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = shl nuw nsw i32 %10, 3
  switch i8 %7, label %14 [
    i8 3, label %12
    i8 5, label %13
  ]

12:                                               ; preds = %.lr.ph
  %.not14 = icmp eq i8 %9, 4
  br i1 %.not14, label %16, label %._crit_edge

13:                                               ; preds = %.lr.ph
  %.not = icmp eq i8 %9, 1
  br i1 %.not, label %16, label %._crit_edge

14:                                               ; preds = %.lr.ph
  %15 = icmp eq i8 %9, 0
  br i1 %15, label %._crit_edge, label %16

16:                                               ; preds = %14, %13, %12
  %17 = add nuw nsw i32 %11, %4
  %18 = and i32 %17, 65535
  %19 = icmp ult i32 %18, %3
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %12, %13, %14, %16, %2
  %.0 = phi i8 [ 1, %2 ], [ 1, %16 ], [ 0, %14 ], [ 0, %13 ], [ 0, %12 ]
  ret i8 %.0
}

attributes #0 = { nofree norecurse nosync nounwind 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass