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

; 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_DHCP6_IA = type { %struct.EFI_DHCP6_IA_DESCRIPTOR, i32, ptr, i32, [1 x %struct.EFI_DHCP6_IA_ADDRESS] }
%struct.EFI_DHCP6_IA_DESCRIPTOR = type { i16, i32 }
%struct.EFI_DHCP6_IA_ADDRESS = type { %struct.EFI_IPv6_ADDRESS, i32, i32 }
%struct.EFI_IPv6_ADDRESS = type { [16 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
define dso_local i64 @Dhcp6CheckAddress(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  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 1, ptr %10) #3
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %45, %3
  %13 = load i64, ptr %8, align 8, !tbaa !11
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = icmp ult i64 %13, %15
  br i1 %16, label %17, label %48

17:                                               ; preds = %12
  store i8 0, ptr %10, align 1, !tbaa !13
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %37, %17
  %19 = load i64, ptr %9, align 8, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = zext i32 %22 to i64
  %24 = icmp ult i64 %19, %23
  br i1 %24, label %25, label %40

25:                                               ; preds = %18
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %8, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %26, i64 %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %29, i32 0, i32 4
  %31 = load i64, ptr %9, align 8, !tbaa !11
  %32 = getelementptr inbounds [1 x %struct.EFI_DHCP6_IA_ADDRESS], ptr %30, i64 0, i64 %31
  %33 = call i64 @CompareMem(ptr noundef %28, ptr noundef %32, i64 noundef 16)
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %25
  store i8 1, ptr %10, align 1, !tbaa !13
  br label %40

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = add i64 %38, 1
  store i64 %39, ptr %9, align 8, !tbaa !11
  br label %18, !llvm.loop !18

40:                                               ; preds = %35, %18
  %41 = load i8, ptr %10, align 1, !tbaa !13
  %42 = icmp ne i8 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i64 -9223372036854775794, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %49

44:                                               ; preds = %40
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = add i64 %46, 1
  store i64 %47, ptr %8, align 8, !tbaa !11
  br label %12, !llvm.loop !20

48:                                               ; preds = %12
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %49

49:                                               ; preds = %48, %43
  call void @llvm.lifetime.end.p0(i64 1, 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
  %50 = load i64, ptr %4, align 8
  ret i64 %50
}

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 24}
!15 = !{!"", !16, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !7, i64 28}
!16 = !{!"", !17, i64 0, !10, i64 4}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.EFI_DHCP6_IA_ADDRESS = type { %struct.EFI_IPv6_ADDRESS, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775794, 1) i64 @Dhcp6CheckAddress(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = zext i32 %1 to i64
  %.not18 = icmp eq i32 %1, 0
  br i1 %.not18, label %.critedge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %17
  %.01217 = phi i64 [ 0, %.preheader.lr.ph ], [ %18, %17 ]
  %7 = load i32, ptr %5, align 8, !tbaa !5
  %.not15.not = icmp eq i32 %7, 0
  br i1 %.not15.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %2, i64 %.01217
  br label %13

9:                                                ; preds = %13
  %10 = add nuw nsw i64 %.01116, 1
  %11 = load i32, ptr %5, align 8, !tbaa !5
  %12 = zext i32 %11 to i64
  %.not = icmp ult i64 %10, %12
  br i1 %.not, label %13, label %.critedge, !llvm.loop !13

13:                                               ; preds = %.lr.ph, %9
  %.01116 = phi i64 [ 0, %.lr.ph ], [ %10, %9 ]
  %14 = getelementptr inbounds [1 x %struct.EFI_DHCP6_IA_ADDRESS], ptr %6, i64 0, i64 %.01116
  %15 = tail call i64 @CompareMem(ptr noundef %8, ptr noundef nonnull %14, i64 noundef 16) #2
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %9

17:                                               ; preds = %13
  %18 = add nuw nsw i64 %.01217, 1
  %exitcond.not = icmp eq i64 %18, %4
  br i1 %exitcond.not, label %.critedge, label %.preheader, !llvm.loop !15

.critedge:                                        ; preds = %17, %.preheader, %9, %3
  %.013 = phi i64 [ 0, %3 ], [ -9223372036854775794, %9 ], [ -9223372036854775794, %.preheader ], [ 0, %17 ]
  ret i64 %.013
}

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 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, !11, i64 24}
!6 = !{!"", !7, i64 0, !11, i64 8, !12, i64 16, !11, i64 24, !9, i64 28}
!7 = !{!"", !8, i64 0, !11, i64 4}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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