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

; 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.MAC_ADDR_DEVICE_PATH = type { %struct.EFI_DEVICE_PATH_PROTOCOL, %struct.EFI_MAC_ADDRESS, i8 }
%struct.EFI_DEVICE_PATH_PROTOCOL = type { i8, i8, [2 x i8] }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

@.str.33 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.96 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.97 = external hidden unnamed_addr constant [7 x i32], align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @UefiDevicePathLibCatPrint(ptr noundef, ptr noundef, ...) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextMacAddr(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i8 %3, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %12, ptr %9, align 8, !tbaa !5
  store i64 32, ptr %10, align 8, !tbaa !10
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.MAC_ADDR_DEVICE_PATH, ptr %13, i32 0, i32 2
  %15 = load i8, ptr %14, align 1, !tbaa !12
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %24, label %18

18:                                               ; preds = %4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.MAC_ADDR_DEVICE_PATH, ptr %19, i32 0, i32 2
  %21 = load i8, ptr %20, align 1, !tbaa !12
  %22 = zext i8 %21 to i32
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %18, %4
  store i64 6, ptr %10, align 8, !tbaa !10
  br label %25

25:                                               ; preds = %24, %18
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %26, ptr noundef @.str.96)
  store i64 0, ptr %11, align 8, !tbaa !10
  br label %28

28:                                               ; preds = %42, %25
  %29 = load i64, ptr %11, align 8, !tbaa !10
  %30 = load i64, ptr %10, align 8, !tbaa !10
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %32, label %45

32:                                               ; preds = %28
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MAC_ADDR_DEVICE_PATH, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %11, align 8, !tbaa !10
  %38 = getelementptr inbounds [32 x i8], ptr %36, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %33, ptr noundef @.str.33, i32 noundef %40)
  br label %42

42:                                               ; preds = %32
  %43 = load i64, ptr %11, align 8, !tbaa !10
  %44 = add i64 %43, 1
  store i64 %44, ptr %11, align 8, !tbaa !10
  br label %28, !llvm.loop !16

45:                                               ; preds = %28
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MAC_ADDR_DEVICE_PATH, ptr %47, i32 0, i32 2
  %49 = load i8, ptr %48, align 1, !tbaa !12
  %50 = zext i8 %49 to i32
  %51 = call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %46, ptr noundef @.str.97, i32 noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !7, i64 36}
!13 = !{!"", !14, i64 0, !15, i64 4, !7, i64 36}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2}
!15 = !{!"", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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"

@.str.33 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.96 = external hidden unnamed_addr constant [5 x i32], align 4
@.str.97 = external hidden unnamed_addr constant [7 x i32], align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @UefiDevicePathLibCatPrint(ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @DevPathToTextMacAddr(ptr noundef %0, ptr nocapture noundef readonly %1, i8 noundef zeroext %2, i8 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 36
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %switch = icmp ult i8 %6, 2
  %spec.select = select i1 %switch, i64 6, i64 32
  %7 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.96)
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  br label %9

9:                                                ; preds = %4, %9
  %.013 = phi i64 [ 0, %4 ], [ %14, %9 ]
  %10 = getelementptr inbounds [32 x i8], ptr %8, i64 0, i64 %.013
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %12 = zext i8 %11 to i32
  %13 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.33, i32 noundef %12)
  %14 = add nuw nsw i64 %.013, 1
  %exitcond.not = icmp eq i64 %14, %spec.select
  br i1 %exitcond.not, label %15, label %9, !llvm.loop !12

15:                                               ; preds = %9
  %16 = load i8, ptr %5, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = tail call ptr (ptr, ptr, ...) @UefiDevicePathLibCatPrint(ptr noundef %0, ptr noundef nonnull @.str.97, i32 noundef %17)
  ret void
}

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" }

!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, !8, i64 36}
!6 = !{!"", !7, i64 0, !10, i64 4, !8, i64 36}
!7 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass