; 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_IP4_MODE_DATA = type { i8, i32, %struct.EFI_IP4_CONFIG_DATA, i8, i32, ptr, i32, ptr, i32, ptr }
%struct.EFI_IP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, i8, i8, i8, i32, i32 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._EFI_IP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@gIp4ComponentName = external dso_local global %struct._EFI_COMPONENT_NAME_PROTOCOL, align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@gIp4ComponentName2 = external dso_local global %struct._EFI_COMPONENT_NAME2_PROTOCOL, align 8
@gIp4ControllerNameTable = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [19 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [25 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_IP4_MODE_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 88, 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 %77

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

19:                                               ; preds = %11
  %20 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %20, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %77

21:                                               ; preds = %11
  %22 = getelementptr inbounds %struct.EFI_IP4_MODE_DATA, ptr %6, i32 0, i32 0
  %23 = load i8, ptr %22, align 8, !tbaa !13
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %21
  %26 = getelementptr inbounds %struct.EFI_IP4_MODE_DATA, ptr %6, i32 0, i32 3
  %27 = load i8, ptr %26, align 4, !tbaa !18
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %32, label %29

29:                                               ; preds = %25, %21
  %30 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %31 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef %30, i64 noundef 160, ptr noundef @.str.4)
  br label %59

32:                                               ; preds = %25
  %33 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %34 = getelementptr inbounds %struct.EFI_IP4_MODE_DATA, ptr %6, i32 0, i32 2
  %35 = getelementptr inbounds %struct.EFI_IP4_CONFIG_DATA, ptr %34, i32 0, i32 6
  %36 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [4 x i8], ptr %36, i64 0, i64 0
  %38 = load i8, ptr %37, align 2, !tbaa !19
  %39 = zext i8 %38 to i32
  %40 = getelementptr inbounds %struct.EFI_IP4_MODE_DATA, ptr %6, i32 0, i32 2
  %41 = getelementptr inbounds %struct.EFI_IP4_CONFIG_DATA, ptr %40, i32 0, i32 6
  %42 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [4 x i8], ptr %42, i64 0, i64 1
  %44 = load i8, ptr %43, align 1, !tbaa !19
  %45 = zext i8 %44 to i32
  %46 = getelementptr inbounds %struct.EFI_IP4_MODE_DATA, ptr %6, i32 0, i32 2
  %47 = getelementptr inbounds %struct.EFI_IP4_CONFIG_DATA, ptr %46, i32 0, i32 6
  %48 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [4 x i8], ptr %48, i64 0, i64 2
  %50 = load i8, ptr %49, align 2, !tbaa !19
  %51 = zext i8 %50 to i32
  %52 = getelementptr inbounds %struct.EFI_IP4_MODE_DATA, ptr %6, i32 0, i32 2
  %53 = getelementptr inbounds %struct.EFI_IP4_CONFIG_DATA, ptr %52, i32 0, i32 6
  %54 = getelementptr inbounds %struct.EFI_IPv4_ADDRESS, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [4 x i8], ptr %54, i64 0, i64 3
  %56 = load i8, ptr %55, align 1, !tbaa !19
  %57 = zext i8 %56 to i32
  %58 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef %33, i64 noundef 160, ptr noundef @.str.5, i32 noundef %39, i32 noundef %45, i32 noundef %51, i32 noundef %57)
  br label %59

59:                                               ; preds = %32, %29
  %60 = load ptr, ptr @gIp4ControllerNameTable, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load ptr, ptr @gIp4ControllerNameTable, align 8, !tbaa !5
  %64 = call i64 @FreeUnicodeStringTable(ptr noundef %63)
  store ptr null, ptr @gIp4ControllerNameTable, align 8, !tbaa !5
  br label %65

65:                                               ; preds = %62, %59
  %66 = load ptr, ptr getelementptr inbounds (%struct._EFI_COMPONENT_NAME_PROTOCOL, ptr @gIp4ComponentName, i32 0, i32 2), align 8, !tbaa !20
  %67 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %68 = call i64 @AddUnicodeString2(ptr noundef @.str, ptr noundef %66, ptr noundef @gIp4ControllerNameTable, ptr noundef %67, i8 noundef zeroext 1)
  store i64 %68, ptr %4, align 8, !tbaa !11
  %69 = load i64, ptr %4, align 8, !tbaa !11
  %70 = icmp slt i64 %69, 0
  br i1 %70, label %71, label %73

71:                                               ; preds = %65
  %72 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %72, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %77

73:                                               ; preds = %65
  %74 = load ptr, ptr getelementptr inbounds (%struct._EFI_COMPONENT_NAME2_PROTOCOL, ptr @gIp4ComponentName2, i32 0, i32 2), align 8, !tbaa !22
  %75 = getelementptr inbounds [80 x i16], ptr %5, i64 0, i64 0
  %76 = call i64 @AddUnicodeString2(ptr noundef @.str.1, ptr noundef %74, ptr noundef @gIp4ControllerNameTable, ptr noundef %75, i8 noundef zeroext 0)
  store i64 %76, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %77

