; LLVM IR from quixdb/squash :: plugins/quicklz (quicklz)

; 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.qlz_state_compress = type { i64, [4096 x %struct.qlz_hash_compress], [4096 x i8] }
%struct.qlz_hash_compress = type { i32, i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @qlz_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %4
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = icmp ugt i64 %17, 4294966895
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %4
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %97

20:                                               ; preds = %16
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = icmp ult i64 %21, 216
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i64 3, ptr %12, align 8, !tbaa !9
  br label %25

24:                                               ; preds = %20
  store i64 9, ptr %12, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %24, %23
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  call void @reset_table_compress(ptr noundef %26)
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %12, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = call i64 @qlz_compress_core(ptr noundef %28, ptr noundef %31, i64 noundef %32, ptr noundef %33)
  %35 = add i64 %27, %34
  store i64 %35, ptr %10, align 8, !tbaa !9
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = icmp eq i64 %36, %37
  br i1 %38, label %39, label %48

39:                                               ; preds = %25
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %12, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %42, ptr align 1 %43, i64 %44, i1 false)
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = load i64, ptr %12, align 8, !tbaa !9
  %47 = add i64 %45, %46
  store i64 %47, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %49

48:                                               ; preds = %25
  store i32 1, ptr %11, align 4, !tbaa !11
  br label %49

49:                                               ; preds = %48, %39
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.qlz_state_compress, ptr %50, i32 0, i32 0
  store i64 0, ptr %51, align 8, !tbaa !13
  %52 = load i64, ptr %12, align 8, !tbaa !9
  %53 = icmp eq i64 %52, 3
  br i1 %53, label %54, label %67

54:                                               ; preds = %49
  %55 = load i32, ptr %11, align 4, !tbaa !11
  %56 = or i32 0, %55
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 %57, ptr %58, align 1, !tbaa !15
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = trunc i64 %59 to i8
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 1
  store i8 %60, ptr %62, align 1, !tbaa !15
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = trunc i64 %63 to i8
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 2
  store i8 %64, ptr %66, align 1, !tbaa !15
  br label %80

67:                                               ; preds = %49
  %68 = load i32, ptr %11, align 4, !tbaa !11
  %69 = or i32 2, %68
  %70 = trunc i32 %69 to i8
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 %70, ptr %71, align 1, !tbaa !15
  %72 = load i64, ptr %10, align 8, !tbaa !9
  %73 = trunc i64 %72 to i32
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 1
  call void @fast_write(i32 noundef %73, ptr noundef %75, i64 noundef 4)
  %76 = load i64, ptr %8, align 8, !tbaa !9
  %77 = trunc i64 %76 to i32
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i64 5
  call void @fast_write(i32 noundef %77, ptr noundef %79, i64 noundef 4)
  br label %80

80:                                               ; preds = %67, %54
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load i8, ptr %81, align 1, !tbaa !15
  %83 = sext i8 %82 to i32
  %84 = or i32 %83, 4
  %85 = trunc i32 %84 to i8
  store i8 %85, ptr %81, align 1, !tbaa !15
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load i8, ptr %86, align 1, !tbaa !15
  %88 = sext i8 %87 to i32
  %89 = or i32 %88, 64
  %90 = trunc i32 %89 to i8
  store i8 %90, ptr %86, align 1, !tbaa !15
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i8, ptr %91, align 1, !tbaa !15
  %93 = sext i8 %92 to i32
  %94 = or i32 %93, 0
  %95 = trunc i32 %94 to i8
  store i8 %95, ptr %91, align 1, !tbaa !15
  %96 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %96, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %97

97:                                               ; preds = %80, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %98 = load i64, ptr %5, align 8
  ret i64 %98
}

; Function Attrs: nounwind uwtable
declare hidden void @reset_table_compress(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @qlz_compress_core(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @fast_write(i32 noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !7, i64 8, !7, i64 32776}
!15 = !{!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
define dso_local i64 @qlz_compress(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = add i64 %2, -4294966896
  %or.cond = icmp ult i64 %5, -4294966895
  br i1 %or.cond, label %27, label %6

6:                                                ; preds = %4
  %7 = icmp ult i64 %2, 216
  %. = select i1 %7, i64 3, i64 9
  tail call void @reset_table_compress(ptr noundef %3)
  %8 = getelementptr inbounds i8, ptr %1, i64 %.
  %9 = tail call i64 @qlz_compress_core(ptr noundef %0, ptr noundef nonnull %8, i64 noundef %2, ptr noundef %3)
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %8, ptr align 1 %0, i64 %2, i1 false)
  br label %12

12:                                               ; preds = %6, %11
  %.pn = phi i64 [ %2, %11 ], [ %9, %6 ]
  %.037 = phi i8 [ 0, %11 ], [ 1, %6 ]
  %.038 = add i64 %.pn, %.
  store i64 0, ptr %3, align 8, !tbaa !5
  br i1 %7, label %13, label %18

13:                                               ; preds = %12
  %14 = trunc i64 %.038 to i8
  %15 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %14, ptr %15, align 1, !tbaa !10
  %16 = trunc nuw i64 %2 to i8
  %17 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %16, ptr %17, align 1, !tbaa !10
  br label %24

18:                                               ; preds = %12
  %19 = or disjoint i8 %.037, 2
  store i8 %19, ptr %1, align 1, !tbaa !10
  %20 = trunc i64 %.038 to i32
  %21 = getelementptr inbounds i8, ptr %1, i64 1
  tail call void @fast_write(i32 noundef %20, ptr noundef nonnull %21, i64 noundef 4)
  %22 = trunc nuw i64 %2 to i32
  %23 = getelementptr inbounds i8, ptr %1, i64 5
  tail call void @fast_write(i32 noundef %22, ptr noundef nonnull %23, i64 noundef 4)
  %.pre = load i8, ptr %1, align 1, !tbaa !10
  br label %24

24:                                               ; preds = %18, %13
  %25 = phi i8 [ %.pre, %18 ], [ %.037, %13 ]
  %26 = or i8 %25, 68
  store i8 %26, ptr %1, align 1, !tbaa !10
  br label %27

27:                                               ; preds = %4, %24
  %.039 = phi i64 [ %.038, %24 ], [ 0, %4 ]
  ret i64 %.039
}

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

; Function Attrs: nounwind uwtable
declare hidden i64 @qlz_compress_core(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @fast_write(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!"", !7, i64 0, !8, i64 8, !8, i64 32776}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass