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

; 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_MAC_ADDRESS = type { [32 x i8] }

@.str.12 = external hidden unnamed_addr constant [144 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [26 x i8], align 1

; 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 zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @NetLibGetMacAddress(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @NetLibGetMacString(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.EFI_MAC_ADDRESS, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i16, align 2
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  br label %16

16:                                               ; preds = %3
  %17 = call zeroext i8 @DebugAssertEnabled()
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @DebugAssert(ptr noundef @.str.12, i64 noundef 2309, ptr noundef @.str.31)
  br label %23

23:                                               ; preds = %22, %19
  br label %24

24:                                               ; preds = %23, %16
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call i64 @NetLibGetMacAddress(ptr noundef %27, ptr noundef %9, ptr noundef %11)
  store i64 %28, ptr %8, align 8, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = icmp slt i64 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %26
  %32 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %32, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %81

33:                                               ; preds = %26
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = mul i64 2, %34
  %36 = add i64 %35, 5
  %37 = add i64 %36, 1
  %38 = mul i64 %37, 2
  %39 = call ptr @AllocateZeroPool(i64 noundef %38)
  store ptr %39, ptr %13, align 8, !tbaa !5
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %81

43:                                               ; preds = %33
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %44, ptr %45, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %9, i32 0, i32 0
  %47 = getelementptr inbounds [32 x i8], ptr %46, i64 0, i64 0
  store ptr %47, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %61, %43
  %49 = load i64, ptr %14, align 8, !tbaa !9
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %64

52:                                               ; preds = %48
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %10, align 8, !tbaa !5
  %56 = load i8, ptr %54, align 1, !tbaa !11
  %57 = zext i8 %56 to i64
  %58 = call i64 @UnicodeValueToString(ptr noundef %53, i64 noundef 160, i64 noundef %57, i64 noundef 2)
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds i16, ptr %59, i64 %58
  store ptr %60, ptr %13, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %52
  %62 = load i64, ptr %14, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %14, align 8, !tbaa !9
  br label %48, !llvm.loop !12

64:                                               ; preds = %48
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = call zeroext i16 @NetLibGetVlanId(ptr noundef %65)
  store i16 %66, ptr %12, align 2, !tbaa !14
  %67 = load i16, ptr %12, align 2, !tbaa !14
  %68 = zext i16 %67 to i32
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %79

70:                                               ; preds = %64
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds i16, ptr %71, i32 1
  store ptr %72, ptr %13, align 8, !tbaa !5
  store i16 92, ptr %71, align 2, !tbaa !14
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = load i16, ptr %12, align 2, !tbaa !14
  %75 = zext i16 %74 to i64
  %76 = call i64 @UnicodeValueToString(ptr noundef %73, i64 noundef 160, i64 noundef %75, i64 noundef 4)
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds i16, ptr %77, i64 %76
  store ptr %78, ptr %13, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %70, %64
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 0, ptr %80, align 2, !tbaa !14
  store i64 0, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %81

81:                                               ; preds = %79, %42, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %82 = load i64, ptr %4, align 8
  ret i64 %82
}

declare ptr @AllocateZeroPool(i64 noundef) #1

declare i64 @UnicodeValueToString(ptr noundef, i64 noundef, i64 noundef, i64 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}


; 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_MAC_ADDRESS = type { [32 x i8] }

@.str.12 = external hidden unnamed_addr constant [144 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [26 x i8], align 1

; 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 zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @NetLibGetMacAddress(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @NetLibGetMacString(ptr noundef %0, ptr nocapture noundef readnone %1, ptr noundef writeonly %2) local_unnamed_addr #2 {
  %4 = alloca %struct.EFI_MAC_ADDRESS, align 1
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %6 = tail call zeroext i8 @DebugAssertEnabled() #3
  %7 = icmp eq i8 %6, 0
  %8 = icmp ne ptr %2, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %10, label %9

9:                                                ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str.12, i64 noundef 2309, ptr noundef nonnull @.str.31) #3
  br label %10

10:                                               ; preds = %9, %3
  %11 = call i64 @NetLibGetMacAddress(ptr noundef %0, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %36, label %13

13:                                               ; preds = %10
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = shl i64 %14, 2
  %16 = add i64 %15, 12
  %17 = call ptr @AllocateZeroPool(i64 noundef %16) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %36, label %19

19:                                               ; preds = %13
  store ptr %17, ptr %2, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %.not28 = icmp eq i64 %20, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.027 = phi i64 [ %26, %.lr.ph ], [ 0, %19 ]
  %.02026 = phi ptr [ %25, %.lr.ph ], [ %17, %19 ]
  %.02225 = phi ptr [ %21, %.lr.ph ], [ %4, %19 ]
  %21 = getelementptr inbounds i8, ptr %.02225, i64 1
  %22 = load i8, ptr %.02225, align 1, !tbaa !11
  %23 = zext i8 %22 to i64
  %24 = call i64 @UnicodeValueToString(ptr noundef %.02026, i64 noundef 160, i64 noundef %23, i64 noundef 2) #3
  %25 = getelementptr inbounds i16, ptr %.02026, i64 %24
  %26 = add nuw i64 %.027, 1
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %19
  %.020.lcssa = phi ptr [ %17, %19 ], [ %25, %.lr.ph ]
  %29 = call zeroext i16 @NetLibGetVlanId(ptr noundef %0)
  %.not = icmp eq i16 %29, 0
  br i1 %.not, label %35, label %30

30:                                               ; preds = %._crit_edge
  %31 = getelementptr inbounds i8, ptr %.020.lcssa, i64 2
  store i16 92, ptr %.020.lcssa, align 2, !tbaa !14
  %32 = zext i16 %29 to i64
  %33 = call i64 @UnicodeValueToString(ptr noundef nonnull %31, i64 noundef 160, i64 noundef %32, i64 noundef 4) #3
  %34 = getelementptr inbounds i16, ptr %31, i64 %33
  br label %35

35:                                               ; preds = %30, %._crit_edge
  %.1 = phi ptr [ %34, %30 ], [ %.020.lcssa, %._crit_edge ]
  store i16 0, ptr %.1, align 2, !tbaa !14
  br label %36

36:                                               ; preds = %13, %10, %35
  %.021 = phi i64 [ 0, %35 ], [ %11, %10 ], [ -9223372036854775799, %13 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  ret i64 %.021
}

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #1

declare i64 @UnicodeValueToString(ptr noundef, i64 noundef, i64 noundef, i64 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass