; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/enc (metablock)

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

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

38:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = call i64 @BrotliCalculateDistanceCodeLimit(i32 noundef 2147483644, i32 noundef %39, i32 noundef %40)
  store i64 %41, ptr %12, align 4
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = add i32 16, %42
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add i32 %44, 1
  %46 = shl i32 62, %45
  %47 = add i32 %43, %46
  store i32 %47, ptr %9, align 4, !tbaa !9
  %48 = getelementptr inbounds %struct.BrotliDistanceCodeLimit, ptr %12, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !15
  store i32 %49, ptr %10, align 4, !tbaa !9
  %50 = getelementptr inbounds %struct.BrotliDistanceCodeLimit, ptr %12, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !17
  store i32 %51, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %52

52:                                               ; preds = %38, %4
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.BrotliDistanceParams, ptr %54, i32 0, i32 2
  store i32 %53, ptr %55, align 8, !tbaa !18
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BrotliDistanceParams, ptr %57, i32 0, i32 3
  store i32 %56, ptr %58, align 4, !tbaa !19
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.BrotliDistanceParams, ptr %61, i32 0, i32 4
  store i64 %60, ptr %62, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @BrotliCalculateDistanceCodeLimit(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"BrotliDistanceParams", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!16, !10, i64 0}
!16 = !{!"BrotliDistanceCodeLimit", !10, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 4}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !10, i64 12}
!20 = !{!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
define hidden void @BrotliInitDistanceParams(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  store i32 %1, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %5, align 4, !tbaa !11
  %6 = add i32 %2, 16
  %7 = add i32 %1, 1
  %8 = shl i32 24, %7
  %9 = add i32 %6, %8
  %10 = add i32 %1, 26
  %11 = shl nuw i32 1, %10
  %12 = add i32 %11, %2
  %13 = add i32 %1, 2
  %.neg = shl nsw i32 -1, %13
  %14 = add i32 %12, %.neg
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %19, label %15

15:                                               ; preds = %4
  %16 = tail call i64 @BrotliCalculateDistanceCodeLimit(i32 noundef 2147483644, i32 noundef %1, i32 noundef %2)
  %.sroa.0.0.extract.trunc = trunc i64 %16 to i32
  %.sroa.4.0.extract.shift = lshr i64 %16, 32
  %.sroa.4.0.extract.trunc = trunc nuw i64 %.sroa.4.0.extract.shift to i32
  %17 = shl i32 62, %7
  %18 = add i32 %6, %17
  br label %19

19:                                               ; preds = %15, %4
  %.021 = phi i32 [ %.sroa.4.0.extract.trunc, %15 ], [ %14, %4 ]
  %.020 = phi i32 [ %.sroa.0.0.extract.trunc, %15 ], [ %9, %4 ]
  %.0 = phi i32 [ %18, %15 ], [ %9, %4 ]
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.0, ptr %20, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %.020, ptr %21, align 4, !tbaa !13
  %22 = zext i32 %.021 to i64
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %22, ptr %23, align 8, !tbaa !14
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @BrotliCalculateDistanceCodeLimit(i32 noundef, i32 noundef, i32 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 = { 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" }

!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 0}
!6 = !{!"BrotliDistanceParams", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !10, i64 16}


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