; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/Common (StringConvert)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z25MultiByteToUnicodeString2R7UStringRK7AStringj(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN7UString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %14)
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef zeroext i1 @_ZNK7AString7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %15)
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  br label %72

18:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef i32 @_ZNK7AString3LenEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  %21 = zext i32 %20 to i64
  %22 = add i64 %21, 1
  %23 = mul i64 %22, 2
  store i64 %23, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i64, ptr %7, align 8, !tbaa !11
  %26 = trunc i64 %25 to i32
  %27 = call noundef ptr @_ZN7UString6GetBufEj(ptr noundef nonnull align 8 dereferenceable(16) %24, i32 noundef %26)
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %29)
  %31 = load i64, ptr %7, align 8, !tbaa !11
  %32 = call i64 @mbstowcs(ptr noundef %28, ptr noundef %30, i64 noundef %31) #4
  store i64 %32, ptr %9, align 8, !tbaa !11
  %33 = load i64, ptr %9, align 8, !tbaa !11
  %34 = icmp ne i64 %33, -1
  br i1 %34, label %35, label %39

35:                                               ; preds = %18
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %9, align 8, !tbaa !11
  %38 = trunc i64 %37 to i32
  call void @_ZN7UString17ReleaseBuf_SetEndEj(ptr noundef nonnull align 8 dereferenceable(16) %36, i32 noundef %38)
  store i32 1, ptr %10, align 4
  br label %70

39:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %40)
  store ptr %41, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %62, %39
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !13
  store i8 %47, ptr %13, align 1, !tbaa !13
  %48 = load i8, ptr %13, align 1, !tbaa !13
  %49 = zext i8 %48 to i32
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %42
  store i32 2, ptr %10, align 4
  br label %60

52:                                               ; preds = %42
  %53 = load i8, ptr %13, align 1, !tbaa !13
  %54 = zext i8 %53 to i32
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %11, align 4, !tbaa !9
  %58 = zext i32 %56 to i64
  %59 = getelementptr inbounds i32, ptr %55, i64 %58
  store i32 %54, ptr %59, align 4, !tbaa !14
  store i32 0, ptr %10, align 4
  br label %60

60:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  %61 = load i32, ptr %10, align 4
  switch i32 %61, label %73 [
    i32 0, label %62
    i32 2, label %63
  ]

62:                                               ; preds = %60
  br label %42, !llvm.loop !16

63:                                               ; preds = %60
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  store i32 0, ptr %67, align 4, !tbaa !14
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i32, ptr %11, align 4, !tbaa !9
  call void @_ZN7UString17ReleaseBuf_SetLenEj(ptr noundef nonnull align 8 dereferenceable(16) %68, i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  store i32 0, ptr %10, align 4
  br label %70

70:                                               ; preds = %63, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %71 = load i32, ptr %10, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70, %17
  ret void

73:                                               ; preds = %70, %60
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7AString7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7AString3LenEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7UString6GetBufEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #0 align 2

; Function Attrs: nounwind
declare i64 @mbstowcs(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UString17ReleaseBuf_SetEndEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UString17ReleaseBuf_SetLenEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

attributes #0 = { mustprogress 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 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"wchar_t", !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"

; Function Attrs: mustprogress uwtable
define dso_local void @_Z25MultiByteToUnicodeString2R7UStringRK7AStringj(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1, i32 noundef %2) local_unnamed_addr #0 {
  tail call void @_ZN7UString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %4 = tail call noundef zeroext i1 @_ZNK7AString7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  br i1 %4, label %31, label %5

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZNK7AString3LenEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 1
  %9 = add nuw nsw i64 %8, 2
  %10 = trunc i64 %9 to i32
  %11 = tail call noundef ptr @_ZN7UString6GetBufEj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %10)
  %12 = tail call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %13 = tail call i64 @mbstowcs(ptr noundef %11, ptr noundef %12, i64 noundef %9) #3
  %.not = icmp eq i64 %13, -1
  br i1 %.not, label %16, label %14

14:                                               ; preds = %5
  %15 = trunc i64 %13 to i32
  tail call void @_ZN7UString17ReleaseBuf_SetEndEj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %15)
  br label %31

16:                                               ; preds = %5
  %17 = tail call noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = icmp eq i8 %18, 0
  br i1 %19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %16, %.lr.ph
  %20 = phi i8 [ %27, %.lr.ph ], [ %18, %16 ]
  %21 = phi i64 [ %25, %.lr.ph ], [ 0, %16 ]
  %.02229 = phi i32 [ %23, %.lr.ph ], [ 0, %16 ]
  %22 = zext i8 %20 to i32
  %23 = add i32 %.02229, 1
  %24 = getelementptr inbounds i32, ptr %11, i64 %21
  store i32 %22, ptr %24, align 4, !tbaa !8
  %25 = zext i32 %23 to i64
  %26 = getelementptr inbounds i8, ptr %17, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = icmp eq i8 %27, 0
  br i1 %28, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %16
  %.022.lcssa = phi i32 [ 0, %16 ], [ %23, %.lr.ph ]
  %29 = zext i32 %.022.lcssa to i64
  %30 = getelementptr inbounds i32, ptr %11, i64 %29
  store i32 0, ptr %30, align 4, !tbaa !8
  tail call void @_ZN7UString17ReleaseBuf_SetLenEj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.022.lcssa)
  br label %31

31:                                               ; preds = %14, %._crit_edge, %3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UString5EmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7AString7IsEmptyEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7AString3LenEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7UString6GetBufEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7AStringcvPKcEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UString17ReleaseBuf_SetEndEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7UString17ReleaseBuf_SetLenEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress 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 = { mustprogress 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 "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"wchar_t", !6, i64 0}


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