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

; 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.DHCP_OPTION_FORMAT = type { i8, i64, i64, i64, i8 }

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

; 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 @DhcpOptionIsValid(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !11
  switch i64 %14, label %19 [
    i64 1, label %15
    i64 2, label %15
    i64 3, label %16
    i64 4, label %17
    i64 5, label %17
    i64 6, label %18
  ]

15:                                               ; preds = %3, %3
  store i64 1, ptr %8, align 8, !tbaa !9
  br label %19

16:                                               ; preds = %3
  store i64 2, ptr %8, align 8, !tbaa !9
  br label %19

17:                                               ; preds = %3, %3
  store i64 4, ptr %8, align 8, !tbaa !9
  br label %19

18:                                               ; preds = %3
  store i64 8, ptr %8, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %18, %17, %16, %15, %3
  br label %20

20:                                               ; preds = %19
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @DebugAssert(ptr noundef @.str, i64 noundef 194, ptr noundef @.str.1)
  br label %27

27:                                               ; preds = %26, %23
  br label %28

28:                                               ; preds = %27, %20
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = srem i64 %31, %32
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %93

36:                                               ; preds = %30
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = sdiv i64 %37, %38
  store i64 %39, ptr %9, align 8, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %40, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !13
  %43 = icmp ne i64 %42, -1
  br i1 %43, label %44, label %50

44:                                               ; preds = %36
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %46, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !13
  %49 = icmp slt i64 %45, %48
  br i1 %49, label %61, label %50

50:                                               ; preds = %44, %36
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %51, i32 0, i32 3
  %53 = load i64, ptr %52, align 8, !tbaa !14
  %54 = icmp ne i64 %53, -1
  br i1 %54, label %55, label %62

55:                                               ; preds = %50
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %57, i32 0, i32 3
  %59 = load i64, ptr %58, align 8, !tbaa !14
  %60 = icmp sgt i64 %56, %59
  br i1 %60, label %61, label %62

61:                                               ; preds = %55, %44
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %93

62:                                               ; preds = %55, %50
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %63, i32 0, i32 1
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = icmp eq i64 %65, 1
  br i1 %66, label %67, label %92

67:                                               ; preds = %62
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %88, %67
  %69 = load i64, ptr %10, align 8, !tbaa !9
  %70 = load i64, ptr %9, align 8, !tbaa !9
  %71 = icmp slt i64 %69, %70
  br i1 %71, label %72, label %91

72:                                               ; preds = %68
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load i64, ptr %10, align 8, !tbaa !9
  %75 = getelementptr inbounds i8, ptr %73, i64 %74
  %76 = load i8, ptr %75, align 1, !tbaa !15
  %77 = zext i8 %76 to i32
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %87

79:                                               ; preds = %72
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = load i64, ptr %10, align 8, !tbaa !9
  %82 = getelementptr inbounds i8, ptr %80, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !15
  %84 = zext i8 %83 to i32
  %85 = icmp ne i32 %84, 1
  br i1 %85, label %86, label %87

86:                                               ; preds = %79
  store i8 0, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %93

87:                                               ; preds = %79, %72
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %10, align 8, !tbaa !9
  %90 = add nsw i64 %89, 1
  store i64 %90, ptr %10, align 8, !tbaa !9
  br label %68, !llvm.loop !16

91:                                               ; preds = %68
  br label %92

92:                                               ; preds = %91, %62
  store i8 1, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %93

93:                                               ; preds = %92, %86, %61, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %94 = load i8, ptr %4, align 1
  ret i8 %94
}

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

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 = { "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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !7, i64 32}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !10, i64 24}
!15 = !{!7, !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"

@.str = external hidden unnamed_addr constant [155 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@switch.table.DhcpOptionIsValid = private unnamed_addr constant [6 x i64] [i64 1, i64 1, i64 2, i64 4, i64 4, i64 8], align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @DhcpOptionIsValid(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %switch.tableidx = add i64 %5, -1
  %6 = icmp ult i64 %switch.tableidx, 6
  br i1 %6, label %switch.lookup, label %8

switch.lookup:                                    ; preds = %3
  %switch.gep = getelementptr inbounds [6 x i64], ptr @switch.table.DhcpOptionIsValid, i64 0, i64 %switch.tableidx
  %switch.load = load i64, ptr %switch.gep, align 8
  %7 = tail call zeroext i8 @DebugAssertEnabled() #2
  br label %12

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

11:                                               ; preds = %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 194, ptr noundef nonnull @.str.1) #2
  br label %12

12:                                               ; preds = %switch.lookup, %11, %8
  %.02234 = phi i64 [ %switch.load, %switch.lookup ], [ 0, %11 ], [ 0, %8 ]
  %13 = add nsw i64 %.02234, -1
  %14 = and i64 %13, %2
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %15, label %.loopexit

15:                                               ; preds = %12
  %16 = sdiv i64 %2, %.02234
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !10
  %.not26 = icmp ne i64 %18, -1
  %19 = icmp slt i64 %16, %18
  %or.cond30 = and i1 %.not26, %19
  br i1 %or.cond30, label %.loopexit, label %20

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %.not27 = icmp ne i64 %22, -1
  %23 = icmp sgt i64 %16, %22
  %or.cond31 = and i1 %.not27, %23
  br i1 %or.cond31, label %.loopexit, label %24

24:                                               ; preds = %20
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = icmp eq i64 %25, 1
  %27 = icmp sgt i64 %16, 0
  %or.cond = and i1 %26, %27
  br i1 %or.cond, label %.lr.ph, label %.loopexit

28:                                               ; preds = %.lr.ph
  %29 = add nuw nsw i64 %.035, 1
  %exitcond.not = icmp eq i64 %29, %16
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !12

.lr.ph:                                           ; preds = %24, %28
  %.035 = phi i64 [ %29, %28 ], [ 0, %24 ]
  %30 = getelementptr inbounds i8, ptr %1, i64 %.035
  %31 = load i8, ptr %30, align 1, !tbaa !14
  %switch = icmp ult i8 %31, 2
  br i1 %switch, label %28, label %.loopexit

.loopexit:                                        ; preds = %28, %.lr.ph, %24, %15, %20, %12
  %.021 = phi i8 [ 0, %12 ], [ 0, %20 ], [ 0, %15 ], [ 1, %24 ], [ 1, %28 ], [ 0, %.lr.ph ]
  ret i8 %.021
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 }

!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 8}
!6 = !{!"", !7, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !7, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long long", !7, i64 0}
!10 = !{!6, !9, i64 16}
!11 = !{!6, !9, i64 24}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass