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

; 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.BrotliEncoderParams = type { i32, i32, i32, i32, i64, i32, %struct.BrotliHasherParams }
%struct.BrotliHasherParams = type { i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare hidden void @BrotliInitZopfliNodes(ptr noundef, i64 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

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

; Function Attrs: nounwind uwtable
declare hidden i64 @BrotliZopfliComputeShortestPath(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define hidden void @BrotliCreateZopfliBackwardReferences(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr noundef %11, ptr noundef %12) #0 {
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca ptr, align 8
  %26 = alloca ptr, align 8
  %27 = alloca i64, align 8
  %28 = alloca ptr, align 8
  store ptr %0, ptr %14, align 8, !tbaa !5
  store ptr %1, ptr %15, align 8, !tbaa !5
  store i64 %2, ptr %16, align 8, !tbaa !9
  store i64 %3, ptr %17, align 8, !tbaa !9
  store ptr %4, ptr %18, align 8, !tbaa !5
  store i64 %5, ptr %19, align 8, !tbaa !9
  store ptr %6, ptr %20, align 8, !tbaa !5
  store ptr %7, ptr %21, align 8, !tbaa !5
  store ptr %8, ptr %22, align 8, !tbaa !5
  store ptr %9, ptr %23, align 8, !tbaa !5
  store ptr %10, ptr %24, align 8, !tbaa !5
  store ptr %11, ptr %25, align 8, !tbaa !5
  store ptr %12, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #3
  %29 = load ptr, ptr %20, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = shl i64 1, %32
  %34 = sub i64 %33, 16
  store i64 %34, ptr %27, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #3
  %35 = load i64, ptr %16, align 8, !tbaa !9
  %36 = add i64 %35, 1
  %37 = icmp ugt i64 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %13
  %39 = load ptr, ptr %14, align 8, !tbaa !5
  %40 = load i64, ptr %16, align 8, !tbaa !9
  %41 = add i64 %40, 1
  %42 = mul i64 %41, 16
  %43 = call ptr @BrotliAllocate(ptr noundef %39, i64 noundef %42)
  br label %45

44:                                               ; preds = %13
  br label %45

45:                                               ; preds = %44, %38
  %46 = phi ptr [ %43, %38 ], [ null, %44 ]
  store ptr %46, ptr %28, align 8, !tbaa !5
  %47 = load ptr, ptr %28, align 8, !tbaa !5
  %48 = load i64, ptr %16, align 8, !tbaa !9
  %49 = add i64 %48, 1
  call void @BrotliInitZopfliNodes(ptr noundef %47, i64 noundef %49)
  %50 = load ptr, ptr %14, align 8, !tbaa !5
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = load i64, ptr %16, align 8, !tbaa !9
  %53 = load i64, ptr %17, align 8, !tbaa !9
  %54 = load ptr, ptr %18, align 8, !tbaa !5
  %55 = load i64, ptr %19, align 8, !tbaa !9
  %56 = load ptr, ptr %20, align 8, !tbaa !5
  %57 = load i64, ptr %27, align 8, !tbaa !9
  %58 = load ptr, ptr %22, align 8, !tbaa !5
  %59 = load ptr, ptr %21, align 8, !tbaa !5
  %60 = load ptr, ptr %28, align 8, !tbaa !5
  %61 = call i64 @BrotliZopfliComputeShortestPath(ptr noundef %50, ptr noundef %51, i64 noundef %52, i64 noundef %53, ptr noundef %54, i64 noundef %55, ptr noundef %56, i64 noundef %57, ptr noundef %58, ptr noundef %59, ptr noundef %60)
  %62 = load ptr, ptr %25, align 8, !tbaa !5
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = add i64 %63, %61
  store i64 %64, ptr %62, align 8, !tbaa !9
  %65 = load i64, ptr %16, align 8, !tbaa !9
  %66 = load i64, ptr %17, align 8, !tbaa !9
  %67 = load i64, ptr %27, align 8, !tbaa !9
  %68 = load ptr, ptr %28, align 8, !tbaa !5
  %69 = load ptr, ptr %22, align 8, !tbaa !5
  %70 = load ptr, ptr %23, align 8, !tbaa !5
  %71 = load ptr, ptr %20, align 8, !tbaa !5
  %72 = load ptr, ptr %24, align 8, !tbaa !5
  %73 = load ptr, ptr %26, align 8, !tbaa !5
  call void @BrotliZopfliCreateCommands(i64 noundef %65, i64 noundef %66, i64 noundef %67, ptr noundef %68, ptr noundef %69, ptr noundef %70, ptr noundef %71, ptr noundef %72, ptr noundef %73)
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  %75 = load ptr, ptr %28, align 8, !tbaa !5
  call void @BrotliFree(ptr noundef %74, ptr noundef %75)
  store ptr null, ptr %28, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #3
  ret void
}

declare hidden ptr @BrotliAllocate(ptr noundef, i64 noundef) #2

declare hidden void @BrotliFree(ptr noundef, ptr noundef) #2

attributes #0 = { 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 = { 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, !13, i64 8}
!12 = !{!"BrotliEncoderParams", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !10, i64 16, !13, i64 24, !14, i64 28}
!13 = !{!"int", !7, i64 0}
!14 = !{!"BrotliHasherParams", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16}


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

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

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

; Function Attrs: nounwind uwtable
define hidden void @BrotliCreateZopfliBackwardReferences(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr nocapture noundef %11, ptr noundef %12) local_unnamed_addr #0 {
  %14 = getelementptr inbounds i8, ptr %6, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !5
  %16 = add i64 %2, 1
  %.not = icmp eq i64 %16, 0
  br i1 %.not, label %20, label %17

17:                                               ; preds = %13
  %18 = shl i64 %16, 4
  %19 = tail call ptr @BrotliAllocate(ptr noundef %0, i64 noundef %18) #2
  br label %20

20:                                               ; preds = %13, %17
  %21 = phi ptr [ %19, %17 ], [ null, %13 ]
  %22 = zext nneg i32 %15 to i64
  %23 = shl nuw i64 1, %22
  %24 = add i64 %23, -16
  tail call void @BrotliInitZopfliNodes(ptr noundef %21, i64 noundef %16)
  %25 = tail call i64 @BrotliZopfliComputeShortestPath(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef nonnull %6, i64 noundef %24, ptr noundef %8, ptr noundef %7, ptr noundef %21)
  %26 = load i64, ptr %11, align 8, !tbaa !12
  %27 = add i64 %26, %25
  store i64 %27, ptr %11, align 8, !tbaa !12
  tail call void @BrotliZopfliCreateCommands(i64 noundef %2, i64 noundef %3, i64 noundef %24, ptr noundef %21, ptr noundef %8, ptr noundef %9, ptr noundef nonnull %6, ptr noundef %10, ptr noundef %12)
  tail call void @BrotliFree(ptr noundef %0, ptr noundef %21) #2
  ret void
}

declare hidden ptr @BrotliAllocate(ptr noundef, i64 noundef) local_unnamed_addr #1

declare hidden void @BrotliFree(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 = { 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, !7, i64 8}
!6 = !{!"BrotliEncoderParams", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !11, i64 28}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"BrotliHasherParams", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!12 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass