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

; 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.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_RUNTIME_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct.NIC_IP4_CONFIG_INFO = type { %struct.NIC_ADDR, i32, i8, %struct.EFI_IP4_IPCONFIG_DATA }
%struct.NIC_ADDR = type { i16, i8, %struct.EFI_MAC_ADDRESS }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.EFI_IP4_IPCONFIG_DATA = type { %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i32, ptr }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

@mIp4ConfigVariableReclaimed = external dso_local global i8, align 1
@gEfiNicIp4ConfigVariableGuid = external global %struct.GUID, align 4
@gRT = external global ptr, align 8

; 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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Ip4ConfigIsNicExist(ptr noundef) #2

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Ip4ConfigReclaimVariable() #2 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.GUID, align 4
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load i8, ptr @mIp4ConfigVariableReclaimed, align 1, !tbaa !5
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  store i32 1, ptr %8, align 4
  br label %74

12:                                               ; preds = %0
  store i8 1, ptr @mIp4ConfigVariableReclaimed, align 1, !tbaa !5
  store i64 2, ptr %2, align 8, !tbaa !8
  %13 = load i64, ptr %2, align 8, !tbaa !8
  %14 = call ptr @AllocateZeroPool(i64 noundef %13)
  store ptr %14, ptr %3, align 8, !tbaa !10
  %15 = load i64, ptr %2, align 8, !tbaa !8
  store i64 %15, ptr %6, align 8, !tbaa !8
  br label %16

16:                                               ; preds = %71, %44, %12
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr @gRT, align 8, !tbaa !10
  %19 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %18, i32 0, i32 8
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load ptr, ptr %3, align 8, !tbaa !10
  %22 = call i64 %20(ptr noundef %2, ptr noundef %21, ptr noundef %5)
  store i64 %22, ptr %1, align 8, !tbaa !8
  br label %23

23:                                               ; preds = %56, %17
  %24 = load i64, ptr %1, align 8, !tbaa !8
  %25 = icmp eq i64 %24, -9223372036854775803
  br i1 %25, label %26, label %37

26:                                               ; preds = %23
  %27 = load i64, ptr %6, align 8, !tbaa !8
  %28 = load i64, ptr %2, align 8, !tbaa !8
  %29 = load ptr, ptr %3, align 8, !tbaa !10
  %30 = call ptr @ReallocatePool(i64 noundef %27, i64 noundef %28, ptr noundef %29)
  store ptr %30, ptr %3, align 8, !tbaa !10
  %31 = load i64, ptr %2, align 8, !tbaa !8
  store i64 %31, ptr %6, align 8, !tbaa !8
  %32 = load ptr, ptr @gRT, align 8, !tbaa !10
  %33 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %32, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = load ptr, ptr %3, align 8, !tbaa !10
  %36 = call i64 %34(ptr noundef %2, ptr noundef %35, ptr noundef %5)
  store i64 %36, ptr %1, align 8, !tbaa !8
  br label %37

37:                                               ; preds = %26, %23
  %38 = load i64, ptr %1, align 8, !tbaa !8
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  br label %72

41:                                               ; preds = %37
  %42 = call zeroext i8 @CompareGuid(ptr noundef %5, ptr noundef @gEfiNicIp4ConfigVariableGuid)
  %43 = icmp ne i8 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  br label %16

45:                                               ; preds = %41
  %46 = load ptr, ptr %3, align 8, !tbaa !10
  %47 = call i64 @GetVariable2(ptr noundef %46, ptr noundef @gEfiNicIp4ConfigVariableGuid, ptr noundef %7, ptr noundef null)
  %48 = load ptr, ptr %7, align 8, !tbaa !10
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %45
  br label %72

51:                                               ; preds = %45
  %52 = load ptr, ptr %7, align 8, !tbaa !10
  %53 = getelementptr inbounds %struct.NIC_IP4_CONFIG_INFO, ptr %52, i32 0, i32 0
  %54 = call zeroext i8 @Ip4ConfigIsNicExist(ptr noundef %53)
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %71, label %56

56:                                               ; preds = %51
  %57 = load i64, ptr %2, align 8, !tbaa !8
  %58 = load ptr, ptr %3, align 8, !tbaa !10
  %59 = call ptr @AllocateCopyPool(i64 noundef %57, ptr noundef %58)
  store ptr %59, ptr %4, align 8, !tbaa !10
  %60 = load ptr, ptr @gRT, align 8, !tbaa !10
  %61 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %60, i32 0, i32 8
  %62 = load ptr, ptr %61, align 8, !tbaa !12
  %63 = load ptr, ptr %3, align 8, !tbaa !10
  %64 = call i64 %62(ptr noundef %2, ptr noundef %63, ptr noundef %5)
  store i64 %64, ptr %1, align 8, !tbaa !8
  %65 = load ptr, ptr @gRT, align 8, !tbaa !10
  %66 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %65, i32 0, i32 9
  %67 = load ptr, ptr %66, align 8, !tbaa !16
  %68 = load ptr, ptr %4, align 8, !tbaa !10
  %69 = call i64 %67(ptr noundef %68, ptr noundef @gEfiNicIp4ConfigVariableGuid, i32 noundef 3, i64 noundef 0, ptr noundef null)
  %70 = load ptr, ptr %4, align 8, !tbaa !10
  call void @FreePool(ptr noundef %70)
  br label %23

71:                                               ; preds = %51
  br label %16

72:                                               ; preds = %50, %40
  %73 = load ptr, ptr %3, align 8, !tbaa !10
  call void @FreePool(ptr noundef %73)
  store i32 0, ptr %8, align 4
  br label %74

74:                                               ; preds = %72, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  %75 = load i32, ptr %8, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74
  ret void

77:                                               ; preds = %74
  unreachable
}

declare ptr @AllocateZeroPool(i64 noundef) #1

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

declare zeroext i8 @CompareGuid(ptr noundef, ptr noundef) #1

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

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !11, i64 80}
!13 = !{!"", !14, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128}
!14 = !{!"", !9, i64 0, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!15 = !{!"int", !6, i64 0}
!16 = !{!13, !11, i64 88}


; 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.GUID = type { i32, i16, i16, [8 x i8] }

@mIp4ConfigVariableReclaimed = external dso_local local_unnamed_addr global i8, align 1
@gEfiNicIp4ConfigVariableGuid = external global %struct.GUID, align 4
@gRT = external local_unnamed_addr global ptr, align 8

; 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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Ip4ConfigIsNicExist(ptr noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @Ip4ConfigReclaimVariable() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = alloca %struct.GUID, align 4
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = load i8, ptr @mIp4ConfigVariableReclaimed, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %43

5:                                                ; preds = %0
  store i8 1, ptr @mIp4ConfigVariableReclaimed, align 1, !tbaa !5
  store i64 2, ptr %1, align 8, !tbaa !8
  %6 = tail call ptr @AllocateZeroPool(i64 noundef 2) #3
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %23, %29
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %5
  %.013 = phi ptr [ %6, %5 ], [ %.215, %.loopexit.loopexit ]
  %.0 = phi i64 [ 2, %5 ], [ %.2, %.loopexit.loopexit ]
  %7 = load ptr, ptr @gRT, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %7, i64 80
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = call i64 %9(ptr noundef nonnull %1, ptr noundef %.013, ptr noundef nonnull %2) #3
  br label %11

11:                                               ; preds = %31, %.loopexit
  %.114 = phi ptr [ %.013, %.loopexit ], [ %.215, %31 ]
  %.011 = phi i64 [ %10, %.loopexit ], [ %37, %31 ]
  %.1 = phi i64 [ %.0, %.loopexit ], [ %.2, %31 ]
  %12 = icmp eq i64 %.011, -9223372036854775803
  br i1 %12, label %13, label %21

13:                                               ; preds = %11
  %14 = load i64, ptr %1, align 8, !tbaa !8
  %15 = call ptr @ReallocatePool(i64 noundef %.1, i64 noundef %14, ptr noundef %.114) #3
  %16 = load i64, ptr %1, align 8, !tbaa !8
  %17 = load ptr, ptr @gRT, align 8, !tbaa !10
  %18 = getelementptr inbounds i8, ptr %17, i64 80
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = call i64 %19(ptr noundef nonnull %1, ptr noundef %15, ptr noundef nonnull %2) #3
  br label %21

21:                                               ; preds = %13, %11
  %.215 = phi ptr [ %15, %13 ], [ %.114, %11 ]
  %.112 = phi i64 [ %20, %13 ], [ %.011, %11 ]
  %.2 = phi i64 [ %16, %13 ], [ %.1, %11 ]
  %22 = icmp slt i64 %.112, 0
  br i1 %22, label %42, label %23

23:                                               ; preds = %21
  %24 = call zeroext i8 @CompareGuid(ptr noundef nonnull %2, ptr noundef nonnull @gEfiNicIp4ConfigVariableGuid) #3
  %.not17 = icmp eq i8 %24, 0
  br i1 %.not17, label %.loopexit.loopexit, label %25

25:                                               ; preds = %23
  %26 = call i64 @GetVariable2(ptr noundef %.215, ptr noundef nonnull @gEfiNicIp4ConfigVariableGuid, ptr noundef nonnull %3, ptr noundef null) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !10
  %28 = icmp eq ptr %27, null
  br i1 %28, label %42, label %29

29:                                               ; preds = %25
  %30 = call zeroext i8 @Ip4ConfigIsNicExist(ptr noundef nonnull %27)
  %.not18 = icmp eq i8 %30, 0
  br i1 %.not18, label %31, label %.loopexit.loopexit

31:                                               ; preds = %29
  %32 = load i64, ptr %1, align 8, !tbaa !8
  %33 = call ptr @AllocateCopyPool(i64 noundef %32, ptr noundef %.215) #3
  %34 = load ptr, ptr @gRT, align 8, !tbaa !10
  %35 = getelementptr inbounds i8, ptr %34, i64 80
  %36 = load ptr, ptr %35, align 8, !tbaa !12
  %37 = call i64 %36(ptr noundef nonnull %1, ptr noundef %.215, ptr noundef nonnull %2) #3
  %38 = load ptr, ptr @gRT, align 8, !tbaa !10
  %39 = getelementptr inbounds i8, ptr %38, i64 88
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = call i64 %40(ptr noundef %33, ptr noundef nonnull @gEfiNicIp4ConfigVariableGuid, i32 noundef 3, i64 noundef 0, ptr noundef null) #3
  call void @FreePool(ptr noundef %33) #3
  br label %11

42:                                               ; preds = %25, %21
  call void @FreePool(ptr noundef %.215) #3
  br label %43

43:                                               ; preds = %0, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void
}

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

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

declare zeroext i8 @CompareGuid(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !11, i64 80}
!13 = !{!"", !14, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128}
!14 = !{!"", !9, i64 0, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!15 = !{!"int", !6, i64 0}
!16 = !{!13, !11, i64 88}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass