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

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

; 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
declare dso_local ptr @SplitStr(ptr noundef, i16 noundef zeroext) #1

declare i64 @StrHexToUintn(ptr noundef) #2

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

7:                                                ; preds = %34, %2
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 8
  br i1 %9, label %10, label %37

10:                                               ; preds = %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call ptr @SplitStr(ptr noundef %11, i16 noundef zeroext 58)
  %13 = call i64 @StrHexToUintn(ptr noundef %12)
  %14 = trunc i64 %13 to i16
  store i16 %14, ptr %6, align 2, !tbaa !11
  %15 = load i16, ptr %6, align 2, !tbaa !11
  %16 = zext i16 %15 to i32
  %17 = ashr i32 %16, 8
  %18 = trunc i32 %17 to i8
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = mul i64 %21, 2
  %23 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 %22
  store i8 %18, ptr %23, align 1, !tbaa !13
  %24 = load i16, ptr %6, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = and i32 %25, 255
  %27 = trunc i32 %26 to i8
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = mul i64 %30, 2
  %32 = add i64 %31, 1
  %33 = getelementptr inbounds [16 x i8], ptr %29, i64 0, i64 %32
  store i8 %27, ptr %33, align 1, !tbaa !13
  br label %34

34:                                               ; preds = %10
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = add i64 %35, 1
  store i64 %36, ptr %5, align 8, !tbaa !9
  br label %7, !llvm.loop !14

37:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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 = !{!"long long", !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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @SplitStr(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare i64 @StrHexToUintn(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @StrToIPv6Addr(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %4 = tail call i64 @StrHexToUintn(ptr noundef %3) #2
  %5 = trunc i64 %4 to i8
  %6 = lshr i64 %4, 8
  %7 = trunc i64 %6 to i8
  store i8 %7, ptr %1, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %5, ptr %8, align 1, !tbaa !5
  %9 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %10 = tail call i64 @StrHexToUintn(ptr noundef %9) #2
  %11 = trunc i64 %10 to i8
  %12 = lshr i64 %10, 8
  %13 = trunc i64 %12 to i8
  %14 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %11, ptr %15, align 1, !tbaa !5
  %16 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %17 = tail call i64 @StrHexToUintn(ptr noundef %16) #2
  %18 = trunc i64 %17 to i8
  %19 = lshr i64 %17, 8
  %20 = trunc i64 %19 to i8
  %21 = getelementptr inbounds i8, ptr %1, i64 4
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %1, i64 5
  store i8 %18, ptr %22, align 1, !tbaa !5
  %23 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %24 = tail call i64 @StrHexToUintn(ptr noundef %23) #2
  %25 = trunc i64 %24 to i8
  %26 = lshr i64 %24, 8
  %27 = trunc i64 %26 to i8
  %28 = getelementptr inbounds i8, ptr %1, i64 6
  store i8 %27, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 7
  store i8 %25, ptr %29, align 1, !tbaa !5
  %30 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %31 = tail call i64 @StrHexToUintn(ptr noundef %30) #2
  %32 = trunc i64 %31 to i8
  %33 = lshr i64 %31, 8
  %34 = trunc i64 %33 to i8
  %35 = getelementptr inbounds i8, ptr %1, i64 8
  store i8 %34, ptr %35, align 1, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %1, i64 9
  store i8 %32, ptr %36, align 1, !tbaa !5
  %37 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %38 = tail call i64 @StrHexToUintn(ptr noundef %37) #2
  %39 = trunc i64 %38 to i8
  %40 = lshr i64 %38, 8
  %41 = trunc i64 %40 to i8
  %42 = getelementptr inbounds i8, ptr %1, i64 10
  store i8 %41, ptr %42, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %1, i64 11
  store i8 %39, ptr %43, align 1, !tbaa !5
  %44 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %45 = tail call i64 @StrHexToUintn(ptr noundef %44) #2
  %46 = trunc i64 %45 to i8
  %47 = lshr i64 %45, 8
  %48 = trunc i64 %47 to i8
  %49 = getelementptr inbounds i8, ptr %1, i64 12
  store i8 %48, ptr %49, align 1, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %1, i64 13
  store i8 %46, ptr %50, align 1, !tbaa !5
  %51 = tail call ptr @SplitStr(ptr noundef %0, i16 noundef zeroext 58)
  %52 = tail call i64 @StrHexToUintn(ptr noundef %51) #2
  %53 = trunc i64 %52 to i8
  %54 = lshr i64 %52, 8
  %55 = trunc i64 %54 to i8
  %56 = getelementptr inbounds i8, ptr %1, i64 14
  store i8 %55, ptr %56, align 1, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %1, i64 15
  store i8 %53, ptr %57, align 1, !tbaa !5
  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 = { "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"}


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