; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/Common/MyString.ll (ZN7AString20SetFromWStr_if_AsciiEPKw)

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

%class.AString = type { ptr, i32, i32 }

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #2

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

12:                                               ; preds = %29, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr %13, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %17, ptr %6, align 4, !tbaa !11
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %12
  store i32 2, ptr %7, align 4
  br label %26

21:                                               ; preds = %12
  %22 = load i32, ptr %6, align 4, !tbaa !11
  %23 = icmp sge i32 %22, 128
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 1, ptr %7, align 4
  br label %26

25:                                               ; preds = %21
  store i32 0, ptr %7, align 4
  br label %26

26:                                               ; preds = %25, %24, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %27 = load i32, ptr %7, align 4
  switch i32 %27, label %79 [
    i32 0, label %28
    i32 2, label %32
  ]

28:                                               ; preds = %26
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = add i32 %30, 1
  store i32 %31, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !13

32:                                               ; preds = %26
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = getelementptr inbounds %class.AString, ptr %11, i32 0, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = icmp ugt i32 %33, %35
  br i1 %36, label %37, label %51

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add i32 %38, 1
  %40 = zext i32 %39 to i64
  %41 = call noalias noundef nonnull ptr @_Znam(i64 noundef %40) #5
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %class.AString, ptr %11, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = icmp eq ptr %43, null
  br i1 %44, label %46, label %45

45:                                               ; preds = %37
  call void @_ZdaPv(ptr noundef %43) #6
  br label %46

46:                                               ; preds = %45, %37
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.AString, ptr %11, i32 0, i32 0
  store ptr %47, ptr %48, align 8, !tbaa !17
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = getelementptr inbounds %class.AString, ptr %11, i32 0, i32 2
  store i32 %49, ptr %50, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %51

51:                                               ; preds = %46, %32
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = getelementptr inbounds %class.AString, ptr %11, i32 0, i32 1
  store i32 %52, ptr %53, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %54 = getelementptr inbounds %class.AString, ptr %11, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  store ptr %55, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %71, %51
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = icmp ult i32 %57, %58
  br i1 %59, label %60, label %74

60:                                               ; preds = %56
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = trunc i32 %65 to i8
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  store i8 %66, ptr %70, align 1, !tbaa !19
  br label %71

71:                                               ; preds = %60
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %10, align 4, !tbaa !9
  br label %56, !llvm.loop !20

74:                                               ; preds = %56
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %75, i64 %77
  store i8 0, ptr %78, align 1, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  store i32 0, ptr %7, align 4
  br label %79

79:                                               ; preds = %74, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %80 = load i32, ptr %7, align 4
  switch i32 %80, label %82 [
    i32 0, label %81
    i32 1, label %81
  ]

81:                                               ; preds = %79, %79
  ret void

82:                                               ; preds = %79
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 = { nobuiltin 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 = { 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 #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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 = !{!"wchar_t", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 12}
!16 = !{!"_ZTS7AString", !6, i64 0, !10, i64 8, !10, i64 12}
!17 = !{!16, !6, i64 0}
!18 = !{!16, !10, i64 8}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !14}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7AString20SetFromWStr_if_AsciiEPKw(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 align 2 {
  br label %3

3:                                                ; preds = %9, %2
  %.020 = phi i32 [ 0, %2 ], [ %10, %9 ]
  %4 = zext i32 %.020 to i64
  %5 = getelementptr inbounds i32, ptr %1, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  %8 = icmp sgt i32 %6, 127
  %. = zext i1 %8 to i32
  %.021 = select i1 %7, i32 2, i32 %.
  switch i32 %.021, label %.loopexit [
    i32 0, label %9
    i32 2, label %11
  ]

9:                                                ; preds = %3
  %10 = add i32 %.020, 1
  br label %3, !llvm.loop !9

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp ugt i32 %.020, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %11
  %16 = add i32 %.020, 1
  %17 = zext i32 %16 to i64
  %18 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %17) #3
  %19 = load ptr, ptr %0, align 8, !tbaa !15
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %15
  tail call void @_ZdaPv(ptr noundef nonnull %19) #4
  br label %.thread

.thread:                                          ; preds = %15, %21
  store ptr %18, ptr %0, align 8, !tbaa !15
  store i32 %.020, ptr %12, align 4, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.020, ptr %22, align 8, !tbaa !16
  br label %.lr.ph.preheader

23:                                               ; preds = %11
  %.pre = load ptr, ptr %0, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.020, ptr %24, align 8, !tbaa !16
  %.not = icmp eq i32 %.020, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.thread, %23
  %25 = phi ptr [ %18, %.thread ], [ %.pre, %23 ]
  %min.iters.check = icmp ult i32 %.020, 12
  br i1 %min.iters.check, label %.lr.ph.preheader37, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %scevgep = getelementptr i8, ptr %25, i64 %4
  %26 = shl nuw nsw i64 %4, 2
  %scevgep35 = getelementptr i8, ptr %1, i64 %26
  %bound0 = icmp ult ptr %25, %scevgep35
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader37, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %4, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %27 = getelementptr inbounds i32, ptr %1, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load = load <4 x i32>, ptr %27, align 4, !tbaa !5, !alias.scope !17
  %wide.load36 = load <4 x i32>, ptr %28, align 4, !tbaa !5, !alias.scope !17
  %29 = trunc <4 x i32> %wide.load to <4 x i8>
  %30 = trunc <4 x i32> %wide.load36 to <4 x i8>
  %31 = getelementptr inbounds i8, ptr %25, i64 %index
  %32 = getelementptr inbounds i8, ptr %31, i64 4
  store <4 x i8> %29, ptr %31, align 1, !tbaa !20, !alias.scope !21, !noalias !17
  store <4 x i8> %30, ptr %32, align 1, !tbaa !20, !alias.scope !21, !noalias !17
  %index.next = add nuw i64 %index, 8
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !23

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %4
  br i1 %cmp.n, label %._crit_edge.loopexit, label %.lr.ph.preheader37

.lr.ph.preheader37:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %4, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader37, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader37 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader37 ]
  %34 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.prol
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = trunc i32 %35 to i8
  %37 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv.prol
  store i8 %36, ptr %37, align 1, !tbaa !20
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !26

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader37
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader37 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %38 = sub nsw i64 %indvars.iv.ph, %4
  %39 = icmp ugt i64 %38, -4
  br i1 %39, label %._crit_edge.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %40 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = trunc i32 %41 to i8
  %43 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv
  store i8 %42, ptr %43, align 1, !tbaa !20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = trunc i32 %45 to i8
  %47 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv.next
  store i8 %46, ptr %47, align 1, !tbaa !20
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %48 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.1
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = trunc i32 %49 to i8
  %51 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv.next.1
  store i8 %50, ptr %51, align 1, !tbaa !20
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %52 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.2
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = trunc i32 %53 to i8
  %55 = getelementptr inbounds i8, ptr %25, i64 %indvars.iv.next.2
  store i8 %54, ptr %55, align 1, !tbaa !20
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %4
  br i1 %exitcond.not.3, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !28

._crit_edge.loopexit:                             ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block
  %56 = zext i32 %.020 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %23, %._crit_edge.loopexit
  %57 = phi ptr [ %25, %._crit_edge.loopexit ], [ %.pre, %23 ]
  %.0.lcssa = phi i64 [ %56, %._crit_edge.loopexit ], [ 0, %23 ]
  %58 = getelementptr inbounds i8, ptr %57, i64 %.0.lcssa
  store i8 0, ptr %58, align 1, !tbaa !20
  br label %.loopexit

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

attributes #0 = { nobuiltin allocsize(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 = { nobuiltin 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 #2 = { 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 #3 = { builtin allocsize(0) }
attributes #4 = { builtin 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 = !{!"wchar_t", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !14, i64 12}
!12 = !{!"_ZTS7AString", !13, i64 0, !14, i64 8, !14, i64 12}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !13, i64 0}
!16 = !{!12, !14, i64 8}
!17 = !{!18}
!18 = distinct !{!18, !19}
!19 = distinct !{!19, !"LVerDomain"}
!20 = !{!7, !7, i64 0}
!21 = !{!22}
!22 = distinct !{!22, !19}
!23 = distinct !{!23, !10, !24, !25}
!24 = !{!"llvm.loop.isvectorized", i32 1}
!25 = !{!"llvm.loop.unroll.runtime.disable"}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.unroll.disable"}
!28 = distinct !{!28, !10, !24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass