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

; 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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #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
define dso_local ptr @Dhcp6SeekOption(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i16 %2, ptr %6, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %7, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %30, %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = icmp ult ptr %13, %17
  br i1 %18, label %19, label %41

19:                                               ; preds = %12
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call zeroext i16 @ReadUnaligned16(ptr noundef %20)
  store i16 %21, ptr %10, align 2, !tbaa !11
  %22 = load i16, ptr %10, align 2, !tbaa !11
  %23 = zext i16 %22 to i32
  %24 = load i16, ptr %6, align 2, !tbaa !11
  %25 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %24)
  %26 = zext i16 %25 to i32
  %27 = icmp eq i32 %23, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %19
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %29, ptr %8, align 8, !tbaa !5
  br label %41

30:                                               ; preds = %19
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 2
  %33 = call zeroext i16 @ReadUnaligned16(ptr noundef %32)
  %34 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %33)
  store i16 %34, ptr %9, align 2, !tbaa !11
  %35 = load i16, ptr %9, align 2, !tbaa !11
  %36 = zext i16 %35 to i32
  %37 = add nsw i32 %36, 4
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = sext i32 %37 to i64
  %40 = getelementptr inbounds i8, ptr %38, i64 %39
  store ptr %40, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !13

41:                                               ; preds = %28, %12
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %42
}

declare zeroext i16 @ReadUnaligned16(ptr 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @Dhcp6SeekOption(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = zext i32 %1 to i64
  %5 = getelementptr inbounds i8, ptr %0, i64 %4
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %9
  %.012 = phi ptr [ %15, %9 ], [ %0, %3 ]
  %6 = tail call zeroext i16 @ReadUnaligned16(ptr noundef %.012) #2
  %7 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %2) #2
  %8 = icmp eq i16 %6, %7
  br i1 %8, label %._crit_edge, label %9

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.012, i64 2
  %11 = tail call zeroext i16 @ReadUnaligned16(ptr noundef nonnull %10) #2
  %12 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %11) #2
  %13 = zext i16 %12 to i64
  %14 = add nuw nsw i64 %13, 4
  %15 = getelementptr inbounds i8, ptr %.012, i64 %14
  %16 = icmp ult ptr %15, %5
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %9, %.lr.ph, %3
  %.011 = phi ptr [ null, %3 ], [ %.012, %.lr.ph ], [ null, %9 ]
  ret ptr %.011
}

declare zeroext i16 @ReadUnaligned16(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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