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

; 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.BrotliEncoderStateStruct = type { %struct.BrotliEncoderParams, %struct.MemoryManager, ptr, i64, %struct.RingBuffer, i64, ptr, i64, i64, i64, i64, i64, [16 x i32], [4 x i32], i8, i8, i8, i8, i64, ptr, [1024 x i32], ptr, i64, [128 x i8], [128 x i16], [512 x i8], i64, ptr, ptr, ptr, i64, i64, %union.anon, i32, i32, i32, i32 }
%struct.BrotliEncoderParams = type { i32, i32, i32, i32, i64, i32, %struct.BrotliHasherParams }
%struct.BrotliHasherParams = type { i32, i32, i32, i32, i32 }
%struct.MemoryManager = type { ptr, ptr, ptr }
%struct.RingBuffer = type { i32, i32, i32, i32, i32, i32, ptr, ptr }
%union.anon = type { [2 x i64] }

; Function Attrs: nounwind uwtable
define dso_local i32 @BrotliEncoderIsFinished(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %3, i32 0, i32 34
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %12

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call i32 @BrotliEncoderHasMoreOutput(ptr noundef %8)
  %10 = icmp ne i32 %9, 0
  %11 = xor i1 %10, true
  br label %12

12:                                               ; preds = %7, %1
  %13 = phi i1 [ false, %1 ], [ %11, %7 ]
  %14 = xor i1 %13, true
  %15 = xor i1 %14, true
  %16 = zext i1 %15 to i64
  %17 = select i1 %15, i32 1, i32 0
  ret i32 %17
}

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

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

!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, !12, i64 5364}
!10 = !{!"BrotliEncoderStateStruct", !11, i64 0, !15, i64 48, !6, i64 72, !13, i64 80, !16, i64 88, !13, i64 128, !6, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !13, i64 176, !7, i64 184, !7, i64 248, !7, i64 264, !7, i64 265, !7, i64 266, !7, i64 267, !13, i64 272, !6, i64 280, !7, i64 288, !6, i64 4384, !13, i64 4392, !7, i64 4400, !7, i64 4528, !7, i64 4784, !13, i64 5296, !6, i64 5304, !6, i64 5312, !6, i64 5320, !13, i64 5328, !13, i64 5336, !7, i64 5344, !12, i64 5360, !12, i64 5364, !12, i64 5368, !12, i64 5372}
!11 = !{!"BrotliEncoderParams", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !13, i64 16, !12, i64 24, !14, i64 28}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"BrotliHasherParams", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!15 = !{!"MemoryManager", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"RingBuffer", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !6, i64 24, !6, i64 32}


; 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 dso_local range(i32 0, 2) i32 @BrotliEncoderIsFinished(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 5364
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = tail call i32 @BrotliEncoderHasMoreOutput(ptr noundef nonnull %0)
  %.not = icmp eq i32 %6, 0
  %7 = zext i1 %.not to i32
  br label %8

8:                                                ; preds = %5, %1
  %9 = phi i32 [ 0, %1 ], [ %7, %5 ]
  ret i32 %9
}

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

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

!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, !8, i64 5364}
!6 = !{!"BrotliEncoderStateStruct", !7, i64 0, !13, i64 48, !14, i64 72, !11, i64 80, !15, i64 88, !11, i64 128, !14, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !9, i64 184, !9, i64 248, !9, i64 264, !9, i64 265, !9, i64 266, !9, i64 267, !11, i64 272, !14, i64 280, !9, i64 288, !14, i64 4384, !11, i64 4392, !9, i64 4400, !9, i64 4528, !9, i64 4784, !11, i64 5296, !14, i64 5304, !14, i64 5312, !14, i64 5320, !11, i64 5328, !11, i64 5336, !9, i64 5344, !8, i64 5360, !8, i64 5364, !8, i64 5368, !8, i64 5372}
!7 = !{!"BrotliEncoderParams", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !11, i64 16, !8, i64 24, !12, i64 28}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"BrotliHasherParams", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16}
!13 = !{!"MemoryManager", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!"RingBuffer", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !8, i64 20, !14, i64 24, !14, i64 32}


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