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

; 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_CONFIG_DATA = type { ptr, ptr, i32, ptr, %struct.EFI_DHCP6_IA_DESCRIPTOR, ptr, i8, i8, ptr }
%struct.EFI_DHCP6_IA_DESCRIPTOR = type { i16, i32 }
%struct.EFI_DHCP6_PACKET_OPTION = type <{ i16, i16, [1 x i8] }>

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

declare ptr @AllocateZeroPool(i64 noundef) #1

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #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 i64 @Dhcp6CopyConfigData(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call ptr @CopyMem(ptr noundef %10, ptr noundef %11, i64 noundef 64)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %13, i32 0, i32 8
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %34

17:                                               ; preds = %2
  %18 = call ptr @AllocateZeroPool(i64 noundef 16)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %19, i32 0, i32 8
  store ptr %18, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %21, i32 0, i32 8
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %17
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %115

26:                                               ; preds = %17
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %27, i32 0, i32 8
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = call ptr @CopyMem(ptr noundef %29, ptr noundef %32, i64 noundef 16)
  br label %34

34:                                               ; preds = %26, %2
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %35, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %114

39:                                               ; preds = %34
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %114

44:                                               ; preds = %39
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !15
  %48 = zext i32 %47 to i64
  %49 = mul i64 %48, 8
  store i64 %49, ptr %7, align 8, !tbaa !16
  %50 = load i64, ptr %7, align 8, !tbaa !16
  %51 = call ptr @AllocateZeroPool(i64 noundef %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %52, i32 0, i32 3
  store ptr %51, ptr %53, align 8, !tbaa !14
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  %57 = icmp eq ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %44
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %115

59:                                               ; preds = %44
  store i64 0, ptr %6, align 8, !tbaa !16
  br label %60

60:                                               ; preds = %110, %59
  %61 = load i64, ptr %6, align 8, !tbaa !16
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 8, !tbaa !15
  %65 = zext i32 %64 to i64
  %66 = icmp ult i64 %61, %65
  br i1 %66, label %67, label %113

67:                                               ; preds = %60
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !14
  %71 = load i64, ptr %6, align 8, !tbaa !16
  %72 = getelementptr inbounds ptr, ptr %70, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.EFI_DHCP6_PACKET_OPTION, ptr %73, i32 0, i32 1
  %75 = load i16, ptr %74, align 1, !tbaa !18
  %76 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %75)
  %77 = zext i16 %76 to i32
  %78 = add nsw i32 %77, 4
  %79 = sext i32 %78 to i64
  store i64 %79, ptr %8, align 8, !tbaa !16
  %80 = load i64, ptr %8, align 8, !tbaa !16
  %81 = call ptr @AllocateZeroPool(i64 noundef %80)
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %82, i32 0, i32 3
  %84 = load ptr, ptr %83, align 8, !tbaa !14
  %85 = load i64, ptr %6, align 8, !tbaa !16
  %86 = getelementptr inbounds ptr, ptr %84, i64 %85
  store ptr %81, ptr %86, align 8, !tbaa !5
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %87, i32 0, i32 3
  %89 = load ptr, ptr %88, align 8, !tbaa !14
  %90 = load i64, ptr %6, align 8, !tbaa !16
  %91 = getelementptr inbounds ptr, ptr %89, i64 %90
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  %93 = icmp eq ptr %92, null
  br i1 %93, label %94, label %95

94:                                               ; preds = %67
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %115

95:                                               ; preds = %67
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %96, i32 0, i32 3
  %98 = load ptr, ptr %97, align 8, !tbaa !14
  %99 = load i64, ptr %6, align 8, !tbaa !16
  %100 = getelementptr inbounds ptr, ptr %98, i64 %99
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %102, i32 0, i32 3
  %104 = load ptr, ptr %103, align 8, !tbaa !14
  %105 = load i64, ptr %6, align 8, !tbaa !16
  %106 = getelementptr inbounds ptr, ptr %104, i64 %105
  %107 = load ptr, ptr %106, align 8, !tbaa !5
  %108 = load i64, ptr %8, align 8, !tbaa !16
  %109 = call ptr @CopyMem(ptr noundef %101, ptr noundef %107, i64 noundef %108)
  br label %110

110:                                              ; preds = %95
  %111 = load i64, ptr %6, align 8, !tbaa !16
  %112 = add i64 %111, 1
  store i64 %112, ptr %6, align 8, !tbaa !16
  br label %60, !llvm.loop !20

113:                                              ; preds = %60
  br label %114

114:                                              ; preds = %113, %39, %34
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %115

115:                                              ; preds = %114, %94, %58, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %116 = load i64, ptr %3, align 8
  ret i64 %116
}

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, !6, i64 56}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !6, i64 40, !7, i64 48, !7, i64 49, !6, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0, !11, i64 4}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !11, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!19, !13, i64 2}
!19 = !{!"", !13, i64 0, !13, i64 2, !7, i64 4}
!20 = distinct !{!20, !21}
!21 = !{!"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 ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #0

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @Dhcp6CopyConfigData(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @CopyMem(ptr noundef %0, ptr noundef %1, i64 noundef 64) #2
  %4 = getelementptr inbounds i8, ptr %1, i64 56
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %13, label %6

6:                                                ; preds = %2
  %7 = tail call ptr @AllocateZeroPool(i64 noundef 16) #2
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %7, ptr %8, align 8, !tbaa !5
  %9 = icmp eq ptr %7, null
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %6
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = tail call ptr @CopyMem(ptr noundef nonnull %7, ptr noundef %11, i64 noundef 16) #2
  br label %13

13:                                               ; preds = %10, %2
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %.not32 = icmp eq ptr %15, null
  br i1 %.not32, label %.loopexit, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %.not33 = icmp eq i32 %18, 0
  br i1 %.not33, label %.loopexit, label %19

19:                                               ; preds = %16
  %20 = zext i32 %18 to i64
  %21 = shl nuw nsw i64 %20, 3
  %22 = tail call ptr @AllocateZeroPool(i64 noundef %21) #2
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %22, ptr %23, align 8, !tbaa !13
  %24 = icmp eq ptr %22, null
  br i1 %24, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %19
  %25 = load i32, ptr %17, align 8, !tbaa !14
  %.not37 = icmp eq i32 %25, 0
  br i1 %.not37, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %41
  %.02834 = phi i64 [ %46, %41 ], [ 0, %.preheader ]
  %26 = load ptr, ptr %14, align 8, !tbaa !13
  %27 = getelementptr inbounds ptr, ptr %26, i64 %.02834
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds i8, ptr %28, i64 2
  %30 = load i16, ptr %29, align 1, !tbaa !16
  %31 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %30) #2
  %32 = zext i16 %31 to i64
  %33 = add nuw nsw i64 %32, 4
  %34 = tail call ptr @AllocateZeroPool(i64 noundef %33) #2
  %35 = load ptr, ptr %23, align 8, !tbaa !13
  %36 = getelementptr inbounds ptr, ptr %35, i64 %.02834
  store ptr %34, ptr %36, align 8, !tbaa !15
  %37 = load ptr, ptr %23, align 8, !tbaa !13
  %38 = getelementptr inbounds ptr, ptr %37, i64 %.02834
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp eq ptr %39, null
  br i1 %40, label %.loopexit, label %41

41:                                               ; preds = %.lr.ph
  %42 = load ptr, ptr %14, align 8, !tbaa !13
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.02834
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = tail call ptr @CopyMem(ptr noundef nonnull %39, ptr noundef %44, i64 noundef %33) #2
  %46 = add nuw nsw i64 %.02834, 1
  %47 = load i32, ptr %17, align 8, !tbaa !14
  %48 = zext i32 %47 to i64
  %49 = icmp ult i64 %46, %48
  br i1 %49, label %.lr.ph, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %.lr.ph, %41, %.preheader, %13, %16, %19, %6
  %.0 = phi i64 [ -9223372036854775799, %6 ], [ -9223372036854775799, %19 ], [ 0, %16 ], [ 0, %13 ], [ 0, %.preheader ], [ -9223372036854775799, %.lr.ph ], [ 0, %41 ]
  ret i64 %.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 = !{!6, !7, i64 56}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !7, i64 40, !8, i64 48, !8, i64 49, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !12, i64 0, !10, i64 4}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !7, i64 24}
!14 = !{!6, !10, i64 16}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !12, i64 2}
!17 = !{!"", !12, i64 0, !12, i64 2, !8, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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