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

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

@.str = external hidden unnamed_addr constant [148 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [56 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

declare zeroext i8 @DebugAssertEnabled() #1

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

; 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 i64 @ConvertToUnicodeText(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 i64, align 8
  %10 = 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 8, ptr %9) #3
  br label %11

11:                                               ; preds = %3
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %22

14:                                               ; preds = %11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %14
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %14
  call void @DebugAssert(ptr noundef @.str, i64 noundef 124, ptr noundef @.str.4)
  br label %21

21:                                               ; preds = %20, %17
  br label %22

22:                                               ; preds = %21, %11
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i64 @AsciiStrSize(ptr noundef %25)
  %27 = mul i64 %26, 2
  store i64 %27, ptr %8, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %35, label %32

32:                                               ; preds = %24
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %38

35:                                               ; preds = %32, %24
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %36, ptr %37, align 8, !tbaa !9
  store i64 -9223372036854775803, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %60

38:                                               ; preds = %32
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %53, %38
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = call i64 @AsciiStrLen(ptr noundef %41)
  %43 = icmp ult i64 %40, %42
  br i1 %43, label %44, label %56

44:                                               ; preds = %39
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i16
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = getelementptr inbounds i16, ptr %50, i64 %51
  store i16 %49, ptr %52, align 2, !tbaa !12
  br label %53

53:                                               ; preds = %44
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %9, align 8, !tbaa !9
  br label %39, !llvm.loop !14

56:                                               ; preds = %39
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %9, align 8, !tbaa !9
  %59 = getelementptr inbounds i16, ptr %57, i64 %58
  store i16 0, ptr %59, align 2, !tbaa !12
  store i64 0, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %60

60:                                               ; preds = %56, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %61 = load i64, ptr %4, align 8
  ret i64 %61
}

declare i64 @AsciiStrSize(ptr noundef) #1

declare i64 @AsciiStrLen(ptr 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 = !{!13, !13, i64 0}
!13 = !{!"short", !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"

@.str = external hidden unnamed_addr constant [148 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [56 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775803, 1) i64 @ConvertToUnicodeText(ptr noundef writeonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %3
  %6 = icmp ne ptr %1, null
  %7 = icmp ne ptr %2, null
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %9, label %8

8:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 124, ptr noundef nonnull @.str.4) #2
  br label %9

9:                                                ; preds = %8, %5, %3
  %10 = tail call i64 @AsciiStrSize(ptr noundef %1) #2
  %11 = shl i64 %10, 1
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = icmp ult i64 %12, %11
  %14 = icmp eq ptr %0, null
  %or.cond3 = or i1 %14, %13
  br i1 %or.cond3, label %16, label %.preheader

.preheader:                                       ; preds = %9
  %15 = tail call i64 @AsciiStrLen(ptr noundef %1) #2
  %.not23 = icmp eq i64 %15, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

16:                                               ; preds = %9
  store i64 %11, ptr %2, align 8, !tbaa !5
  br label %25

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.022 = phi i64 [ %21, %.lr.ph ], [ 0, %.preheader ]
  %17 = getelementptr inbounds i8, ptr %1, i64 %.022
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i16
  %20 = getelementptr inbounds i16, ptr %0, i64 %.022
  store i16 %19, ptr %20, align 2, !tbaa !10
  %21 = add nuw i64 %.022, 1
  %22 = tail call i64 @AsciiStrLen(ptr noundef %1) #2
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %21, %.lr.ph ]
  %24 = getelementptr inbounds i16, ptr %0, i64 %.0.lcssa
  store i16 0, ptr %24, align 2, !tbaa !10
  br label %25

25:                                               ; preds = %._crit_edge, %16
  %.020 = phi i64 [ -9223372036854775803, %16 ], [ 0, %._crit_edge ]
  ret i64 %.020
}

declare i64 @AsciiStrSize(ptr noundef) local_unnamed_addr #0

declare i64 @AsciiStrLen(ptr noundef) local_unnamed_addr #0

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


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