77:                                               ; preds = %73, %71, %19, %10
  call void @llvm.lifetime.end.p0(i64 88, 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
  %78 = load i64, ptr %2, align 8
  ret i64 %78
}

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

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_IP4_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}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"", !7, i64 0, !15, i64 4, !16, i64 8, !7, i64 36, !15, i64 40, !6, i64 48, !15, i64 56, !6, i64 64, !15, i64 72, !6, i64 80}
!15 = !{!"int", !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !17, i64 6, !17, i64 10, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !15, i64 20, !15, i64 24}
!17 = !{!"", !7, i64 0}
!18 = !{!14, !7, i64 36}
!19 = !{!7, !7, i64 0}
!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_IP4_MODE_DATA = type { i8, i32, %struct.EFI_IP4_CONFIG_DATA, i8, i32, ptr, i32, ptr, i32, ptr }
%struct.EFI_IP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, i8, i8, i8, i32, i32 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@gIp4ComponentName = 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
@gIp4ComponentName2 = external dso_local local_unnamed_addr global %struct._EFI_COMPONENT_NAME2_PROTOCOL, align 8
@gIp4ControllerNameTable = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [19 x i32], align 4
@.str.5 = external hidden unnamed_addr constant [25 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_IP4_MODE_DATA, align 8
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %3) #3
  %4 = icmp eq ptr %0, null
  br i1 %4, label %42, label %5

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

9:                                                ; preds = %5
  %10 = load i8, ptr %3, align 8, !tbaa !10
  %11 = icmp ne i8 %10, 0
  %12 = getelementptr inbounds i8, ptr %3, i64 36
  %13 = load i8, ptr %12, align 4
  %14 = icmp ne i8 %13, 0
  %or.cond = select i1 %11, i1 %14, i1 false
  br i1 %or.cond, label %17, label %15

15:                                               ; preds = %9
  %16 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef nonnull %2, i64 noundef 160, ptr noundef nonnull @.str.4) #3
  br label %31

17:                                               ; preds = %9
  %18 = getelementptr inbounds i8, ptr %3, i64 14
  %19 = load i8, ptr %18, align 2, !tbaa !15
  %20 = zext i8 %19 to i32
  %21 = getelementptr inbounds i8, ptr %3, i64 15
  %22 = load i8, ptr %21, align 1, !tbaa !15
  %23 = zext i8 %22 to i32
  %24 = getelementptr inbounds i8, ptr %3, i64 16
  %25 = load i8, ptr %24, align 8, !tbaa !15
  %26 = zext i8 %25 to i32
  %27 = getelementptr inbounds i8, ptr %3, i64 17
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = zext i8 %28 to i32
  %30 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef nonnull %2, i64 noundef 160, ptr noundef nonnull @.str.5, i32 noundef %20, i32 noundef %23, i32 noundef %26, i32 noundef %29) #3
  br label %31

31:                                               ; preds = %17, %15
  %32 = load ptr, ptr @gIp4ControllerNameTable, align 8, !tbaa !16
  %.not = icmp eq ptr %32, null
  br i1 %.not, label %35, label %33

33:                                               ; preds = %31
  %34 = call i64 @FreeUnicodeStringTable(ptr noundef nonnull %32) #3
  store ptr null, ptr @gIp4ControllerNameTable, align 8, !tbaa !16
  br label %35

35:                                               ; preds = %33, %31
  %36 = load ptr, ptr getelementptr inbounds (i8, ptr @gIp4ComponentName, i64 16), align 8, !tbaa !17
  %37 = call i64 @AddUnicodeString2(ptr noundef nonnull @.str, ptr noundef %36, ptr noundef nonnull @gIp4ControllerNameTable, ptr noundef nonnull %2, i8 noundef zeroext 1) #3
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %42, label %39

39:                                               ; preds = %35
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @gIp4ComponentName2, i64 16), align 8, !tbaa !19
  %41 = call i64 @AddUnicodeString2(ptr noundef nonnull @.str.1, ptr noundef %40, ptr noundef nonnull @gIp4ControllerNameTable, ptr noundef nonnull %2, i8 noundef zeroext 0) #3
  br label %42

42:                                               ; preds = %35, %5, %1, %39
  %.0 = phi i64 [ %41, %39 ], [ -9223372036854775806, %1 ], [ %7, %5 ], [ %37, %35 ]
  call void @llvm.lifetime.end.p0(i64 88, 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 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_IP4_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 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !8, i64 0}
!11 = !{!"", !8, i64 0, !12, i64 4, !13, i64 8, !8, i64 36, !12, i64 40, !7, i64 48, !12, i64 56, !7, i64 64, !12, i64 72, !7, i64 80}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !14, i64 6, !14, i64 10, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !12, i64 20, !12, i64 24}
!14 = !{!"", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 16}
!18 = !{!"_EFI_COMPONENT_NAME_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!20, !7, i64 16}
!20 = !{!"_EFI_COMPONENT_NAME2_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16}


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