; LLVM IR from fwip/fastqz :: libzpaq.ll (ZN7libzpaq10Compressor10startBlockEi)

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

@_ZZN7libzpaq10Compressor10startBlockEiE6models = external hidden constant [299 x i8], align 16
@.str.37 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef) #0

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

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

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq10Compressor10startBlockEi(ptr noundef nonnull align 8 dereferenceable(110868) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.37)
  br label %11

11:                                               ; preds = %10, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr @_ZZN7libzpaq10Compressor10startBlockEiE6models, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %29, %11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %17)
  %19 = icmp ne i32 %18, 0
  br label %20

20:                                               ; preds = %16, %12
  %21 = phi i1 [ false, %12 ], [ %19, %16 ]
  br i1 %21, label %22, label %32

22:                                               ; preds = %20
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %23)
  %25 = add nsw i32 %24, 2
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  store ptr %28, ptr %5, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %22
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !11

32:                                               ; preds = %20
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %33)
  %35 = icmp slt i32 %34, 1
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.38)
  br label %37

37:                                               ; preds = %36, %32
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN7libzpaq10Compressor10startBlockEPKc(ptr noundef nonnull align 8 dereferenceable(110868) %7, ptr noundef %38)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7libzpaq10Compressor10startBlockEPKc(ptr noundef nonnull align 8 dereferenceable(110868), ptr noundef) #3 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }

!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 = distinct !{!11, !12}
!12 = !{!"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"

@_ZZN7libzpaq10Compressor10startBlockEiE6models = external hidden constant [299 x i8], align 16
@.str.37 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef) local_unnamed_addr #0

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq10Compressor10startBlockEi(ptr noundef nonnull align 8 dereferenceable(110868) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = icmp slt i32 %1, 1
  br i1 %3, label %.thread, label %4

.thread:                                          ; preds = %2
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.37)
  br label %.critedge

4:                                                ; preds = %2
  %.not14 = icmp eq i32 %1, 1
  br i1 %.not14, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %6
  %.011 = phi i32 [ %11, %6 ], [ 1, %4 ]
  %.0910 = phi ptr [ %10, %6 ], [ @_ZZN7libzpaq10Compressor10startBlockEiE6models, %4 ]
  %5 = tail call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %.0910)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.critedge, label %6

6:                                                ; preds = %.lr.ph
  %7 = tail call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %.0910)
  %8 = add nsw i32 %7, 2
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %.0910, i64 %9
  %11 = add nuw nsw i32 %.011, 1
  %exitcond.not = icmp eq i32 %11, %1
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %6, %.thread, %4
  %.09.lcssa = phi ptr [ @_ZZN7libzpaq10Compressor10startBlockEiE6models, %4 ], [ @_ZZN7libzpaq10Compressor10startBlockEiE6models, %.thread ], [ %10, %6 ], [ %.0910, %.lr.ph ]
  %12 = tail call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %.09.lcssa)
  %13 = icmp slt i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %.critedge
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.38)
  br label %15

15:                                               ; preds = %14, %.critedge
  tail call void @_ZN7libzpaq10Compressor10startBlockEPKc(ptr noundef nonnull align 8 dereferenceable(110868) %0, ptr noundef %.09.lcssa)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7libzpaq10Compressor10startBlockEPKc(ptr noundef nonnull align 8 dereferenceable(110868), ptr noundef) local_unnamed_addr #2 align 2

attributes #0 = { 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 #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 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass