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

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

@DhcpOptionFormats = external dso_local global [75 x %struct.DHCP_OPTION_FORMAT], align 16

; Function Attrs: nounwind uwtable
define dso_local ptr @DhcpFindOptionFormat(i8 noundef zeroext %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i8 %0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %4, align 8, !tbaa !8
  store i64 74, ptr %5, align 8, !tbaa !8
  br label %8

8:                                                ; preds = %43, %1
  %9 = load i64, ptr %5, align 8, !tbaa !8
  %10 = load i64, ptr %4, align 8, !tbaa !8
  %11 = icmp sge i64 %9, %10
  br i1 %11, label %12, label %44

12:                                               ; preds = %8
  %13 = load i64, ptr %4, align 8, !tbaa !8
  %14 = load i64, ptr %5, align 8, !tbaa !8
  %15 = add nsw i64 %13, %14
  %16 = sdiv i64 %15, 2
  store i64 %16, ptr %6, align 8, !tbaa !8
  %17 = load i8, ptr %3, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = load i64, ptr %6, align 8, !tbaa !8
  %20 = getelementptr inbounds [75 x %struct.DHCP_OPTION_FORMAT], ptr @DhcpOptionFormats, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 8, !tbaa !10
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %18, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %12
  %26 = load i64, ptr %6, align 8, !tbaa !8
  %27 = getelementptr inbounds [75 x %struct.DHCP_OPTION_FORMAT], ptr @DhcpOptionFormats, i64 0, i64 %26
  store ptr %27, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %45

28:                                               ; preds = %12
  %29 = load i8, ptr %3, align 1, !tbaa !5
  %30 = zext i8 %29 to i32
  %31 = load i64, ptr %6, align 8, !tbaa !8
  %32 = getelementptr inbounds [75 x %struct.DHCP_OPTION_FORMAT], ptr @DhcpOptionFormats, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.DHCP_OPTION_FORMAT, ptr %32, i32 0, i32 0
  %34 = load i8, ptr %33, align 8, !tbaa !10
  %35 = zext i8 %34 to i32
  %36 = icmp slt i32 %30, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %28
  %38 = load i64, ptr %6, align 8, !tbaa !8
  %39 = sub nsw i64 %38, 1
  store i64 %39, ptr %5, align 8, !tbaa !8
  br label %43

40:                                               ; preds = %28
  %41 = load i64, ptr %6, align 8, !tbaa !8
  %42 = add nsw i64 %41, 1
  store i64 %42, ptr %4, align 8, !tbaa !8
  br label %43

43:                                               ; preds = %40, %37
  br label %8, !llvm.loop !12

44:                                               ; preds = %8
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %45

45:                                               ; preds = %44, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %46 = load ptr, ptr %2, align 8
  ret ptr %46
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"", !6, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !6, i64 32}
!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"

%struct.DHCP_OPTION_FORMAT = type { i8, i64, i64, i64, i8 }

@DhcpOptionFormats = external dso_local global [75 x %struct.DHCP_OPTION_FORMAT], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef ptr @DhcpFindOptionFormat(i8 noundef zeroext %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %1, %8
  %.01117 = phi i64 [ 74, %1 ], [ %.1, %8 ]
  %.01216 = phi i64 [ 0, %1 ], [ %.113, %8 ]
  %3 = add nsw i64 %.01117, %.01216
  %4 = sdiv i64 %3, 2
  %5 = getelementptr inbounds [75 x %struct.DHCP_OPTION_FORMAT], ptr @DhcpOptionFormats, i64 0, i64 %4
  %6 = load i8, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i8 %6, %0
  br i1 %7, label %12, label %8

8:                                                ; preds = %2
  %9 = icmp ugt i8 %6, %0
  %10 = add nsw i64 %4, -1
  %11 = add nsw i64 %4, 1
  %.113 = select i1 %9, i64 %.01216, i64 %11
  %.1 = select i1 %9, i64 %10, i64 %.01117
  %.not = icmp slt i64 %.1, %.113
  br i1 %.not, label %12, label %2, !llvm.loop !10

12:                                               ; preds = %8, %2
  %.0 = phi ptr [ %5, %2 ], [ null, %8 ]
  ret ptr %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) 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, !7, i64 0}
!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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass