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

; 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._DHCP6_INSTANCE = type { i32, ptr, ptr, %struct._LIST_ENTRY, %struct._EFI_DHCP6_PROTOCOL, ptr, ptr, ptr, %struct._DHCP6_IA_CB, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, i8, ptr, i64, i8, i8, i64 }
%struct._EFI_DHCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._DHCP6_IA_CB = type { ptr, i32, i32, i32, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%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] }
%struct.EFI_DHCP6_CONFIG_DATA = type { ptr, ptr, i32, ptr, %struct.EFI_DHCP6_IA_DESCRIPTOR, ptr, i8, i8, ptr }

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

declare void @FreePool(ptr noundef) #1

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

declare ptr @ZeroMem(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @Dhcp6CalculateLeaseTime(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @Dhcp6ParseAddrOption(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Dhcp6GenerateIaCb(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i16 %2, ptr %9, align 2, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !11
  store i32 %4, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %16, i32 0, i32 8
  %18 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %5
  store i64 -9223372036854775801, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %109

22:                                               ; preds = %5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %23, i32 0, i32 8
  %25 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i16, ptr %9, align 2, !tbaa !9
  call void @Dhcp6ParseAddrOption(ptr noundef %26, ptr noundef %27, i16 noundef zeroext %28, ptr noundef %12, ptr noundef null)
  %29 = load i32, ptr %12, align 4, !tbaa !11
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %22
  store i64 -9223372036854775794, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %109

32:                                               ; preds = %22
  %33 = load i32, ptr %12, align 4, !tbaa !11
  %34 = sub i32 %33, 1
  %35 = zext i32 %34 to i64
  %36 = mul i64 %35, 24
  %37 = add i64 56, %36
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %13, align 4, !tbaa !11
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = zext i32 %39 to i64
  %41 = call ptr @AllocateZeroPool(i64 noundef %40)
  store ptr %41, ptr %14, align 8, !tbaa !5
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %45

44:                                               ; preds = %32
  store i64 -9223372036854775799, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %109

45:                                               ; preds = %32
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %46, i32 0, i32 8
  %48 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %52, i32 0, i32 1
  store i32 %51, ptr %53, align 8, !tbaa !19
  %54 = load i32, ptr %12, align 4, !tbaa !11
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %55, i32 0, i32 3
  store i32 %54, ptr %56, align 8, !tbaa !22
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %59, i32 0, i32 6
  %61 = load ptr, ptr %60, align 8, !tbaa !23
  %62 = getelementptr inbounds %struct.EFI_DHCP6_CONFIG_DATA, ptr %61, i32 0, i32 4
  %63 = call ptr @CopyMem(ptr noundef %58, ptr noundef %62, i64 noundef 8)
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %64, i32 0, i32 8
  %66 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load i16, ptr %9, align 2, !tbaa !9
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %70, i32 0, i32 4
  %72 = getelementptr inbounds [1 x %struct.EFI_DHCP6_IA_ADDRESS], ptr %71, i64 0, i64 0
  call void @Dhcp6ParseAddrOption(ptr noundef %67, ptr noundef %68, i16 noundef zeroext %69, ptr noundef %12, ptr noundef %72)
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %73, i32 0, i32 8
  %75 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !13
  %77 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !24
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %87

80:                                               ; preds = %45
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %81, i32 0, i32 8
  %83 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !13
  %85 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !24
  call void @FreePool(ptr noundef %86)
  br label %87

87:                                               ; preds = %80, %45
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %88, i32 0, i32 8
  %90 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  call void @FreePool(ptr noundef %91)
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %92, i32 0, i32 8
  %94 = call ptr @ZeroMem(ptr noundef %93, i64 noundef 24)
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %96, i32 0, i32 8
  %98 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %97, i32 0, i32 0
  store ptr %95, ptr %98, align 8, !tbaa !13
  %99 = load i32, ptr %10, align 4, !tbaa !11
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %100, i32 0, i32 8
  %102 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %101, i32 0, i32 1
  store i32 %99, ptr %102, align 8, !tbaa !25
  %103 = load i32, ptr %11, align 4, !tbaa !11
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %104, i32 0, i32 8
  %106 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %105, i32 0, i32 2
  store i32 %103, ptr %106, align 4, !tbaa !26
  %107 = load ptr, ptr %7, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %107, i32 0, i32 8
  call void @Dhcp6CalculateLeaseTime(ptr noundef %108)
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %109

109:                                              ; preds = %87, %44, %31, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %110 = load i64, ptr %6, align 8
  ret i64 %110
}

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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 136}
!14 = !{!"_DHCP6_INSTANCE", !12, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !16, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !17, i64 136, !15, i64 160, !15, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !18, i64 216, !7, i64 224, !7, i64 225, !18, i64 232}
!15 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!16 = !{!"_EFI_DHCP6_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}
!17 = !{!"_DHCP6_IA_CB", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!18 = !{!"long long", !7, i64 0}
!19 = !{!20, !12, i64 8}
!20 = !{!"", !21, i64 0, !12, i64 8, !6, i64 16, !12, i64 24, !7, i64 28}
!21 = !{!"", !10, i64 0, !12, i64 4}
!22 = !{!20, !12, i64 24}
!23 = !{!14, !6, i64 120}
!24 = !{!20, !6, i64 16}
!25 = !{!14, !12, i64 144}
!26 = !{!14, !12, i64 148}


; 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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

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

declare void @FreePool(ptr noundef) local_unnamed_addr #1

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

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Dhcp6CalculateLeaseTime(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @Dhcp6ParseAddrOption(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775801, 1) i64 @Dhcp6GenerateIaCb(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %7 = getelementptr inbounds i8, ptr %0, i64 136
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %41, label %10

10:                                               ; preds = %5
  call void @Dhcp6ParseAddrOption(ptr noundef nonnull %8, ptr noundef %1, i16 noundef zeroext %2, ptr noundef nonnull %6, ptr noundef null)
  %11 = load i32, ptr %6, align 4, !tbaa !15
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %41, label %13

13:                                               ; preds = %10
  %14 = mul i32 %11, 24
  %15 = add i32 %14, 32
  %16 = zext i32 %15 to i64
  %17 = call ptr @AllocateZeroPool(i64 noundef %16) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %41, label %19

19:                                               ; preds = %13
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %17, i64 8
  store i32 %22, ptr %23, align 8, !tbaa !16
  %24 = load i32, ptr %6, align 4, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %17, i64 24
  store i32 %24, ptr %25, align 8, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %0, i64 120
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %27, i64 32
  %29 = call ptr @CopyMem(ptr noundef nonnull %17, ptr noundef nonnull %28, i64 noundef 8) #3
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %17, i64 28
  call void @Dhcp6ParseAddrOption(ptr noundef %30, ptr noundef %1, i16 noundef zeroext %2, ptr noundef nonnull %6, ptr noundef nonnull %31)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %.not = icmp eq ptr %34, null
  br i1 %.not, label %36, label %35

35:                                               ; preds = %19
  call void @FreePool(ptr noundef nonnull %34) #3
  %.pre = load ptr, ptr %7, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %35, %19
  %37 = phi ptr [ %.pre, %35 ], [ %32, %19 ]
  call void @FreePool(ptr noundef %37) #3
  %38 = call ptr @ZeroMem(ptr noundef nonnull %7, i64 noundef 24) #3
  store ptr %17, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %0, i64 144
  store i32 %3, ptr %39, align 8, !tbaa !23
  %40 = getelementptr inbounds i8, ptr %0, i64 148
  store i32 %4, ptr %40, align 4, !tbaa !24
  call void @Dhcp6CalculateLeaseTime(ptr noundef nonnull %7)
  br label %41

41:                                               ; preds = %13, %10, %5, %36
  %.0 = phi i64 [ 0, %36 ], [ -9223372036854775801, %5 ], [ -9223372036854775794, %10 ], [ -9223372036854775799, %13 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  ret i64 %.0
}

attributes #0 = { mustprogress 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, !10, i64 136}
!6 = !{!"_DHCP6_INSTANCE", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 40, !10, i64 112, !10, i64 120, !10, i64 128, !13, i64 136, !11, i64 160, !11, i64 176, !10, i64 192, !8, i64 200, !10, i64 208, !14, i64 216, !8, i64 224, !8, i64 225, !14, i64 232}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!12 = !{!"_EFI_DHCP6_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64}
!13 = !{!"_DHCP6_IA_CB", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!14 = !{!"long long", !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !7, i64 8}
!17 = !{!"", !18, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !8, i64 28}
!18 = !{!"", !19, i64 0, !7, i64 4}
!19 = !{!"short", !8, i64 0}
!20 = !{!17, !7, i64 24}
!21 = !{!6, !10, i64 120}
!22 = !{!17, !10, i64 16}
!23 = !{!6, !7, i64 144}
!24 = !{!6, !7, i64 148}


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