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

; 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.libzpaq::ZPAQL" = type { ptr, ptr, %"class.libzpaq::Array.0", i32, i32, i32, [4 x i8], %"class.libzpaq::Array.0", %"class.libzpaq::Array", %"class.libzpaq::Array", %"class.libzpaq::Array.4", i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%"class.libzpaq::Array.0" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array.4" = type <{ ptr, i64, i32, [4 x i8] }>

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq5ZPAQL5writeEPNS_6WriterEb(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i1 noundef zeroext %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %7, align 1, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 2
  %13 = call noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %12)
  %14 = icmp ule i64 %13, 6
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %86

16:                                               ; preds = %3
  %17 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc i8 %17 to i1
  br i1 %18, label %41, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %37, %19
  %21 = load i32, ptr %8, align 4, !tbaa !13
  %22 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %40

26:                                               ; preds = %20
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 2
  %29 = load i32, ptr %8, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %28, i64 noundef %30)
  %32 = load i8, ptr %31, align 1, !tbaa !21
  %33 = zext i8 %32 to i32
  %34 = load ptr, ptr %27, align 8, !tbaa !22
  %35 = getelementptr inbounds ptr, ptr %34, i64 0
  %36 = load ptr, ptr %35, align 8
  call void %36(ptr noundef nonnull align 8 dereferenceable(8) %27, i32 noundef %33)
  br label %37

37:                                               ; preds = %26
  %38 = load i32, ptr %8, align 4, !tbaa !13
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %8, align 4, !tbaa !13
  br label %20, !llvm.loop !24

40:                                               ; preds = %25
  br label %62

41:                                               ; preds = %16
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 5
  %44 = load i32, ptr %43, align 8, !tbaa !26
  %45 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 4
  %46 = load i32, ptr %45, align 4, !tbaa !27
  %47 = sub nsw i32 %44, %46
  %48 = and i32 %47, 255
  %49 = load ptr, ptr %42, align 8, !tbaa !22
  %50 = getelementptr inbounds ptr, ptr %49, i64 0
  %51 = load ptr, ptr %50, align 8
  call void %51(ptr noundef nonnull align 8 dereferenceable(8) %42, i32 noundef %48)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 5
  %54 = load i32, ptr %53, align 8, !tbaa !26
  %55 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 4
  %56 = load i32, ptr %55, align 4, !tbaa !27
  %57 = sub nsw i32 %54, %56
  %58 = ashr i32 %57, 8
  %59 = load ptr, ptr %52, align 8, !tbaa !22
  %60 = getelementptr inbounds ptr, ptr %59, i64 0
  %61 = load ptr, ptr %60, align 8
  call void %61(ptr noundef nonnull align 8 dereferenceable(8) %52, i32 noundef %58)
  br label %62

62:                                               ; preds = %41, %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %63 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 4
  %64 = load i32, ptr %63, align 4, !tbaa !27
  store i32 %64, ptr %9, align 4, !tbaa !13
  br label %65

65:                                               ; preds = %82, %62
  %66 = load i32, ptr %9, align 4, !tbaa !13
  %67 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 5
  %68 = load i32, ptr %67, align 8, !tbaa !26
  %69 = icmp slt i32 %66, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %85

71:                                               ; preds = %65
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %11, i32 0, i32 2
  %74 = load i32, ptr %9, align 4, !tbaa !13
  %75 = sext i32 %74 to i64
  %76 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %73, i64 noundef %75)
  %77 = load i8, ptr %76, align 1, !tbaa !21
  %78 = zext i8 %77 to i32
  %79 = load ptr, ptr %72, align 8, !tbaa !22
  %80 = getelementptr inbounds ptr, ptr %79, i64 0
  %81 = load ptr, ptr %80, align 8
  call void %81(ptr noundef nonnull align 8 dereferenceable(8) %72, i32 noundef %78)
  br label %82

82:                                               ; preds = %71
  %83 = load i32, ptr %9, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %9, align 4, !tbaa !13
  br label %65, !llvm.loop !28

85:                                               ; preds = %70
  store i1 true, ptr %4, align 1
  br label %86

