; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/C (7zArcIn)

; 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.CSzArEx = type { %struct.CSzAr, i64, i64, i32, ptr, ptr, %struct.CSzBitUi32s, %struct.CSzBitUi32s, %struct.CSzBitUi64s, %struct.CSzBitUi64s, ptr, ptr, ptr, ptr }
%struct.CSzAr = type { i32, i32, ptr, %struct.CSzBitUi32s, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.CSzBitUi32s = type { ptr, ptr }
%struct.CSzBitUi64s = type { ptr, ptr }

; 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 i64 @SzArEx_GetFileNameUtf16(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.CSzArEx, ptr %11, i32 0, i32 12
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds i64, ptr %13, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !9
  store i64 %16, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.CSzArEx, ptr %17, i32 0, i32 12
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = add i64 %20, 1
  %22 = getelementptr inbounds i64, ptr %19, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = sub i64 %23, %24
  store i64 %25, ptr %8, align 8, !tbaa !9
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %52

28:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.CSzArEx, ptr %29, i32 0, i32 13
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = mul i64 %32, 2
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  store ptr %34, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %48, %28
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %39, label %51

39:                                               ; preds = %35
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = mul i64 %41, 2
  %43 = getelementptr inbounds i8, ptr %40, i64 %42
  %44 = load i16, ptr %43, align 2, !tbaa !18
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds i16, ptr %45, i64 %46
  store i16 %44, ptr %47, align 2, !tbaa !18
  br label %48

48:                                               ; preds = %39
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %9, align 8, !tbaa !9
  br label %35, !llvm.loop !20

51:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %52

52:                                               ; preds = %51, %3
  %53 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %53
}

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 = { 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", !7, i64 0}
!11 = !{!12, !6, i64 200}
!12 = !{!"", !13, i64 0, !16, i64 80, !16, i64 88, !14, i64 96, !6, i64 104, !6, i64 112, !15, i64 120, !15, i64 136, !15, i64 152, !15, i64 168, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208}
!13 = !{!"", !14, i64 0, !14, i64 4, !6, i64 8, !15, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 8}
!16 = !{!"long long", !7, i64 0}
!17 = !{!12, !6, i64 208}
!18 = !{!19, !19, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local i64 @SzArEx_GetFileNameUtf16(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %2 to i64
  %5 = getelementptr inbounds i8, ptr %0, i64 200
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i64, ptr %6, i64 %1
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %9 = getelementptr i8, ptr %7, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !14
  %11 = sub i64 %10, %8
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %12

12:                                               ; preds = %3
  %13 = getelementptr inbounds i8, ptr %0, i64 208
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = ptrtoint ptr %14 to i64
  %16 = shl i64 %8, 1
  %17 = getelementptr i8, ptr %14, i64 %16
  %.not17 = icmp eq i64 %10, %8
  br i1 %.not17, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %12
  %min.iters.check = icmp ult i64 %11, 16
  br i1 %min.iters.check, label %.lr.ph.preheader19, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %18 = add i64 %16, %15
  %19 = sub i64 %4, %18
  %diff.check = icmp ult i64 %19, 32
  br i1 %diff.check, label %.lr.ph.preheader19, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %11, -16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %20 = shl i64 %index, 1
  %21 = getelementptr inbounds i8, ptr %17, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <8 x i16>, ptr %21, align 2, !tbaa !17
  %wide.load18 = load <8 x i16>, ptr %22, align 2, !tbaa !17
  %23 = getelementptr inbounds i16, ptr %2, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <8 x i16> %wide.load, ptr %23, align 2, !tbaa !17
  store <8 x i16> %wide.load18, ptr %24, align 2, !tbaa !17
  %index.next = add nuw i64 %index, 16
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !19

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

.lr.ph.preheader19:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.016.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader19, %.lr.ph
  %.016 = phi i64 [ %30, %.lr.ph ], [ %.016.ph, %.lr.ph.preheader19 ]
  %26 = shl i64 %.016, 1
  %27 = getelementptr inbounds i8, ptr %17, i64 %26
  %28 = load i16, ptr %27, align 2, !tbaa !17
  %29 = getelementptr inbounds i16, ptr %2, i64 %.016
  store i16 %28, ptr %29, align 2, !tbaa !17
  %30 = add nuw i64 %.016, 1
  %exitcond.not = icmp eq i64 %30, %11
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !23

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %12, %3
  ret i64 %11
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !11, i64 200}
!6 = !{!"", !7, i64 0, !13, i64 80, !13, i64 88, !8, i64 96, !11, i64 104, !11, i64 112, !12, i64 120, !12, i64 136, !12, i64 152, !12, i64 168, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208}
!7 = !{!"", !8, i64 0, !8, i64 4, !11, i64 8, !12, i64 16, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 8}
!13 = !{!"long long", !9, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !9, i64 0}
!16 = !{!6, !11, i64 208}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !9, i64 0}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !21}


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