; LLVM IR from itchio/go-brotli :: dec (decode)

; 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.BrotliDecoderStateStruct = type { i32, i32, %struct.BrotliBitReader, ptr, ptr, ptr, %union.anon, i32, i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.HuffmanTreeGroup, %struct.HuffmanTreeGroup, %struct.HuffmanTreeGroup, ptr, ptr, i32, i32, i32, i32, [3 x i32], [3 x i32], [6 x i32], i32, i32, i32, i32, ptr, ptr, i8, i32, i32, i32, i32, i64, i64, i32, i32, i32, [32 x %struct.HuffmanCode], ptr, [720 x i16], [32 x i32], [18 x i8], [16 x i16], i32, ptr, i32, i32, i32, [646 x %struct.HuffmanCode], i32, [65 x i32], i32, i32, i32, i32, i32, i32, i32, i16, i32, i32, i32, ptr, ptr, ptr, [8 x i32] }
%struct.BrotliBitReader = type { i64, i32, ptr, i64 }
%union.anon = type { i64 }
%struct.HuffmanTreeGroup = type { ptr, ptr, i16, i16 }
%struct.HuffmanCode = type { i8, i16 }

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

8:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  br label %24

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.BrotliDecoderStateStruct, ptr %10, i32 0, i32 17
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %18

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call i64 @UnwrittenBytes(ptr noundef %15, i32 noundef 0)
  %17 = icmp ne i64 %16, 0
  br label %18

18:                                               ; preds = %14, %9
  %19 = phi i1 [ false, %9 ], [ %17, %14 ]
  %20 = xor i1 %19, true
  %21 = xor i1 %20, true
  %22 = zext i1 %21 to i64
  %23 = select i1 %21, i32 1, i32 0
  store i32 %23, ptr %2, align 4
  br label %24

24:                                               ; preds = %18, %8
  %25 = load i32, ptr %2, align 4
  ret i32 %25
}

; Function Attrs: nounwind uwtable
declare hidden i64 @UnwrittenBytes(ptr noundef, i32 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, !11, i64 116}
!10 = !{!"BrotliDecoderStateStruct", !11, i64 0, !11, i64 4, !12, i64 8, !6, i64 40, !6, i64 48, !6, i64 56, !7, i64 64, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !7, i64 100, !11, i64 116, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !14, i64 184, !14, i64 208, !14, i64 232, !6, i64 256, !6, i64 264, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !7, i64 288, !7, i64 300, !7, i64 312, !11, i64 336, !11, i64 340, !11, i64 344, !11, i64 348, !6, i64 352, !6, i64 360, !7, i64 368, !11, i64 372, !11, i64 376, !11, i64 380, !11, i64 384, !13, i64 392, !13, i64 400, !11, i64 408, !11, i64 412, !11, i64 416, !7, i64 420, !6, i64 552, !7, i64 560, !7, i64 2000, !7, i64 2128, !7, i64 2146, !11, i64 2180, !6, i64 2184, !11, i64 2192, !11, i64 2196, !11, i64 2200, !7, i64 2204, !11, i64 4788, !7, i64 4792, !11, i64 5052, !11, i64 5056, !11, i64 5060, !11, i64 5064, !11, i64 5068, !11, i64 5072, !11, i64 5076, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5080, !11, i64 5084, !11, i64 5088, !11, i64 5092, !6, i64 5096, !6, i64 5104, !6, i64 5112, !7, i64 5120}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0, !11, i64 8, !6, i64 16, !13, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !15, i64 16, !15, i64 18}
!15 = !{!"short", !7, i64 0}
!16 = !{!10, !6, i64 128}


; 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 @BrotliDecoderHasMoreOutput(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 116
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 0
  br i1 %4, label %12, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 128
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %12, label %8

8:                                                ; preds = %5
  %9 = tail call i64 @UnwrittenBytes(ptr noundef nonnull %0, i32 noundef 0)
  %10 = icmp ne i64 %9, 0
  %11 = zext i1 %10 to i32
  br label %12

12:                                               ; preds = %5, %8, %1
  %.0 = phi i32 [ 0, %1 ], [ 0, %5 ], [ %11, %8 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @UnwrittenBytes(ptr noundef, i32 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, !7, i64 116}
!6 = !{!"BrotliDecoderStateStruct", !7, i64 0, !7, i64 4, !10, i64 8, !12, i64 40, !12, i64 48, !12, i64 56, !8, i64 64, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !8, i64 100, !7, i64 116, !7, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !13, i64 184, !13, i64 208, !13, i64 232, !12, i64 256, !12, i64 264, !7, i64 272, !7, i64 276, !7, i64 280, !7, i64 284, !8, i64 288, !8, i64 300, !8, i64 312, !7, i64 336, !7, i64 340, !7, i64 344, !7, i64 348, !12, i64 352, !12, i64 360, !8, i64 368, !7, i64 372, !7, i64 376, !7, i64 380, !7, i64 384, !11, i64 392, !11, i64 400, !7, i64 408, !7, i64 412, !7, i64 416, !8, i64 420, !12, i64 552, !8, i64 560, !8, i64 2000, !8, i64 2128, !8, i64 2146, !7, i64 2180, !12, i64 2184, !7, i64 2192, !7, i64 2196, !7, i64 2200, !8, i64 2204, !7, i64 4788, !8, i64 4792, !7, i64 5052, !7, i64 5056, !7, i64 5060, !7, i64 5064, !7, i64 5068, !7, i64 5072, !7, i64 5076, !7, i64 5080, !7, i64 5080, !7, i64 5080, !7, i64 5080, !7, i64 5080, !7, i64 5080, !7, i64 5084, !7, i64 5088, !7, i64 5092, !12, i64 5096, !12, i64 5104, !12, i64 5112, !8, i64 5120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !7, i64 8, !12, i64 16, !11, i64 24}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 8, !14, i64 16, !14, i64 18}
!14 = !{!"short", !8, i64 0}
!15 = !{!6, !12, i64 128}


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