86:                                               ; preds = %85, %15
  %87 = load i1, ptr %4, align 1
  ret i1 %87
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 40}
!16 = !{!"_ZTSN7libzpaq5ZPAQLE", !6, i64 0, !6, i64 8, !17, i64 16, !14, i64 40, !14, i64 44, !14, i64 48, !17, i64 56, !19, i64 80, !19, i64 104, !20, i64 128, !14, i64 152, !14, i64 156, !14, i64 160, !14, i64 164, !14, i64 168, !14, i64 172, !14, i64 176, !14, i64 180, !6, i64 184}
!17 = !{!"_ZTSN7libzpaq5ArrayIhEE", !6, i64 0, !18, i64 8, !14, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSN7libzpaq5ArrayIjEE", !6, i64 0, !18, i64 8, !14, i64 16}
!20 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !18, i64 8, !14, i64 16}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!16, !14, i64 48}
!27 = !{!16, !14, i64 44}
!28 = distinct !{!28, !25}


; 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 noundef zeroext i1 @_ZN7libzpaq5ZPAQL5writeEPNS_6WriterEb(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = tail call noundef i64 @_ZNK7libzpaq5ArrayIhE4sizeEv(ptr noundef nonnull align 8 dereferenceable(20) %4)
  %6 = icmp ugt i64 %5, 6
  br i1 %6, label %7, label %.loopexit

7:                                                ; preds = %3
  br i1 %2, label %19, label %.preheader

.preheader:                                       ; preds = %7
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %.loopexit14

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %11 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %4, i64 noundef %indvars.iv)
  %12 = load i8, ptr %11, align 1, !tbaa !15
  %13 = zext i8 %12 to i32
  %14 = load ptr, ptr %1, align 8, !tbaa !16
  %15 = load ptr, ptr %14, align 8
  tail call void %15(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %13)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr %8, align 8, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %.loopexit14, !llvm.loop !18

19:                                               ; preds = %7
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = load i32, ptr %20, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %0, i64 44
  %23 = load i32, ptr %22, align 4, !tbaa !21
  %24 = sub nsw i32 %21, %23
  %25 = and i32 %24, 255
  %26 = load ptr, ptr %1, align 8, !tbaa !16
  %27 = load ptr, ptr %26, align 8
  tail call void %27(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %25)
  %28 = load i32, ptr %20, align 8, !tbaa !20
  %29 = load i32, ptr %22, align 4, !tbaa !21
  %30 = sub nsw i32 %28, %29
  %31 = ashr i32 %30, 8
  %32 = load ptr, ptr %1, align 8, !tbaa !16
  %33 = load ptr, ptr %32, align 8
  tail call void %33(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %31)
  br label %.loopexit14

.loopexit14:                                      ; preds = %.lr.ph, %.preheader, %19
  %34 = getelementptr inbounds i8, ptr %0, i64 44
  %35 = load i32, ptr %34, align 4, !tbaa !21
  %36 = getelementptr inbounds i8, ptr %0, i64 48
  %37 = load i32, ptr %36, align 8, !tbaa !20
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %.lr.ph17.preheader, label %.loopexit

.lr.ph17.preheader:                               ; preds = %.loopexit14
  %39 = sext i32 %35 to i64
  br label %.lr.ph17

.lr.ph17:                                         ; preds = %.lr.ph17.preheader, %.lr.ph17
  %indvars.iv19 = phi i64 [ %39, %.lr.ph17.preheader ], [ %indvars.iv.next20, %.lr.ph17 ]
  %40 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %4, i64 noundef %indvars.iv19)
  %41 = load i8, ptr %40, align 1, !tbaa !15
  %42 = zext i8 %41 to i32
  %43 = load ptr, ptr %1, align 8, !tbaa !16
  %44 = load ptr, ptr %43, align 8
  tail call void %44(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %42)
  %indvars.iv.next20 = add nsw i64 %indvars.iv19, 1
  %45 = load i32, ptr %36, align 8, !tbaa !20
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next20, %46
  br i1 %47, label %.lr.ph17, label %.loopexit, !llvm.loop !22

.loopexit:                                        ; preds = %.lr.ph17, %.loopexit14, %3
  ret i1 %6
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 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" }

!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, !12, i64 40}
!6 = !{!"_ZTSN7libzpaq5ZPAQLE", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 40, !12, i64 44, !12, i64 48, !10, i64 56, !13, i64 80, !13, i64 104, !14, i64 128, !12, i64 152, !12, i64 156, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172, !12, i64 176, !12, i64 180, !7, i64 184}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN7libzpaq5ArrayIhEE", !7, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_ZTSN7libzpaq5ArrayIjEE", !7, i64 0, !11, i64 8, !12, i64 16}
!14 = !{!"_ZTSN7libzpaq5ArrayIcEE", !7, i64 0, !11, i64 8, !12, i64 16}
!15 = !{!8, !8, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !9, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !12, i64 48}
!21 = !{!6, !12, i64 44}
!22 = distinct !{!22, !19}


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