; 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 @BrotliEncoderSetParameter(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, 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
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %8, i32 0, i32 36
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  br label %61

13:                                               ; preds = %3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %14, label %60 [
    i32 0, label %15
    i32 1, label %20
    i32 2, label %25
    i32 3, label %30
    i32 4, label %35
    i32 5, label %54
  ]

15:                                               ; preds = %13
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %18, i32 0, i32 0
  store i32 %16, ptr %19, align 8, !tbaa !18
  store i32 1, ptr %4, align 4
  br label %61

20:                                               ; preds = %13
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %23, i32 0, i32 1
  store i32 %21, ptr %24, align 4, !tbaa !19
  store i32 1, ptr %4, align 4
  br label %61

25:                                               ; preds = %13
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %28, i32 0, i32 2
  store i32 %26, ptr %29, align 8, !tbaa !20
  store i32 1, ptr %4, align 4
  br label %61

30:                                               ; preds = %13
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %33, i32 0, i32 3
  store i32 %31, ptr %34, align 4, !tbaa !21
  store i32 1, ptr %4, align 4
  br label %61

35:                                               ; preds = %13
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %42

38:                                               ; preds = %35
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i32 0, ptr %4, align 4
  br label %61

42:                                               ; preds = %38, %35
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 0
  %45 = xor i1 %44, true
  %46 = xor i1 %45, true
  %47 = xor i1 %46, true
  %48 = xor i1 %47, true
  %49 = zext i1 %48 to i64
  %50 = select i1 %48, i32 1, i32 0
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %52, i32 0, i32 5
  store i32 %50, ptr %53, align 8, !tbaa !22
  store i32 1, ptr %4, align 4
  br label %61

54:                                               ; preds = %13
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BrotliEncoderStateStruct, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %struct.BrotliEncoderParams, ptr %58, i32 0, i32 4
  store i64 %56, ptr %59, align 8, !tbaa !23
  store i32 1, ptr %4, align 4
  br label %61

60:                                               ; preds = %13
  store i32 0, ptr %4, align 4
  br label %61

61:                                               ; preds = %60, %54, %42, %41, %30, %25, %20, %15, %12
  %62 = load i32, ptr %4, align 4
  ret i32 %62
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 5372}
!12 = !{!"BrotliEncoderStateStruct", !13, i64 0, !16, i64 48, !6, i64 72, !14, i64 80, !17, i64 88, !14, i64 128, !6, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !14, i64 176, !7, i64 184, !7, i64 248, !7, i64 264, !7, i64 265, !7, i64 266, !7, i64 267, !14, i64 272, !6, i64 280, !7, i64 288, !6, i64 4384, !14, i64 4392, !7, i64 4400, !7, i64 4528, !7, i64 4784, !14, i64 5296, !6, i64 5304, !6, i64 5312, !6, i64 5320, !14, i64 5328, !14, i64 5336, !7, i64 5344, !10, i64 5360, !10, i64 5364, !10, i64 5368, !10, i64 5372}
!13 = !{!"BrotliEncoderParams", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !10, i64 24, !15, i64 28}
!14 = !{!"long", !7, i64 0}
!15 = !{!"BrotliHasherParams", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!16 = !{!"MemoryManager", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"RingBuffer", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32}
!18 = !{!12, !10, i64 0}
!19 = !{!12, !10, i64 4}
!20 = !{!12, !10, i64 8}
!21 = !{!12, !10, i64 12}
!22 = !{!12, !10, i64 24}
!23 = !{!12, !14, 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @BrotliEncoderSetParameter(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 5372
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %20

6:                                                ; preds = %3
  switch i32 %1, label %20 [
    i32 0, label %7
    i32 1, label %8
    i32 2, label %10
    i32 3, label %12
    i32 4, label %14
    i32 5, label %17
  ]

7:                                                ; preds = %6
  store i32 %2, ptr %0, align 8, !tbaa !16
  br label %20

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %9, align 4, !tbaa !17
  br label %20

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %11, align 8, !tbaa !18
  br label %20

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %2, ptr %13, align 4, !tbaa !19
  br label %20

14:                                               ; preds = %6
  %or.cond = icmp ugt i32 %2, 1
  br i1 %or.cond, label %20, label %15

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %2, ptr %16, align 8, !tbaa !20
  br label %20

17:                                               ; preds = %6
  %18 = zext i32 %2 to i64
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %18, ptr %19, align 8, !tbaa !21
  br label %20

20:                                               ; preds = %6, %14, %3, %17, %15, %12, %10, %8, %7
  %.0 = phi i32 [ 1, %17 ], [ 1, %15 ], [ 1, %12 ], [ 1, %10 ], [ 1, %8 ], [ 1, %7 ], [ 0, %3 ], [ 0, %14 ], [ 0, %6 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 5372}
!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}
!16 = !{!6, !8, i64 0}
!17 = !{!6, !8, i64 4}
!18 = !{!6, !8, i64 8}
!19 = !{!6, !8, i64 12}
!20 = !{!6, !8, i64 24}
!21 = !{!6, !11, i64 16}


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