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

; 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_PACKET = type <{ i32, i32, %struct.anon }>
%struct.anon = type <{ %struct.EFI_DHCP4_HEADER, i32, [1 x i8] }>
%struct.EFI_DHCP4_HEADER = type { i8, i8, i8, i8, i32, i16, i16, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, [16 x i8], [64 x i8], [128 x i8] }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

; 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
declare dso_local i64 @DhcpIterateBufferOptions(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @DhcpIterateOptions(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  store i8 0, ptr %9, align 1, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %11, i32 0, i32 2
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 2
  %14 = getelementptr inbounds [1 x i8], ptr %13, i64 0, i64 0
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 1, !tbaa !10
  %18 = zext i32 %17 to i64
  %19 = sub i64 %18, 236
  %20 = sub i64 %19, 4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i64 @DhcpIterateBufferOptions(ptr noundef %14, i64 noundef %20, ptr noundef %21, ptr noundef %22, ptr noundef %9)
  store i64 %23, ptr %8, align 8, !tbaa !17
  %24 = load i64, ptr %8, align 8, !tbaa !17
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %3
  %27 = load i64, ptr %8, align 8, !tbaa !17
  store i64 %27, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %73

28:                                               ; preds = %3
  %29 = load i8, ptr %9, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %36, label %32

32:                                               ; preds = %28
  %33 = load i8, ptr %9, align 1, !tbaa !9
  %34 = zext i8 %33 to i32
  %35 = icmp eq i32 %34, 3
  br i1 %35, label %36, label %50

36:                                               ; preds = %32, %28
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.EFI_DHCP4_HEADER, ptr %39, i32 0, i32 13
  %41 = getelementptr inbounds [128 x i8], ptr %40, i64 0, i64 0
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call i64 @DhcpIterateBufferOptions(ptr noundef %41, i64 noundef 128, ptr noundef %42, ptr noundef %43, ptr noundef null)
  store i64 %44, ptr %8, align 8, !tbaa !17
  %45 = load i64, ptr %8, align 8, !tbaa !17
  %46 = icmp slt i64 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %36
  %48 = load i64, ptr %8, align 8, !tbaa !17
  store i64 %48, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %73

49:                                               ; preds = %36
  br label %50

50:                                               ; preds = %49, %32
  %51 = load i8, ptr %9, align 1, !tbaa !9
  %52 = zext i8 %51 to i32
  %53 = icmp eq i32 %52, 2
  br i1 %53, label %58, label %54

54:                                               ; preds = %50
  %55 = load i8, ptr %9, align 1, !tbaa !9
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 3
  br i1 %57, label %58, label %72

58:                                               ; preds = %54, %50
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.EFI_DHCP4_PACKET, ptr %59, i32 0, i32 2
  %61 = getelementptr inbounds %struct.anon, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.EFI_DHCP4_HEADER, ptr %61, i32 0, i32 12
  %63 = getelementptr inbounds [64 x i8], ptr %62, i64 0, i64 0
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = call i64 @DhcpIterateBufferOptions(ptr noundef %63, i64 noundef 64, ptr noundef %64, ptr noundef %65, ptr noundef null)
  store i64 %66, ptr %8, align 8, !tbaa !17
  %67 = load i64, ptr %8, align 8, !tbaa !17
  %68 = icmp slt i64 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %58
  %70 = load i64, ptr %8, align 8, !tbaa !17
  store i64 %70, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %73

71:                                               ; preds = %58
  br label %72

72:                                               ; preds = %71, %54
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %73

73:                                               ; preds = %72, %69, %47, %26
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %74 = load i64, ptr %4, align 8
  ret i64 %74
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 4}
!11 = !{!"", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !14, i64 0, !12, i64 236, !7, i64 240}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !12, i64 4, !15, i64 8, !15, i64 10, !16, i64 12, !16, i64 16, !16, i64 20, !16, i64 24, !7, i64 28, !7, i64 44, !7, i64 108}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !7, i64 0}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @DhcpIterateBufferOptions(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @DhcpIterateOptions(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #2
  store i8 0, ptr %4, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 248
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 1, !tbaa !8
  %8 = zext i32 %7 to i64
  %9 = add nsw i64 %8, -240
  %10 = call i64 @DhcpIterateBufferOptions(ptr noundef nonnull %5, i64 noundef %9, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %4)
  %11 = icmp slt i64 %10, 0
  br i1 %11, label %27, label %12

12:                                               ; preds = %3
  %13 = load i8, ptr %4, align 1
  %14 = and i8 %13, -3
  %or.cond = icmp eq i8 %14, 1
  br i1 %or.cond, label %15, label %19

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 116
  %17 = call i64 @DhcpIterateBufferOptions(ptr noundef nonnull %16, i64 noundef 128, ptr noundef %1, ptr noundef %2, ptr noundef null)
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %27, label %._crit_edge

._crit_edge:                                      ; preds = %15
  %.pre = load i8, ptr %4, align 1
  br label %19

19:                                               ; preds = %._crit_edge, %12
  %20 = phi i8 [ %.pre, %._crit_edge ], [ %13, %12 ]
  %21 = and i8 %20, -2
  %or.cond5 = icmp eq i8 %21, 2
  br i1 %or.cond5, label %22, label %26

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %0, i64 52
  %24 = call i64 @DhcpIterateBufferOptions(ptr noundef nonnull %23, i64 noundef 64, ptr noundef %1, ptr noundef %2, ptr noundef null)
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %22, %19
  br label %27

27:                                               ; preds = %22, %15, %3, %26
  %.0 = phi i64 [ 0, %26 ], [ %10, %3 ], [ %17, %15 ], [ %24, %22 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #2
  ret i64 %.0
}

attributes #0 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 4}
!9 = !{!"", !10, i64 0, !10, i64 4, !11, i64 8}
!10 = !{!"int", !6, i64 0}
!11 = !{!"", !12, i64 0, !10, i64 236, !6, i64 240}
!12 = !{!"", !6, i64 0, !6, i64 1, !6, i64 2, !6, i64 3, !10, i64 4, !13, i64 8, !13, i64 10, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !6, i64 28, !6, i64 44, !6, i64 108}
!13 = !{!"short", !6, i64 0}
!14 = !{!"", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass