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

; 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_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct._EFI_COMPONENT_NAME2_PROTOCOL = type { ptr, ptr, ptr }
%struct.EFI_TCP4_CONFIG_DATA = type { i8, i8, %struct.EFI_TCP4_ACCESS_POINT, ptr }
%struct.EFI_TCP4_ACCESS_POINT = type { i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16, i8 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@gTcp4ComponentName = external dso_local global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@gTcp4ComponentName2 = external dso_local global %struct._EFI_COMPONENT_NAME2_PROTOCOL, align 8
@gTcpControllerNameTable = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [47 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.6 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.7 = external hidden unnamed_addr constant [20 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @UpdateName(ptr noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca [80 x i16], align 16
  %6 = alloca %struct.EFI_TCP4_CONFIG_DATA, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 160, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i64 -9223372036854775806, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

11:                                               ; preds = %1
  %12 = call ptr @ZeroMem(ptr noundef %6, i64 noundef 32)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i64 %15(ptr noundef %16, ptr noundef null, ptr noundef %6, ptr noundef null, ptr noundef null, ptr noundef null)
  store i64 %17, ptr %4, align 8, !tbaa !11
  %18 = load i64, ptr %4, align 8, !tbaa !11
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %38, label %20

20:                                               ; preds = %11
  %21 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %22 = getelementptr inbounds %struct.EFI_TCP4_CONFIG_DATA, ptr %6, i32 0, i32 2
  %23 = getelementptr inbounds %struct.EFI_TCP4_ACCESS_POINT, ptr %22, i32 0, i32 3
  %24 = load i16, ptr %23, align 2, !tbaa !13
  %25 = zext i16 %24 to i32
  %26 = getelementptr inbounds %struct.EFI_TCP4_CONFIG_DATA, ptr %6, i32 0, i32 2
  %27 = getelementptr inbounds %struct.EFI_TCP4_ACCESS_POINT, ptr %26, i32 0, i32 5
  %28 = load i16, ptr %27, align 2, !tbaa !18
  %29 = zext i16 %28 to i32
  %30 = getelementptr inbounds %struct.EFI_TCP4_CONFIG_DATA, ptr %6, i32 0, i32 2
  %31 = getelementptr inbounds %struct.EFI_TCP4_ACCESS_POINT, ptr %30, i32 0, i32 6
  %32 = load i8, ptr %31, align 2, !tbaa !19
  %33 = zext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, ptr @.str.5, ptr @.str.6
  %37 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef %21, i64 noundef 160, ptr noundef @.str.4, i32 noundef %25, i32 noundef %29, ptr noundef %36)
  br label %47

38:                                               ; preds = %11
  %39 = load i64, ptr %4, align 8, !tbaa !11
  %40 = icmp eq i64 %39, -9223372036854775789
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %43 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef %42, i64 noundef 160, ptr noundef @.str.7)
  br label %46

44:                                               ; preds = %38
  %45 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %45, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

46:                                               ; preds = %41
  br label %47

47:                                               ; preds = %46, %20
  %48 = load ptr, ptr @gTcpControllerNameTable, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load ptr, ptr @gTcpControllerNameTable, align 8, !tbaa !5
  %52 = call i64 @FreeUnicodeStringTable(ptr noundef %51)
  store ptr null, ptr @gTcpControllerNameTable, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %50, %47
  %54 = load ptr, ptr getelementptr inbounds (%struct._EFI_COMPONENT_NAME_PROTOCOL, ptr @gTcp4ComponentName, i32 0, i32 2), align 8, !tbaa !20
  %55 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %56 = call i64 @AddUnicodeString2(ptr noundef @.str, ptr noundef %54, ptr noundef @gTcpControllerNameTable, ptr noundef %55, i8 noundef zeroext 1)
  store i64 %56, ptr %4, align 8, !tbaa !11
  %57 = load i64, ptr %4, align 8, !tbaa !11
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %53
  %60 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %60, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

61:                                               ; preds = %53
  %62 = load ptr, ptr getelementptr inbounds (%struct._EFI_COMPONENT_NAME2_PROTOCOL, ptr @gTcp4ComponentName2, i32 0, i32 2), align 8, !tbaa !22
  %63 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %64 = call i64 @AddUnicodeString2(ptr noundef @.str.1, ptr noundef %62, ptr noundef @gTcpControllerNameTable, ptr noundef %63, i8 noundef zeroext 0)
  store i64 %64, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %61, %59, %44, %10
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 160, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %66 = load i64, ptr %2, align 8
  ret i64 %66
}

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

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

declare i64 @UnicodeSPrint(ptr noundef, i64 noundef, ptr noundef, ...) #2

declare i64 @FreeUnicodeStringTable(ptr noundef) #2

declare i64 @AddUnicodeString2(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"_EFI_TCP4_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, !6, i64 72}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !17, i64 12}
!14 = !{!"", !7, i64 0, !7, i64 1, !15, i64 2, !6, i64 24}
!15 = !{!"", !7, i64 0, !16, i64 1, !16, i64 5, !17, i64 10, !16, i64 12, !17, i64 16, !7, i64 18}
!16 = !{!"", !7, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!14, !17, i64 18}
!19 = !{!14, !7, i64 20}
!20 = !{!21, !6, i64 16}
!21 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!23, !6, i64 16}
!23 = !{!"_EFI_COMPONENT_NAME2_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}


; 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_COMPONENT_NAME_PROTOCOL = type { ptr, ptr, ptr }
%struct._EFI_COMPONENT_NAME2_PROTOCOL = type { ptr, ptr, ptr }
%struct.EFI_TCP4_CONFIG_DATA = type { i8, i8, %struct.EFI_TCP4_ACCESS_POINT, ptr }
%struct.EFI_TCP4_ACCESS_POINT = type { i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16, i8 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@gTcp4ComponentName = external dso_local local_unnamed_addr global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@gTcp4ComponentName2 = external dso_local local_unnamed_addr global %struct._EFI_COMPONENT_NAME2_PROTOCOL, align 8
@gTcpControllerNameTable = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [47 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.6 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.7 = external hidden unnamed_addr constant [20 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @UpdateName(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [80 x i16], align 16
  %3 = alloca %struct.EFI_TCP4_CONFIG_DATA, align 8
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %4 = icmp eq ptr %0, null
  br i1 %4, label %36, label %5

5:                                                ; preds = %1
  %6 = call ptr @ZeroMem(ptr noundef nonnull %3, i64 noundef 32) #3
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = call i64 %7(ptr noundef nonnull %0, ptr noundef null, ptr noundef nonnull %3, ptr noundef null, ptr noundef null, ptr noundef null) #3
  %9 = icmp slt i64 %8, 0
  br i1 %9, label %21, label %10

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %3, i64 12
  %12 = load i16, ptr %11, align 4, !tbaa !10
  %13 = zext i16 %12 to i32
  %14 = getelementptr inbounds i8, ptr %3, i64 18
  %15 = load i16, ptr %14, align 2, !tbaa !15
  %16 = zext i16 %15 to i32
  %17 = getelementptr inbounds i8, ptr %3, i64 20
  %18 = load i8, ptr %17, align 4, !tbaa !16
  %.not = icmp eq i8 %18, 0
  %19 = select i1 %.not, ptr @.str.6, ptr @.str.5
  %20 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef nonnull %2, i64 noundef 160, ptr noundef nonnull @.str.4, i32 noundef %13, i32 noundef %16, ptr noundef nonnull %19) #3
  br label %25

21:                                               ; preds = %5
  %22 = icmp eq i64 %8, -9223372036854775789
  br i1 %22, label %23, label %36

23:                                               ; preds = %21
  %24 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef nonnull %2, i64 noundef 160, ptr noundef nonnull @.str.7) #3
  br label %25

25:                                               ; preds = %23, %10
  %26 = load ptr, ptr @gTcpControllerNameTable, align 8, !tbaa !17
  %.not12 = icmp eq ptr %26, null
  br i1 %.not12, label %29, label %27

27:                                               ; preds = %25
  %28 = call i64 @FreeUnicodeStringTable(ptr noundef nonnull %26) #3
  store ptr null, ptr @gTcpControllerNameTable, align 8, !tbaa !17
  br label %29

29:                                               ; preds = %27, %25
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @gTcp4ComponentName, i64 16), align 8, !tbaa !18
  %31 = call i64 @AddUnicodeString2(ptr noundef nonnull @.str, ptr noundef %30, ptr noundef nonnull @gTcpControllerNameTable, ptr noundef nonnull %2, i8 noundef zeroext 1) #3
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %36, label %33

33:                                               ; preds = %29
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @gTcp4ComponentName2, i64 16), align 8, !tbaa !20
  %35 = call i64 @AddUnicodeString2(ptr noundef nonnull @.str.1, ptr noundef %34, ptr noundef nonnull @gTcpControllerNameTable, ptr noundef nonnull %2, i8 noundef zeroext 0) #3
  br label %36

36:                                               ; preds = %29, %21, %1, %33
  %.0 = phi i64 [ %35, %33 ], [ -9223372036854775806, %1 ], [ %8, %21 ], [ %31, %29 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %2) #3
  ret i64 %.0
}

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

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

declare i64 @UnicodeSPrint(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #2

declare i64 @FreeUnicodeStringTable(ptr noundef) local_unnamed_addr #2

declare i64 @AddUnicodeString2(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_EFI_TCP4_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !14, i64 12}
!11 = !{!"", !8, i64 0, !8, i64 1, !12, i64 2, !7, i64 24}
!12 = !{!"", !8, i64 0, !13, i64 1, !13, i64 5, !14, i64 10, !13, i64 12, !14, i64 16, !8, i64 18}
!13 = !{!"", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!11, !14, i64 18}
!16 = !{!11, !8, i64 20}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !7, i64 16}
!19 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16}
!20 = !{!21, !7, i64 16}
!21 = !{!"_EFI_COMPONENT_NAME2_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16}


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