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

; 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] }

@IScsiHexString = external dso_local constant [23 x i8], align 16
@.str.6 = external hidden unnamed_addr constant [6 x i32], align 4

; 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

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

11:                                               ; preds = %58, %4
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %61

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [32 x i8], ptr %17, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %22 = zext i8 %21 to i32
  %23 = ashr i32 %22, 4
  %24 = and i32 %23, 15
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [23 x i8], ptr @IScsiHexString, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = sext i8 %27 to i16
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = mul i32 3, %30
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds i16, ptr %29, i64 %32
  store i16 %28, ptr %33, align 2, !tbaa !11
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [32 x i8], ptr %35, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = and i32 %40, 15
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [23 x i8], ptr @IScsiHexString, i64 0, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = sext i8 %44 to i16
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = mul i32 3, %47
  %49 = add i32 %48, 1
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i16, ptr %46, i64 %50
  store i16 %45, ptr %51, align 2, !tbaa !11
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = mul i32 3, %53
  %55 = add i32 %54, 2
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i16, ptr %52, i64 %56
  store i16 45, ptr %57, align 2, !tbaa !11
  br label %58

58:                                               ; preds = %15
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %9, align 4, !tbaa !9
  br label %11, !llvm.loop !14

61:                                               ; preds = %11
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = mul i32 3, %63
  %65 = sub i32 %64, 1
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds i16, ptr %62, i64 %66
  store ptr %67, ptr %10, align 8, !tbaa !5
  %68 = load i16, ptr %7, align 2, !tbaa !11
  %69 = zext i16 %68 to i32
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %78

71:                                               ; preds = %61
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load i16, ptr %7, align 2, !tbaa !11
  %74 = zext i16 %73 to i64
  %75 = call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef %72, i64 noundef 12, ptr noundef @.str.6, i64 noundef %74)
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds i16, ptr %76, i64 %75
  store ptr %77, ptr %10, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %71, %61
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  store i16 0, ptr %79, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@IScsiHexString = external dso_local local_unnamed_addr constant [23 x i8], align 16
@.str.6 = external hidden unnamed_addr constant [6 x i32], align 4

; Function Attrs: nounwind uwtable
define dso_local void @IScsiMacAddrToStr(ptr nocapture noundef readonly %0, i32 noundef %1, i16 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #0 {
  %.not21 = icmp eq i32 %1, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %5 = getelementptr inbounds [32 x i8], ptr %0, i64 0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = lshr i8 %6, 4
  %8 = zext nneg i8 %7 to i64
  %9 = getelementptr inbounds [23 x i8], ptr @IScsiHexString, i64 0, i64 %8
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = sext i8 %10 to i16
  %12 = trunc nuw i64 %indvars.iv to i32
  %13 = mul i32 %12, 3
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i16, ptr %3, i64 %14
  store i16 %11, ptr %15, align 2, !tbaa !8
  %16 = load i8, ptr %5, align 1, !tbaa !5
  %17 = and i8 %16, 15
  %18 = zext nneg i8 %17 to i64
  %19 = getelementptr inbounds [23 x i8], ptr @IScsiHexString, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = sext i8 %20 to i16
  %22 = add i32 %13, 1
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i16, ptr %3, i64 %23
  store i16 %21, ptr %24, align 2, !tbaa !8
  %25 = add i32 %13, 2
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i16, ptr %3, i64 %26
  store i16 45, ptr %27, align 2, !tbaa !8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !10

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %28 = mul i32 %1, 3
  %29 = add i32 %28, -1
  %30 = zext i32 %29 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.019.lcssa = phi i64 [ 4294967295, %4 ], [ %30, %._crit_edge.loopexit ]
  %31 = getelementptr inbounds i16, ptr %3, i64 %.019.lcssa
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %36, label %32

32:                                               ; preds = %._crit_edge
  %33 = zext i16 %2 to i64
  %34 = tail call i64 (ptr, i64, ptr, ...) @UnicodeSPrint(ptr noundef %31, i64 noundef 12, ptr noundef nonnull @.str.6, i64 noundef %33) #2
  %35 = getelementptr inbounds i16, ptr %31, i64 %34
  br label %36

36:                                               ; preds = %32, %._crit_edge
  %.0 = phi ptr [ %35, %32 ], [ %31, %._crit_edge ]
  store i16 0, ptr %.0, align 2, !tbaa !8
  ret void
}

declare i64 @UnicodeSPrint(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #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 = { "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 }

!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 = !{!"short", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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