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

; 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_DHCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_DHCP4_PACKET_OPTION = type { i8, i8, [1 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local i64 @IScsiDhcpExtractRootPath(ptr noundef, i8 noundef zeroext, ptr noundef) #0

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

declare ptr @AllocatePool(i64 noundef) #2

declare void @FreePool(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiDhcpSelectOffer(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %19 = load i32, ptr %11, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 2
  br i1 %20, label %21, label %25

21:                                               ; preds = %6
  %22 = load i32, ptr %11, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 3
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i64 0, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %99

25:                                               ; preds = %21, %6
  store i32 0, ptr %15, align 4, !tbaa !9
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._EFI_DHCP4_PROTOCOL, ptr %26, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = call i64 %28(ptr noundef %29, ptr noundef %30, ptr noundef %15, ptr noundef null)
  store i64 %31, ptr %14, align 8, !tbaa !13
  %32 = load i64, ptr %14, align 8, !tbaa !13
  %33 = icmp ne i64 %32, -9223372036854775803
  br i1 %33, label %34, label %35

34:                                               ; preds = %25
  store i64 -9223372036854775802, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %99

35:                                               ; preds = %25
  %36 = load i32, ptr %15, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = mul i64 %37, 8
  %39 = call ptr @AllocatePool(i64 noundef %38)
  store ptr %39, ptr %16, align 8, !tbaa !5
  %40 = load ptr, ptr %16, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  store i64 -9223372036854775802, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %99

43:                                               ; preds = %35
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._EFI_DHCP4_PROTOCOL, ptr %44, i32 0, i32 8
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = call i64 %46(ptr noundef %47, ptr noundef %48, ptr noundef %15, ptr noundef %49)
  store i64 %50, ptr %14, align 8, !tbaa !13
  %51 = load i64, ptr %14, align 8, !tbaa !13
  %52 = icmp slt i64 %51, 0
  br i1 %52, label %53, label %55

53:                                               ; preds = %43
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  call void @FreePool(ptr noundef %54)
  store i64 -9223372036854775802, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %99

55:                                               ; preds = %43
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %88, %55
  %57 = load i32, ptr %17, align 4, !tbaa !9
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = icmp ult i32 %57, %58
  br i1 %59, label %60, label %91

60:                                               ; preds = %56
  %61 = load ptr, ptr %16, align 8, !tbaa !5
  %62 = load i32, ptr %17, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds ptr, ptr %61, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.EFI_DHCP4_PACKET_OPTION, ptr %65, i32 0, i32 0
  %67 = load i8, ptr %66, align 1, !tbaa !15
  %68 = zext i8 %67 to i32
  %69 = icmp ne i32 %68, 17
  br i1 %69, label %70, label %71

70:                                               ; preds = %60
  br label %88

71:                                               ; preds = %60
  %72 = load ptr, ptr %16, align 8, !tbaa !5
  %73 = load i32, ptr %17, align 4, !tbaa !9
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds ptr, ptr %72, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.EFI_DHCP4_PACKET_OPTION, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds [1 x i8], ptr %77, i64 0, i64 0
  %79 = load ptr, ptr %16, align 8, !tbaa !5
  %80 = load i32, ptr %17, align 4, !tbaa !9
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.EFI_DHCP4_PACKET_OPTION, ptr %83, i32 0, i32 1
  %85 = load i8, ptr %84, align 1, !tbaa !17
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = call i64 @IScsiDhcpExtractRootPath(ptr noundef %78, i8 noundef zeroext %85, ptr noundef %86)
  store i64 %87, ptr %14, align 8, !tbaa !13
  br label %91

88:                                               ; preds = %70
  %89 = load i32, ptr %17, align 4, !tbaa !9
  %90 = add i32 %89, 1
  store i32 %90, ptr %17, align 4, !tbaa !9
  br label %56, !llvm.loop !18

91:                                               ; preds = %71, %56
  %92 = load i32, ptr %17, align 4, !tbaa !9
  %93 = load i32, ptr %15, align 4, !tbaa !9
  %94 = icmp eq i32 %92, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %91
  store i64 -9223372036854775802, ptr %14, align 8, !tbaa !13
  br label %96

96:                                               ; preds = %95, %91
  %97 = load ptr, ptr %16, align 8, !tbaa !5
  call void @FreePool(ptr noundef %97)
  %98 = load i64, ptr %14, align 8, !tbaa !13
  store i64 %98, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %99

99:                                               ; preds = %96, %53, %42, %34, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %100 = load i64, ptr %7, align 8
  ret i64 %100
}

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 = { "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, !6, i64 64}
!12 = !{!"_EFI_DHCP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!17 = !{!16, !7, i64 1}
!18 = distinct !{!18, !19}
!19 = !{!"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: nounwind uwtable
declare dso_local i64 @IScsiDhcpExtractRootPath(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #0

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

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiDhcpSelectOffer(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr nocapture noundef readnone %5) local_unnamed_addr #0 {
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %8 = add i32 %3, -4
  %or.cond = icmp ult i32 %8, -2
  br i1 %or.cond, label %36, label %9

9:                                                ; preds = %6
  store i32 0, ptr %7, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = call i64 %11(ptr noundef %0, ptr noundef %4, ptr noundef nonnull %7, ptr noundef null) #3
  %.not = icmp eq i64 %12, -9223372036854775803
  br i1 %.not, label %13, label %36

13:                                               ; preds = %9
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = shl nuw nsw i64 %15, 3
  %17 = call ptr @AllocatePool(i64 noundef %16) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %36, label %19

19:                                               ; preds = %13
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  %21 = call i64 %20(ptr noundef nonnull %0, ptr noundef %4, ptr noundef nonnull %7, ptr noundef nonnull %17) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %.sink.split, label %.preheader

.preheader:                                       ; preds = %19
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %.not34 = icmp eq i32 %23, 0
  br i1 %.not34, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext i32 %23 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %33 ]
  %24 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %.not30 = icmp eq i8 %26, 17
  br i1 %.not30, label %27, label %33

27:                                               ; preds = %.lr.ph
  %28 = trunc nuw i64 %indvars.iv to i32
  %29 = getelementptr inbounds i8, ptr %25, i64 2
  %30 = getelementptr inbounds i8, ptr %25, i64 1
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = call i64 @IScsiDhcpExtractRootPath(ptr noundef nonnull %29, i8 noundef zeroext %31, ptr noundef %1)
  %.pre = load i32, ptr %7, align 4, !tbaa !5
  br label %.loopexit

33:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !16

.loopexit:                                        ; preds = %33, %.preheader, %27
  %34 = phi i32 [ %.pre, %27 ], [ 0, %.preheader ], [ %23, %33 ]
  %.032 = phi i32 [ %28, %27 ], [ 0, %.preheader ], [ %23, %33 ]
  %.027 = phi i64 [ %32, %27 ], [ %21, %.preheader ], [ %21, %33 ]
  %35 = icmp eq i32 %.032, %34
  %spec.select = select i1 %35, i64 -9223372036854775802, i64 %.027
  br label %.sink.split

.sink.split:                                      ; preds = %19, %.loopexit
  %.026.ph = phi i64 [ %spec.select, %.loopexit ], [ -9223372036854775802, %19 ]
  call void @FreePool(ptr noundef nonnull %17) #3
  br label %36

36:                                               ; preds = %.sink.split, %13, %9, %6
  %.026 = phi i64 [ 0, %6 ], [ -9223372036854775802, %9 ], [ -9223372036854775802, %13 ], [ %.026.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  ret i64 %.026
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 64}
!10 = !{!"_EFI_DHCP4_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!14, !7, i64 1}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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