; LLVM IR from DanEngelbrecht/longtail :: lib/brotli/ext/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"

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @BrotliEncoderCreateInstance(ptr noundef, ptr noundef, ptr 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 dso_local void @BrotliEncoderDestroyInstance(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @BrotliEncoderMaxCompressedSize(i64 noundef) #0

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

36:                                               ; preds = %7
  store i32 0, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %113

37:                                               ; preds = %7
  %38 = load i64, ptr %12, align 8, !tbaa !9
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load ptr, ptr %14, align 8, !tbaa !11
  store i64 1, ptr %41, align 8, !tbaa !9
  %42 = load ptr, ptr %15, align 8, !tbaa !11
  store i8 6, ptr %42, align 1, !tbaa !13
  store i32 1, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %113

43:                                               ; preds = %37
  %44 = call ptr @BrotliEncoderCreateInstance(ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %44, ptr %16, align 8, !tbaa !11
  %45 = load ptr, ptr %16, align 8, !tbaa !11
  %46 = icmp ne ptr %45, null
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 0, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %113

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #2
  %49 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %49, ptr %22, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #2
  %50 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %50, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #2
  %51 = load ptr, ptr %14, align 8, !tbaa !11
  %52 = load i64, ptr %51, align 8, !tbaa !9
  store i64 %52, ptr %24, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #2
  %53 = load ptr, ptr %15, align 8, !tbaa !11
  store ptr %53, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #2
  store i64 0, ptr %26, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #2
  store i32 0, ptr %27, align 4, !tbaa !5
  %54 = load ptr, ptr %16, align 8, !tbaa !11
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = call i32 @BrotliEncoderSetParameter(ptr noundef %54, i32 noundef 1, i32 noundef %55)
  %57 = load ptr, ptr %16, align 8, !tbaa !11
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = call i32 @BrotliEncoderSetParameter(ptr noundef %57, i32 noundef 2, i32 noundef %58)
  %60 = load ptr, ptr %16, align 8, !tbaa !11
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = call i32 @BrotliEncoderSetParameter(ptr noundef %60, i32 noundef 0, i32 noundef %61)
  %63 = load ptr, ptr %16, align 8, !tbaa !11
  %64 = load i64, ptr %12, align 8, !tbaa !9
  %65 = trunc i64 %64 to i32
  %66 = call i32 @BrotliEncoderSetParameter(ptr noundef %63, i32 noundef 5, i32 noundef %65)
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = icmp sgt i32 %67, 24
  br i1 %68, label %69, label %72

69:                                               ; preds = %48
  %70 = load ptr, ptr %16, align 8, !tbaa !11
  %71 = call i32 @BrotliEncoderSetParameter(ptr noundef %70, i32 noundef 6, i32 noundef 1)
  br label %72

72:                                               ; preds = %69, %48
  %73 = load ptr, ptr %16, align 8, !tbaa !11
  %74 = call i32 @BrotliEncoderCompressStream(ptr noundef %73, i32 noundef 2, ptr noundef %22, ptr noundef %23, ptr noundef %24, ptr noundef %25, ptr noundef %26)
  store i32 %74, ptr %27, align 4, !tbaa !5
  %75 = load ptr, ptr %16, align 8, !tbaa !11
  %76 = call i32 @BrotliEncoderIsFinished(ptr noundef %75)
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %79, label %78

78:                                               ; preds = %72
  store i32 0, ptr %27, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %78, %72
  %80 = load i64, ptr %26, align 8, !tbaa !9
  %81 = load ptr, ptr %14, align 8, !tbaa !11
  store i64 %80, ptr %81, align 8, !tbaa !9
  %82 = load ptr, ptr %16, align 8, !tbaa !11
  call void @BrotliEncoderDestroyInstance(ptr noundef %82)
  %83 = load i32, ptr %27, align 4, !tbaa !5
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %93

85:                                               ; preds = %79
  %86 = load i64, ptr %20, align 8, !tbaa !9
  %87 = icmp ne i64 %86, 0
  br i1 %87, label %88, label %94

88:                                               ; preds = %85
  %89 = load ptr, ptr %14, align 8, !tbaa !11
  %90 = load i64, ptr %89, align 8, !tbaa !9
  %91 = load i64, ptr %20, align 8, !tbaa !9
  %92 = icmp ugt i64 %90, %91
  br i1 %92, label %93, label %94

93:                                               ; preds = %88, %79
  store i32 2, ptr %21, align 4
  br label %95

94:                                               ; preds = %88, %85
  store i32 1, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %95

95:                                               ; preds = %94, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #2
  %96 = load i32, ptr %21, align 4
  switch i32 %96, label %113 [
    i32 2, label %97
  ]

97:                                               ; preds = %95
  %98 = load ptr, ptr %14, align 8, !tbaa !11
  store i64 0, ptr %98, align 8, !tbaa !9
  %99 = load i64, ptr %20, align 8, !tbaa !9
  %100 = icmp ne i64 %99, 0
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  store i32 0, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %113

102:                                              ; preds = %97
  %103 = load i64, ptr %17, align 8, !tbaa !9
  %104 = load i64, ptr %20, align 8, !tbaa !9
  %105 = icmp uge i64 %103, %104
  br i1 %105, label %106, label %112

106:                                              ; preds = %102
  %107 = load ptr, ptr %18, align 8, !tbaa !11
  %108 = load i64, ptr %12, align 8, !tbaa !9
  %109 = load ptr, ptr %19, align 8, !tbaa !11
  %110 = call i64 @MakeUncompressedStream(ptr noundef %107, i64 noundef %108, ptr noundef %109)
  %111 = load ptr, ptr %14, align 8, !tbaa !11
  store i64 %110, ptr %111, align 8, !tbaa !9
  store i32 1, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %113

112:                                              ; preds = %102
  store i32 0, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %113

113:                                              ; preds = %112, %106, %101, %95, %47, %40, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  %114 = load i32, ptr %8, align 4
  ret i32 %114
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i64 @MakeUncompressedStream(ptr noundef, i64 noundef, 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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"int", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}


; 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 dso_local i32 @BrotliEncoderSetParameter(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @BrotliEncoderMaxCompressedSize(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @BrotliEncoderCompress(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, ptr noundef %4, ptr nocapture noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = freeze i64 %13
  %15 = tail call i64 @BrotliEncoderMaxCompressedSize(i64 noundef %3)
  %16 = icmp eq i64 %14, 0
  br i1 %16, label %44, label %17

17:                                               ; preds = %7
  %18 = icmp eq i64 %3, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  store i64 1, ptr %5, align 8, !tbaa !5
  store i8 6, ptr %6, align 1, !tbaa !9
  br label %44

20:                                               ; preds = %17
  %21 = tail call ptr @BrotliEncoderCreateInstance(ptr noundef null, ptr noundef null, ptr noundef null)
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %44, label %22

22:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #2
  store i64 %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #2
  store ptr %4, ptr %9, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #2
  %23 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #2
  store ptr %6, ptr %11, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #2
  store i64 0, ptr %12, align 8, !tbaa !5
  %24 = tail call i32 @BrotliEncoderSetParameter(ptr noundef nonnull %21, i32 noundef 1, i32 noundef %0)
  %25 = tail call i32 @BrotliEncoderSetParameter(ptr noundef nonnull %21, i32 noundef 2, i32 noundef %1)
  %26 = tail call i32 @BrotliEncoderSetParameter(ptr noundef nonnull %21, i32 noundef 0, i32 noundef %2)
  %27 = trunc i64 %3 to i32
  %28 = tail call i32 @BrotliEncoderSetParameter(ptr noundef nonnull %21, i32 noundef 5, i32 noundef %27)
  %29 = icmp sgt i32 %1, 24
  br i1 %29, label %30, label %32

30:                                               ; preds = %22
  %31 = tail call i32 @BrotliEncoderSetParameter(ptr noundef nonnull %21, i32 noundef 6, i32 noundef 1)
  br label %32

32:                                               ; preds = %30, %22
  %33 = call i32 @BrotliEncoderCompressStream(ptr noundef nonnull %21, i32 noundef 2, ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull %12)
  %34 = call i32 @BrotliEncoderIsFinished(ptr noundef nonnull %21)
  %.not47 = icmp eq i32 %34, 0
  %35 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %35, ptr %5, align 8, !tbaa !5
  call void @BrotliEncoderDestroyInstance(ptr noundef nonnull %21)
  %.not4852 = icmp eq i32 %33, 0
  %.not48 = select i1 %.not47, i1 true, i1 %.not4852
  br i1 %.not48, label %40, label %36

36:                                               ; preds = %32
  %.not49 = icmp eq i64 %15, 0
  br i1 %.not49, label %.critedge, label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = icmp ugt i64 %38, %15
  br i1 %39, label %40, label %.critedge

.critedge:                                        ; preds = %37, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #2
  br label %44

40:                                               ; preds = %32, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #2
  store i64 0, ptr %5, align 8, !tbaa !5
  %41 = add i64 %15, -1
  %or.cond.not = icmp ult i64 %41, %14
  br i1 %or.cond.not, label %42, label %44

42:                                               ; preds = %40
  %43 = call i64 @MakeUncompressedStream(ptr noundef %4, i64 noundef %3, ptr noundef %6)
  store i64 %43, ptr %5, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %40, %.critedge, %20, %7, %42, %19
  %.1 = phi i32 [ 1, %19 ], [ 1, %42 ], [ 0, %7 ], [ 0, %20 ], [ 1, %.critedge ], [ 0, %40 ]
  ret i32 %.1
}

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

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

; Function Attrs: nounwind uwtable
declare hidden i64 @MakeUncompressedStream(ptr noundef, i64 noundef, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}


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