; LLVM IR from itchio/go-brotli :: enc (brotli_bit_stream)

; 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: 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: alwaysinline nounwind uwtable
declare hidden void @BrotliWriteBits(i64 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden void @JumpToByteBoundary(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define hidden void @BrotliStoreUncompressedMetaBlock(i32 noundef %0, ptr noalias noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noalias noundef %5, ptr noalias noundef %6) #3 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !11
  store i64 %3, ptr %11, align 8, !tbaa !11
  store i64 %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %17 = load i64, ptr %10, align 8, !tbaa !11
  %18 = load i64, ptr %11, align 8, !tbaa !11
  %19 = and i64 %17, %18
  store i64 %19, ptr %15, align 8, !tbaa !11
  %20 = load i64, ptr %12, align 8, !tbaa !11
  %21 = load ptr, ptr %13, align 8, !tbaa !9
  %22 = load ptr, ptr %14, align 8, !tbaa !9
  call void @BrotliStoreUncompressedMetaBlockHeader(i64 noundef %20, ptr noundef %21, ptr noundef %22)
  %23 = load ptr, ptr %13, align 8, !tbaa !9
  %24 = load ptr, ptr %14, align 8, !tbaa !9
  call void @JumpToByteBoundary(ptr noundef %23, ptr noundef %24)
  %25 = load i64, ptr %15, align 8, !tbaa !11
  %26 = load i64, ptr %12, align 8, !tbaa !11
  %27 = add i64 %25, %26
  %28 = load i64, ptr %11, align 8, !tbaa !11
  %29 = add i64 %28, 1
  %30 = icmp ugt i64 %27, %29
  br i1 %30, label %31, label %53

31:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %32 = load i64, ptr %11, align 8, !tbaa !11
  %33 = add i64 %32, 1
  %34 = load i64, ptr %15, align 8, !tbaa !11
  %35 = sub i64 %33, %34
  store i64 %35, ptr %16, align 8, !tbaa !11
  %36 = load ptr, ptr %14, align 8, !tbaa !9
  %37 = load ptr, ptr %13, align 8, !tbaa !9
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = lshr i64 %38, 3
  %40 = getelementptr inbounds i8, ptr %36, i64 %39
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = load i64, ptr %15, align 8, !tbaa !11
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  %44 = load i64, ptr %16, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %40, ptr align 1 %43, i64 %44, i1 false)
  %45 = load i64, ptr %16, align 8, !tbaa !11
  %46 = shl i64 %45, 3
  %47 = load ptr, ptr %13, align 8, !tbaa !9
  %48 = load i64, ptr %47, align 8, !tbaa !11
  %49 = add i64 %48, %46
  store i64 %49, ptr %47, align 8, !tbaa !11
  %50 = load i64, ptr %16, align 8, !tbaa !11
  %51 = load i64, ptr %12, align 8, !tbaa !11
  %52 = sub i64 %51, %50
  store i64 %52, ptr %12, align 8, !tbaa !11
  store i64 0, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %53

53:                                               ; preds = %31, %7
  %54 = load ptr, ptr %14, align 8, !tbaa !9
  %55 = load ptr, ptr %13, align 8, !tbaa !9
  %56 = load i64, ptr %55, align 8, !tbaa !11
  %57 = lshr i64 %56, 3
  %58 = getelementptr inbounds i8, ptr %54, i64 %57
  %59 = load ptr, ptr %9, align 8, !tbaa !9
  %60 = load i64, ptr %15, align 8, !tbaa !11
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  %62 = load i64, ptr %12, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %58, ptr align 1 %61, i64 %62, i1 false)
  %63 = load i64, ptr %12, align 8, !tbaa !11
  %64 = shl i64 %63, 3
  %65 = load ptr, ptr %13, align 8, !tbaa !9
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = add i64 %66, %64
  store i64 %67, ptr %65, align 8, !tbaa !11
  %68 = load ptr, ptr %13, align 8, !tbaa !9
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = load ptr, ptr %14, align 8, !tbaa !9
  call void @BrotliWriteBitsPrepareStorage(i64 noundef %69, ptr noundef %70)
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %80

73:                                               ; preds = %53
  %74 = load ptr, ptr %13, align 8, !tbaa !9
  %75 = load ptr, ptr %14, align 8, !tbaa !9
  call void @BrotliWriteBits(i64 noundef 1, i64 noundef 1, ptr noundef %74, ptr noundef %75)
  %76 = load ptr, ptr %13, align 8, !tbaa !9
  %77 = load ptr, ptr %14, align 8, !tbaa !9
  call void @BrotliWriteBits(i64 noundef 1, i64 noundef 1, ptr noundef %76, ptr noundef %77)
  %78 = load ptr, ptr %13, align 8, !tbaa !9
  %79 = load ptr, ptr %14, align 8, !tbaa !9
  call void @JumpToByteBoundary(ptr noundef %78, ptr noundef %79)
  br label %80

80:                                               ; preds = %73, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @BrotliStoreUncompressedMetaBlockHeader(i64 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @BrotliWriteBitsPrepareStorage(i64 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


; 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: alwaysinline nounwind uwtable
declare hidden void @BrotliWriteBits(i64 noundef, i64 noundef, ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden void @JumpToByteBoundary(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define hidden void @BrotliStoreUncompressedMetaBlock(i32 noundef %0, ptr noalias nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noalias noundef %5, ptr noalias noundef %6) local_unnamed_addr #2 {
  %8 = and i64 %3, %2
  tail call void @BrotliStoreUncompressedMetaBlockHeader(i64 noundef %4, ptr noundef %5, ptr noundef %6)
  tail call void @JumpToByteBoundary(ptr noundef %5, ptr noundef %6)
  %9 = add i64 %8, %4
  %10 = add i64 %3, 1
  %11 = icmp ugt i64 %9, %10
  %.pre = load i64, ptr %5, align 8, !tbaa !5
  br i1 %11, label %12, label %20

12:                                               ; preds = %7
  %13 = sub i64 %10, %8
  %14 = lshr i64 %.pre, 3
  %15 = getelementptr inbounds i8, ptr %6, i64 %14
  %16 = getelementptr inbounds i8, ptr %1, i64 %8
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr align 1 %16, i64 %13, i1 false)
  %17 = shl i64 %13, 3
  %18 = add i64 %.pre, %17
  %19 = sub i64 %4, %13
  br label %20

20:                                               ; preds = %12, %7
  %21 = phi i64 [ %18, %12 ], [ %.pre, %7 ]
  %.036 = phi i64 [ 0, %12 ], [ %8, %7 ]
  %.0 = phi i64 [ %19, %12 ], [ %4, %7 ]
  %22 = lshr i64 %21, 3
  %23 = getelementptr inbounds i8, ptr %6, i64 %22
  %24 = getelementptr inbounds i8, ptr %1, i64 %.036
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 %24, i64 %.0, i1 false)
  %25 = shl i64 %.0, 3
  %26 = add i64 %21, %25
  store i64 %26, ptr %5, align 8, !tbaa !5
  tail call void @BrotliWriteBitsPrepareStorage(i64 noundef %26, ptr noundef %6)
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %28, label %27

27:                                               ; preds = %20
  tail call void @BrotliWriteBits(i64 noundef 1, i64 noundef 1, ptr noundef nonnull %5, ptr noundef %6)
  tail call void @BrotliWriteBits(i64 noundef 1, i64 noundef 1, ptr noundef nonnull %5, ptr noundef %6)
  tail call void @JumpToByteBoundary(ptr noundef nonnull %5, ptr noundef %6)
  br label %28

28:                                               ; preds = %27, %20
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @BrotliStoreUncompressedMetaBlockHeader(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @BrotliWriteBitsPrepareStorage(i64 noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { alwaysinline 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass